diff --git a/es/utils/aepp-wallet-communication/helpers.js b/es/utils/aepp-wallet-communication/helpers.js index f253f83a53..2c69b012cd 100644 --- a/es/utils/aepp-wallet-communication/helpers.js +++ b/es/utils/aepp-wallet-communication/helpers.js @@ -7,10 +7,11 @@ import { isMemoryAccount } from '../../account/selector' const isWeb = () => location && location.protocol && location.protocol.startsWith('http') export const getBrowserAPI = (force = false) => { + const window = getWindow(force) // Chrome, Opera support - if (chrome === Object(chrome)) return chrome + if (window && window.chrome === Object(window.chrome)) return window.chrome // Firefox support - if (browser === Object(browser)) return browser + if (window && window.browser === Object(window.browser)) return window.browser if (!force) throw new Error('Browser is not detected') return {} } @@ -24,8 +25,8 @@ export const isContentScript = () => isExtensionContext() && isWeb() export const isInIframe = () => window !== window.parent -export const getWindow = () => { - if (!window) throw new Error('Browser is not detected') +export const getWindow = (force = false) => { + if (!window && !force) throw new Error('Browser is not detected') return window } diff --git a/test/integration/rpc.js b/test/integration/rpc.js index a163c1ee03..553037ab51 100644 --- a/test/integration/rpc.js +++ b/test/integration/rpc.js @@ -636,11 +636,13 @@ describe('Aepp<->Wallet', function () { }) it('getBrowserAPI: chrome', () => { global.chrome = { runtime: {}, chrome: true } + global.window = { location: { origin: '//test' }, chrome: global.chrome } getBrowserAPI().chrome.should.be.equal(true) }) it('getBrowserAPI: firefox', () => { global.chrome = null global.browser = { runtime: {}, firefox: true } + global.window = { location: { origin: '//test' }, browser: global.browser } getBrowserAPI().firefox.should.be.equal(true) }) it('isInIframe/getWindow', () => { @@ -673,7 +675,7 @@ describe('Aepp<->Wallet', function () { const getConnections = (direct) => { global.chrome = { runtime: {} } - global.window = { location: { origin: '//test' } } + global.window = { location: { origin: '//test' }, chrome: global.chrome } global.location = { protocol: 'http://test.com' } return getFakeConnections(direct) }