diff --git a/app/scripts/background.js b/app/scripts/background.js index 2f8d40ea0..6267c4441 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -100,7 +100,7 @@ const initApp = async (remotePort) => { log.info('MetaMask initialization complete.'); }; -if (isManifestV3()) { +if (isManifestV3) { browser.runtime.onConnect.addListener(initApp); } else { // initialization flow @@ -402,7 +402,7 @@ function setupController(initState, initLangCode, remoteSourcePort) { // // connect to other contexts // - if (isManifestV3() && remoteSourcePort) { + if (isManifestV3 && remoteSourcePort) { connectRemote(remoteSourcePort); } @@ -476,7 +476,7 @@ function setupController(initState, initLangCode, remoteSourcePort) { controller.isClientOpen = true; controller.setupTrustedCommunication(portStream, remotePort.sender); - if (isManifestV3()) { + if (isManifestV3) { // Message below if captured by UI code in app/scripts/ui.js which will trigger UI initialisation // This ensures that UI is initialised only after background is ready // It fixes the issue of blank screen coming when extension is loaded, the issue is very frequent in MV3 @@ -605,7 +605,7 @@ function setupController(initState, initLangCode, remoteSourcePort) { label = String(count); } // browserAction has been replaced by action in MV3 - if (isManifestV3()) { + if (isManifestV3) { browser.action.setBadgeText({ text: label }); browser.action.setBadgeBackgroundColor({ color: '#037DD6' }); } else { diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 7810bd8e7..a6fb3bcd1 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -44,7 +44,7 @@ if ( ) { setupPhishingStream(); } else if (shouldInjectProvider()) { - if (!isManifestV3()) { + if (!isManifestV3) { injectScript(inpageBundle); } setupStreams(); diff --git a/app/scripts/ui.js b/app/scripts/ui.js index 50c94cc08..5d7a0c181 100644 --- a/app/scripts/ui.js +++ b/app/scripts/ui.js @@ -35,7 +35,7 @@ const WORKER_KEEP_ALIVE_MESSAGE = 'WORKER_KEEP_ALIVE_MESSAGE'; * if service worker is inactive it is reactivated and script re-loaded * Time has been kept to 1000ms but can be reduced for even faster re-activation of service worker */ -if (isManifestV3()) { +if (isManifestV3) { setInterval(() => { browser.runtime.sendMessage({ name: WORKER_KEEP_ALIVE_MESSAGE }); }, WORKER_KEEP_ALIVE_INTERVAL); @@ -62,7 +62,7 @@ async function start() { * In case of MV3 the issue of blank screen was very frequent, it is caused by UI initialising before background is ready to send state. * Code below ensures that UI is rendered only after background is ready. */ - if (isManifestV3()) { + if (isManifestV3) { /* * In case of MV3 the issue of blank screen was very frequent, it is caused by UI initialising before background is ready to send state. * Code below ensures that UI is rendered only after CONNECTION_READY message is received thus background is ready. diff --git a/shared/modules/mv3.utils.js b/shared/modules/mv3.utils.js index a990075b6..3f9388b07 100644 --- a/shared/modules/mv3.utils.js +++ b/shared/modules/mv3.utils.js @@ -1,4 +1,4 @@ import browser from 'webextension-polyfill'; -export const isManifestV3 = () => +export const isManifestV3 = browser.runtime.getManifest().manifest_version === 3; diff --git a/test/helpers/setup-helper.js b/test/helpers/setup-helper.js index 0e3887e3e..ae38d0c9f 100644 --- a/test/helpers/setup-helper.js +++ b/test/helpers/setup-helper.js @@ -6,7 +6,9 @@ import { JSDOM } from 'jsdom'; process.env.IN_TEST = true; -global.chrome = { runtime: { id: 'testid' } }; +global.chrome = { + runtime: { id: 'testid', getManifest: () => ({ manifest_version: 2 }) }, +}; nock.disableNetConnect(); nock.enableNetConnect('localhost'); diff --git a/ui/__mocks__/webextension-polyfill.js b/ui/__mocks__/webextension-polyfill.js index 54e90aa25..0984c767d 100644 --- a/ui/__mocks__/webextension-polyfill.js +++ b/ui/__mocks__/webextension-polyfill.js @@ -1,3 +1,3 @@ module.exports = { - runtime: {}, + runtime: { getManifest: () => ({ manifest_version: 2 }) }, };