Deprecate extensionizer for webextension-polyfill (#13960)

* deprecate extensionizer for webextension-polyfill

* fix tests

* remove extensionizer

* fix browser windows api calls

* fix broken on firefox

* fix getAcceptLanguages call

* update more browser apis that are now promisified

* remove unnecessary console error ignoring in e2e tests
feature/default_network_editable
Alex Donesky 3 years ago committed by GitHub
parent 093c69cf76
commit 8df8f81df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      app/scripts/background.js
  2. 8
      app/scripts/contentscript.js
  3. 4
      app/scripts/lib/createOnboardingMiddleware.js
  4. 11
      app/scripts/lib/ens-ipfs/setup.js
  5. 9
      app/scripts/lib/get-first-preferred-lang-code.js
  6. 12
      app/scripts/lib/local-store.js
  7. 5
      app/scripts/lib/util.js
  8. 4
      app/scripts/metamask-controller.js
  9. 4
      app/scripts/metamask-controller.test.js
  10. 4
      app/scripts/phishing-detect.js
  11. 51
      app/scripts/platforms/extension.js
  12. 20
      app/scripts/platforms/extension.test.js
  13. 6
      app/scripts/ui.js
  14. 15
      lavamoat/browserify/beta/policy.json
  15. 15
      lavamoat/browserify/flask/policy.json
  16. 15
      lavamoat/browserify/main/policy.json
  17. 2
      package.json
  18. 2
      test/helpers/setup-helper.js
  19. 3
      ui/__mocks__/webextension-polyfill.js
  20. 4
      ui/components/app/menu-bar/menu-bar.js
  21. 16
      ui/pages/first-time-flow/onboarding-initiator-util.js
  22. 10
      yarn.lock

@ -6,7 +6,7 @@ import endOfStream from 'end-of-stream';
import pump from 'pump'; import pump from 'pump';
import debounce from 'debounce-stream'; import debounce from 'debounce-stream';
import log from 'loglevel'; import log from 'loglevel';
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import { storeAsStream, storeTransformStream } from '@metamask/obs-store'; import { storeAsStream, storeTransformStream } from '@metamask/obs-store';
import PortStream from 'extension-port-stream'; import PortStream from 'extension-port-stream';
import { captureException } from '@sentry/browser'; import { captureException } from '@sentry/browser';
@ -224,7 +224,7 @@ function setupController(initState, initLangCode) {
// platform specific api // platform specific api
platform, platform,
notificationManager, notificationManager,
extension, browser,
getRequestAccountTabIds: () => { getRequestAccountTabIds: () => {
return requestAccountTabIds; return requestAccountTabIds;
}, },
@ -294,8 +294,8 @@ function setupController(initState, initLangCode) {
// //
// connect to other contexts // connect to other contexts
// //
extension.runtime.onConnect.addListener(connectRemote); browser.runtime.onConnect.addListener(connectRemote);
extension.runtime.onConnectExternal.addListener(connectExternal); browser.runtime.onConnectExternal.addListener(connectExternal);
const metamaskInternalProcessHash = { const metamaskInternalProcessHash = {
[ENVIRONMENT_TYPE_POPUP]: true, [ENVIRONMENT_TYPE_POPUP]: true,
@ -359,8 +359,7 @@ function setupController(initState, initLangCode) {
isMetaMaskInternalProcess = metamaskInternalProcessHash[processName]; isMetaMaskInternalProcess = metamaskInternalProcessHash[processName];
} else { } else {
isMetaMaskInternalProcess = isMetaMaskInternalProcess =
remotePort.sender.origin === remotePort.sender.origin === `chrome-extension://${browser.runtime.id}`;
`chrome-extension://${extension.runtime.id}`;
} }
if (isMetaMaskInternalProcess) { if (isMetaMaskInternalProcess) {
@ -481,8 +480,8 @@ function setupController(initState, initLangCode) {
if (count) { if (count) {
label = String(count); label = String(count);
} }
extension.browserAction.setBadgeText({ text: label }); browser.browserAction.setBadgeText({ text: label });
extension.browserAction.setBadgeBackgroundColor({ color: '#037DD6' }); browser.browserAction.setBadgeBackgroundColor({ color: '#037DD6' });
} }
function getUnapprovedTransactionCount() { function getUnapprovedTransactionCount() {
@ -627,7 +626,7 @@ async function openPopup() {
} }
// On first install, open a new tab with MetaMask // On first install, open a new tab with MetaMask
extension.runtime.onInstalled.addListener(({ reason }) => { browser.runtime.onInstalled.addListener(({ reason }) => {
if ( if (
reason === 'install' && reason === 'install' &&
!(process.env.METAMASK_DEBUG || process.env.IN_TEST) !(process.env.METAMASK_DEBUG || process.env.IN_TEST)

@ -2,7 +2,7 @@ import querystring from 'querystring';
import pump from 'pump'; import pump from 'pump';
import { WindowPostMessageStream } from '@metamask/post-message-stream'; import { WindowPostMessageStream } from '@metamask/post-message-stream';
import ObjectMultiplex from 'obj-multiplex'; import ObjectMultiplex from 'obj-multiplex';
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import PortStream from 'extension-port-stream'; import PortStream from 'extension-port-stream';
import { obj as createThoughStream } from 'through2'; import { obj as createThoughStream } from 'through2';
@ -14,7 +14,7 @@ const inpageContent = fs.readFileSync(
path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js'), path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js'),
'utf8', 'utf8',
); );
const inpageSuffix = `//# sourceURL=${extension.runtime.getURL('inpage.js')}\n`; const inpageSuffix = `//# sourceURL=${browser.runtime.getURL('inpage.js')}\n`;
const inpageBundle = inpageContent + inpageSuffix; const inpageBundle = inpageContent + inpageSuffix;
const CONTENT_SCRIPT = 'metamask-contentscript'; const CONTENT_SCRIPT = 'metamask-contentscript';
@ -61,7 +61,7 @@ async function setupStreams() {
name: CONTENT_SCRIPT, name: CONTENT_SCRIPT,
target: INPAGE, target: INPAGE,
}); });
const extensionPort = extension.runtime.connect({ name: CONTENT_SCRIPT }); const extensionPort = browser.runtime.connect({ name: CONTENT_SCRIPT });
const extensionStream = new PortStream(extensionPort); const extensionStream = new PortStream(extensionPort);
// create and connect channel muxers // create and connect channel muxers
@ -301,7 +301,7 @@ function blockedDomainCheck() {
*/ */
function redirectToPhishingWarning() { function redirectToPhishingWarning() {
console.debug('MetaMask: Routing to Phishing Warning component.'); console.debug('MetaMask: Routing to Phishing Warning component.');
const extensionURL = extension.runtime.getURL('phishing.html'); const extensionURL = browser.runtime.getURL('phishing.html');
window.location.href = `${extensionURL}#${querystring.stringify({ window.location.href = `${extensionURL}#${querystring.stringify({
hostname: window.location.hostname, hostname: window.location.hostname,
href: window.location.href, href: window.location.href,

@ -1,5 +1,5 @@
import log from 'loglevel'; import log from 'loglevel';
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
/** /**
* Returns a middleware that intercepts `wallet_registerOnboarding` messages * Returns a middleware that intercepts `wallet_registerOnboarding` messages
@ -17,7 +17,7 @@ export default function createOnboardingMiddleware({
next(); next();
return; return;
} }
if (req.tabId && req.tabId !== extension.tabs.TAB_ID_NONE) { if (req.tabId && req.tabId !== browser.tabs.TAB_ID_NONE) {
await registerOnboarding(location, req.tabId); await registerOnboarding(location, req.tabId);
} else { } else {
log.debug( log.debug(

@ -1,6 +1,7 @@
import base32Encode from 'base32-encode'; import base32Encode from 'base32-encode';
import base64 from 'base64-js'; import base64 from 'base64-js';
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import { SECOND } from '../../../../shared/constants/time'; import { SECOND } from '../../../../shared/constants/time';
import getFetchWithTimeout from '../../../../shared/modules/fetch-with-timeout'; import getFetchWithTimeout from '../../../../shared/modules/fetch-with-timeout';
import resolveEnsToIpfsContentId from './resolver'; import resolveEnsToIpfsContentId from './resolver';
@ -16,7 +17,7 @@ export default function setupEnsIpfsResolver({
}) { }) {
// install listener // install listener
const urlPatterns = supportedTopLevelDomains.map((tld) => `*://*.${tld}/*`); const urlPatterns = supportedTopLevelDomains.map((tld) => `*://*.${tld}/*`);
extension.webRequest.onErrorOccurred.addListener(webRequestDidFail, { browser.webRequest.onErrorOccurred.addListener(webRequestDidFail, {
urls: urlPatterns, urls: urlPatterns,
types: ['main_frame'], types: ['main_frame'],
}); });
@ -25,7 +26,7 @@ export default function setupEnsIpfsResolver({
return { return {
// uninstall listener // uninstall listener
remove() { remove() {
extension.webRequest.onErrorOccurred.removeListener(webRequestDidFail); browser.webRequest.onErrorOccurred.removeListener(webRequestDidFail);
}, },
}; };
@ -51,7 +52,7 @@ export default function setupEnsIpfsResolver({
async function attemptResolve({ tabId, name, pathname, search, fragment }) { async function attemptResolve({ tabId, name, pathname, search, fragment }) {
const ipfsGateway = getIpfsGateway(); const ipfsGateway = getIpfsGateway();
extension.tabs.update(tabId, { url: `loading.html` }); browser.tabs.update(tabId, { url: `loading.html` });
let url = `https://app.ens.domains/name/${name}`; let url = `https://app.ens.domains/name/${name}`;
try { try {
const { type, hash } = await resolveEnsToIpfsContentId({ const { type, hash } = await resolveEnsToIpfsContentId({
@ -101,7 +102,7 @@ export default function setupEnsIpfsResolver({
} catch (err) { } catch (err) {
console.warn(err); console.warn(err);
} finally { } finally {
extension.tabs.update(tabId, { url }); browser.tabs.update(tabId, { url });
} }
} }
} }

@ -1,11 +1,6 @@
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import promisify from 'pify';
import allLocales from '../../_locales/index.json'; import allLocales from '../../_locales/index.json';
const getPreferredLocales = extension.i18n
? promisify(extension.i18n.getAcceptLanguages, { errorFirst: false })
: async () => [];
// mapping some browsers return hyphen instead underscore in locale codes (e.g. zh_TW -> zh-tw) // mapping some browsers return hyphen instead underscore in locale codes (e.g. zh_TW -> zh-tw)
const existingLocaleCodes = {}; const existingLocaleCodes = {};
allLocales.forEach((locale) => { allLocales.forEach((locale) => {
@ -25,7 +20,7 @@ export default async function getFirstPreferredLangCode() {
let userPreferredLocaleCodes; let userPreferredLocaleCodes;
try { try {
userPreferredLocaleCodes = await getPreferredLocales(); userPreferredLocaleCodes = await browser.i18n.getAcceptLanguages();
} catch (e) { } catch (e) {
// Brave currently throws when calling getAcceptLanguages, so this handles that. // Brave currently throws when calling getAcceptLanguages, so this handles that.
userPreferredLocaleCodes = []; userPreferredLocaleCodes = [];

@ -1,4 +1,4 @@
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import log from 'loglevel'; import log from 'loglevel';
import { checkForError } from './util'; import { checkForError } from './util';
@ -7,7 +7,7 @@ import { checkForError } from './util';
*/ */
export default class ExtensionStore { export default class ExtensionStore {
constructor() { constructor() {
this.isSupported = Boolean(extension.storage.local); this.isSupported = Boolean(browser.storage.local);
if (!this.isSupported) { if (!this.isSupported) {
log.error('Storage local API not available.'); log.error('Storage local API not available.');
} }
@ -48,9 +48,9 @@ export default class ExtensionStore {
* @returns {Object} the key-value map from local storage * @returns {Object} the key-value map from local storage
*/ */
_get() { _get() {
const { local } = extension.storage; const { local } = browser.storage;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
local.get(null, (/** @type {any} */ result) => { local.get(null).then((/** @type {any} */ result) => {
const err = checkForError(); const err = checkForError();
if (err) { if (err) {
reject(err); reject(err);
@ -69,9 +69,9 @@ export default class ExtensionStore {
* @private * @private
*/ */
_set(obj) { _set(obj) {
const { local } = extension.storage; const { local } = browser.storage;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
local.set(obj, () => { local.set(obj).then(() => {
const err = checkForError(); const err = checkForError();
if (err) { if (err) {
reject(err); reject(err);

@ -1,4 +1,5 @@
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import { stripHexPrefix } from 'ethereumjs-util'; import { stripHexPrefix } from 'ethereumjs-util';
import BN from 'bn.js'; import BN from 'bn.js';
import { memoize } from 'lodash'; import { memoize } from 'lodash';
@ -102,7 +103,7 @@ function BnMultiplyByFraction(targetBN, numerator, denominator) {
* @returns {Error|undefined} * @returns {Error|undefined}
*/ */
function checkForError() { function checkForError() {
const { lastError } = extension.runtime; const { lastError } = browser.runtime;
if (!lastError) { if (!lastError) {
return undefined; return undefined;
} }

@ -164,7 +164,7 @@ export default class MetamaskController extends EventEmitter {
MILLISECOND * 200, MILLISECOND * 200,
); );
this.opts = opts; this.opts = opts;
this.extension = opts.extension; this.extension = opts.browser;
this.platform = opts.platform; this.platform = opts.platform;
this.notificationManager = opts.notificationManager; this.notificationManager = opts.notificationManager;
const initState = opts.initState || {}; const initState = opts.initState || {};
@ -1001,7 +1001,7 @@ export default class MetamaskController extends EventEmitter {
} }
// Lazily update the store with the current extension environment // Lazily update the store with the current extension environment
this.extension.runtime.getPlatformInfo(({ os }) => { this.extension.runtime.getPlatformInfo().then(({ os }) => {
this.appStateController.setBrowserEnvironment( this.appStateController.setBrowserEnvironment(
os, os,
// This method is presently only supported by Firefox // This method is presently only supported by Firefox

@ -65,7 +65,7 @@ class ThreeBoxControllerMock {
} }
} }
const ExtensionizerMock = { const browserPolyfillMock = {
runtime: { runtime: {
id: 'fake-extension-id', id: 'fake-extension-id',
onInstalled: { onInstalled: {
@ -148,7 +148,7 @@ describe('MetaMaskController', function () {
showTransactionNotification: () => undefined, showTransactionNotification: () => undefined,
getVersion: () => 'foo', getVersion: () => 'foo',
}, },
extension: ExtensionizerMock, browser: browserPolyfillMock,
infuraProjectId: 'foo', infuraProjectId: 'foo',
}); });

@ -1,6 +1,6 @@
import querystring from 'querystring'; import querystring from 'querystring';
import PortStream from 'extension-port-stream'; import PortStream from 'extension-port-stream';
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import createRandomId from '../../shared/modules/random-id'; import createRandomId from '../../shared/modules/random-id';
import { setupMultiplex } from './lib/stream-utils'; import { setupMultiplex } from './lib/stream-utils';
import { getEnvironmentType } from './lib/util'; import { getEnvironmentType } from './lib/util';
@ -21,7 +21,7 @@ function start() {
global.platform = new ExtensionPlatform(); global.platform = new ExtensionPlatform();
const extensionPort = extension.runtime.connect({ const extensionPort = browser.runtime.connect({
name: getEnvironmentType(), name: getEnvironmentType(),
}); });
const connectionStream = new PortStream(extensionPort); const connectionStream = new PortStream(extensionPort);

@ -1,4 +1,5 @@
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import { getBlockExplorerLink } from '@metamask/etherscan-link'; import { getBlockExplorerLink } from '@metamask/etherscan-link';
import { getEnvironmentType, checkForError } from '../lib/util'; import { getEnvironmentType, checkForError } from '../lib/util';
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app'; import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
@ -9,12 +10,12 @@ export default class ExtensionPlatform {
// Public // Public
// //
reload() { reload() {
extension.runtime.reload(); browser.runtime.reload();
} }
openTab(options) { openTab(options) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.tabs.create(options, (newTab) => { browser.tabs.create(options).then((newTab) => {
const error = checkForError(); const error = checkForError();
if (error) { if (error) {
return reject(error); return reject(error);
@ -26,7 +27,7 @@ export default class ExtensionPlatform {
openWindow(options) { openWindow(options) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.windows.create(options, (newWindow) => { browser.windows.create(options).then((newWindow) => {
const error = checkForError(); const error = checkForError();
if (error) { if (error) {
return reject(error); return reject(error);
@ -38,7 +39,7 @@ export default class ExtensionPlatform {
focusWindow(windowId) { focusWindow(windowId) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.windows.update(windowId, { focused: true }, () => { browser.windows.update(windowId, { focused: true }).then(() => {
const error = checkForError(); const error = checkForError();
if (error) { if (error) {
return reject(error); return reject(error);
@ -50,7 +51,7 @@ export default class ExtensionPlatform {
updateWindowPosition(windowId, left, top) { updateWindowPosition(windowId, left, top) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.windows.update(windowId, { left, top }, () => { browser.windows.update(windowId, { left, top }).then(() => {
const error = checkForError(); const error = checkForError();
if (error) { if (error) {
return reject(error); return reject(error);
@ -62,7 +63,7 @@ export default class ExtensionPlatform {
getLastFocusedWindow() { getLastFocusedWindow() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.windows.getLastFocused((windowObject) => { browser.windows.getLastFocused().then((windowObject) => {
const error = checkForError(); const error = checkForError();
if (error) { if (error) {
return reject(error); return reject(error);
@ -73,8 +74,8 @@ export default class ExtensionPlatform {
} }
closeCurrentWindow() { closeCurrentWindow() {
return extension.windows.getCurrent((windowDetails) => { return browser.windows.getCurrent().then((windowDetails) => {
return extension.windows.remove(windowDetails.id); return browser.windows.remove(windowDetails.id);
}); });
} }
@ -82,7 +83,7 @@ export default class ExtensionPlatform {
const { const {
version, version,
version_name: versionName, version_name: versionName,
} = extension.runtime.getManifest(); } = browser.runtime.getManifest();
const versionParts = version.split('.'); const versionParts = version.split('.');
if (versionName) { if (versionName) {
@ -115,7 +116,7 @@ export default class ExtensionPlatform {
queryString = null, queryString = null,
keepWindowOpen = false, keepWindowOpen = false,
) { ) {
let extensionURL = extension.runtime.getURL('home.html'); let extensionURL = browser.runtime.getURL('home.html');
if (route) { if (route) {
extensionURL += `#${route}`; extensionURL += `#${route}`;
@ -136,9 +137,9 @@ export default class ExtensionPlatform {
getPlatformInfo(cb) { getPlatformInfo(cb) {
try { try {
extension.runtime.getPlatformInfo((platform) => { const platformInfo = browser.runtime.getPlatformInfo();
cb(null, platform); cb(platformInfo);
}); return;
} catch (e) { } catch (e) {
cb(e); cb(e);
// eslint-disable-next-line no-useless-return // eslint-disable-next-line no-useless-return
@ -163,12 +164,12 @@ export default class ExtensionPlatform {
} }
addOnRemovedListener(listener) { addOnRemovedListener(listener) {
extension.windows.onRemoved.addListener(listener); browser.windows.onRemoved.addListener(listener);
} }
getAllWindows() { getAllWindows() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.windows.getAll((windows) => { browser.windows.getAll().then((windows) => {
const error = checkForError(); const error = checkForError();
if (error) { if (error) {
return reject(error); return reject(error);
@ -180,7 +181,7 @@ export default class ExtensionPlatform {
getActiveTabs() { getActiveTabs() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.tabs.query({ active: true }, (tabs) => { browser.tabs.query({ active: true }).then((tabs) => {
const error = checkForError(); const error = checkForError();
if (error) { if (error) {
return reject(error); return reject(error);
@ -192,7 +193,7 @@ export default class ExtensionPlatform {
currentTab() { currentTab() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.tabs.getCurrent((tab) => { browser.tabs.getCurrent().then((tab) => {
const err = checkForError(); const err = checkForError();
if (err) { if (err) {
reject(err); reject(err);
@ -205,7 +206,7 @@ export default class ExtensionPlatform {
switchToTab(tabId) { switchToTab(tabId) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.tabs.update(tabId, { highlighted: true }, (tab) => { browser.tabs.update(tabId, { highlighted: true }).then((tab) => {
const err = checkForError(); const err = checkForError();
if (err) { if (err) {
reject(err); reject(err);
@ -218,7 +219,7 @@ export default class ExtensionPlatform {
closeTab(tabId) { closeTab(tabId) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
extension.tabs.remove(tabId, () => { browser.tabs.remove(tabId).then(() => {
const err = checkForError(); const err = checkForError();
if (err) { if (err) {
reject(err); reject(err);
@ -252,23 +253,23 @@ export default class ExtensionPlatform {
} }
_showNotification(title, message, url) { _showNotification(title, message, url) {
extension.notifications.create(url, { browser.notifications.create(url, {
type: 'basic', type: 'basic',
title, title,
iconUrl: extension.extension.getURL('../../images/icon-64.png'), iconUrl: browser.extension.getURL('../../images/icon-64.png'),
message, message,
}); });
} }
_subscribeToNotificationClicked() { _subscribeToNotificationClicked() {
if (!extension.notifications.onClicked.hasListener(this._viewOnEtherscan)) { if (!browser.notifications.onClicked.hasListener(this._viewOnEtherscan)) {
extension.notifications.onClicked.addListener(this._viewOnEtherscan); browser.notifications.onClicked.addListener(this._viewOnEtherscan);
} }
} }
_viewOnEtherscan(url) { _viewOnEtherscan(url) {
if (url.startsWith('https://')) { if (url.startsWith('https://')) {
extension.tabs.create({ url }); browser.tabs.create({ url });
} }
} }
} }

@ -1,7 +1,7 @@
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import ExtensionPlatform from './extension'; import ExtensionPlatform from './extension';
jest.mock('extensionizer', () => { jest.mock('webextension-polyfill', () => {
return { return {
runtime: { runtime: {
getManifest: jest.fn(), getManifest: jest.fn(),
@ -17,7 +17,7 @@ describe('extension platform', () => {
describe('getVersion', () => { describe('getVersion', () => {
it('should return non-prerelease version', () => { it('should return non-prerelease version', () => {
extension.runtime.getManifest.mockReturnValue({ version: '1.2.3' }); browser.runtime.getManifest.mockReturnValue({ version: '1.2.3' });
const extensionPlatform = new ExtensionPlatform(); const extensionPlatform = new ExtensionPlatform();
const version = extensionPlatform.getVersion(); const version = extensionPlatform.getVersion();
@ -26,7 +26,7 @@ describe('extension platform', () => {
}); });
it('should return SemVer-formatted version for Chrome style manifest of prerelease', () => { it('should return SemVer-formatted version for Chrome style manifest of prerelease', () => {
extension.runtime.getManifest.mockReturnValue({ browser.runtime.getManifest.mockReturnValue({
version: '1.2.3.0', version: '1.2.3.0',
version_name: '1.2.3-beta.0', version_name: '1.2.3-beta.0',
}); });
@ -38,7 +38,7 @@ describe('extension platform', () => {
}); });
it('should return SemVer-formatted version for Firefox style manifest of prerelease', () => { it('should return SemVer-formatted version for Firefox style manifest of prerelease', () => {
extension.runtime.getManifest.mockReturnValue({ browser.runtime.getManifest.mockReturnValue({
version: '1.2.3beta0', version: '1.2.3beta0',
}); });
const extensionPlatform = new ExtensionPlatform(); const extensionPlatform = new ExtensionPlatform();
@ -49,7 +49,7 @@ describe('extension platform', () => {
}); });
it('should throw error if build version is missing from Chrome style prerelease manifest', () => { it('should throw error if build version is missing from Chrome style prerelease manifest', () => {
extension.runtime.getManifest.mockReturnValue({ browser.runtime.getManifest.mockReturnValue({
version: '1.2.3', version: '1.2.3',
version_name: '1.2.3-beta.0', version_name: '1.2.3-beta.0',
}); });
@ -61,7 +61,7 @@ describe('extension platform', () => {
}); });
it('should throw error if version name is missing from Chrome style prerelease manifest', () => { it('should throw error if version name is missing from Chrome style prerelease manifest', () => {
extension.runtime.getManifest.mockReturnValue({ browser.runtime.getManifest.mockReturnValue({
version: '1.2.3.0', version: '1.2.3.0',
}); });
const extensionPlatform = new ExtensionPlatform(); const extensionPlatform = new ExtensionPlatform();
@ -70,7 +70,7 @@ describe('extension platform', () => {
}); });
it('should throw error if version includes four parts in a Firefox style manifest', () => { it('should throw error if version includes four parts in a Firefox style manifest', () => {
extension.runtime.getManifest.mockReturnValue({ browser.runtime.getManifest.mockReturnValue({
version: '1.2.3.4', version: '1.2.3.4',
}); });
const extensionPlatform = new ExtensionPlatform(); const extensionPlatform = new ExtensionPlatform();
@ -79,7 +79,7 @@ describe('extension platform', () => {
}); });
it('should throw error if build version is missing from Firefox style prerelease manifest', () => { it('should throw error if build version is missing from Firefox style prerelease manifest', () => {
extension.runtime.getManifest.mockReturnValue({ browser.runtime.getManifest.mockReturnValue({
version: '1.2.3beta', version: '1.2.3beta',
}); });
const extensionPlatform = new ExtensionPlatform(); const extensionPlatform = new ExtensionPlatform();
@ -90,7 +90,7 @@ describe('extension platform', () => {
}); });
it('should throw error if patch is missing from Firefox style prerelease manifest', () => { it('should throw error if patch is missing from Firefox style prerelease manifest', () => {
extension.runtime.getManifest.mockReturnValue({ browser.runtime.getManifest.mockReturnValue({
version: '1.2.beta0', version: '1.2.beta0',
}); });
const extensionPlatform = new ExtensionPlatform(); const extensionPlatform = new ExtensionPlatform();

@ -5,7 +5,7 @@ import '@formatjs/intl-relativetimeformat/polyfill';
import 'react-devtools'; import 'react-devtools';
import PortStream from 'extension-port-stream'; import PortStream from 'extension-port-stream';
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import Eth from 'ethjs'; import Eth from 'ethjs';
import EthQuery from 'eth-query'; import EthQuery from 'eth-query';
@ -31,7 +31,7 @@ async function start() {
const windowType = getEnvironmentType(); const windowType = getEnvironmentType();
// setup stream to background // setup stream to background
const extensionPort = extension.runtime.connect({ name: windowType }); const extensionPort = browser.runtime.connect({ name: windowType });
const connectionStream = new PortStream(extensionPort); const connectionStream = new PortStream(extensionPort);
const activeTab = await queryCurrentActiveTab(windowType); const activeTab = await queryCurrentActiveTab(windowType);
@ -72,7 +72,7 @@ async function queryCurrentActiveTab(windowType) {
return; return;
} }
extension.tabs.query({ active: true, currentWindow: true }, (tabs) => { browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
const [activeTab] = tabs; const [activeTab] = tabs;
const { id, title, url } = activeTab; const { id, title, url } = activeTab;
const { origin, protocol } = url ? new URL(url) : {}; const { origin, protocol } = url ? new URL(url) : {};

@ -2240,12 +2240,6 @@
"stream-browserify": true "stream-browserify": true
} }
}, },
"extensionizer": {
"globals": {
"browser": true,
"chrome": true
}
},
"faker": { "faker": {
"globals": { "globals": {
"console.error": true, "console.error": true,
@ -5189,6 +5183,15 @@
"utf8": true "utf8": true
} }
}, },
"webextension-polyfill": {
"globals": {
"browser": true,
"chrome": true,
"console.error": true,
"console.warn": true,
"define": true
}
},
"webrtcsupport": { "webrtcsupport": {
"globals": { "globals": {
"AudioContext": true, "AudioContext": true,

@ -2259,12 +2259,6 @@
"stream-browserify": true "stream-browserify": true
} }
}, },
"extensionizer": {
"globals": {
"browser": true,
"chrome": true
}
},
"faker": { "faker": {
"globals": { "globals": {
"console.error": true, "console.error": true,
@ -5208,6 +5202,15 @@
"utf8": true "utf8": true
} }
}, },
"webextension-polyfill": {
"globals": {
"browser": true,
"chrome": true,
"console.error": true,
"console.warn": true,
"define": true
}
},
"webrtcsupport": { "webrtcsupport": {
"globals": { "globals": {
"AudioContext": true, "AudioContext": true,

@ -2240,12 +2240,6 @@
"stream-browserify": true "stream-browserify": true
} }
}, },
"extensionizer": {
"globals": {
"browser": true,
"chrome": true
}
},
"faker": { "faker": {
"globals": { "globals": {
"console.error": true, "console.error": true,
@ -5189,6 +5183,15 @@
"utf8": true "utf8": true
} }
}, },
"webextension-polyfill": {
"globals": {
"browser": true,
"chrome": true,
"console.error": true,
"console.warn": true,
"define": true
}
},
"webrtcsupport": { "webrtcsupport": {
"globals": { "globals": {
"AudioContext": true, "AudioContext": true,

@ -168,7 +168,6 @@
"ethjs-ens": "^2.0.0", "ethjs-ens": "^2.0.0",
"ethjs-query": "^0.3.4", "ethjs-query": "^0.3.4",
"extension-port-stream": "^2.0.0", "extension-port-stream": "^2.0.0",
"extensionizer": "^1.0.1",
"fast-json-patch": "^2.2.1", "fast-json-patch": "^2.2.1",
"fast-safe-stringify": "^2.0.7", "fast-safe-stringify": "^2.0.7",
"fuse.js": "^3.2.0", "fuse.js": "^3.2.0",
@ -363,6 +362,7 @@
"vinyl-source-stream": "^2.0.0", "vinyl-source-stream": "^2.0.0",
"vinyl-sourcemaps-apply": "^0.2.1", "vinyl-sourcemaps-apply": "^0.2.1",
"watchify": "^4.0.0", "watchify": "^4.0.0",
"webextension-polyfill": "^0.8.0",
"webpack": "^4.41.6", "webpack": "^4.41.6",
"yargs": "^17.0.1", "yargs": "^17.0.1",
"yarn-deduplicate": "^3.1.0" "yarn-deduplicate": "^3.1.0"

@ -6,6 +6,8 @@ import { JSDOM } from 'jsdom';
process.env.IN_TEST = true; process.env.IN_TEST = true;
global.chrome = { runtime: { id: 'testid' } };
nock.disableNetConnect(); nock.disableNetConnect();
nock.enableNetConnect('localhost'); nock.enableNetConnect('localhost');

@ -0,0 +1,3 @@
module.exports = {
runtime: {},
};

@ -1,5 +1,5 @@
import React, { useState, useContext } from 'react'; import React, { useState, useContext } from 'react';
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import SelectedAccount from '../selected-account'; import SelectedAccount from '../selected-account';
@ -26,7 +26,7 @@ export default function MenuBar() {
const showStatus = const showStatus =
getEnvironmentType() === ENVIRONMENT_TYPE_POPUP && getEnvironmentType() === ENVIRONMENT_TYPE_POPUP &&
origin && origin &&
origin !== extension.runtime.id; origin !== browser.runtime.id;
return ( return (
<div className="menu-bar"> <div className="menu-bar">

@ -1,9 +1,9 @@
import extension from 'extensionizer'; import browser from 'webextension-polyfill';
import log from 'loglevel'; import log from 'loglevel';
const returnToOnboardingInitiatorTab = async (onboardingInitiator) => { const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
const tab = await new Promise((resolve) => { const tab = await new Promise((resolve) => {
extension.tabs.update( browser.tabs.update(
onboardingInitiator.tabId, onboardingInitiator.tabId,
{ active: true }, { active: true },
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
@ -12,8 +12,8 @@ const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
resolve(tab); resolve(tab);
} else { } else {
// silence console message about unchecked error // silence console message about unchecked error
if (extension.runtime.lastError) { if (browser.runtime.lastError) {
log.debug(extension.runtime.lastError); log.debug(browser.runtime.lastError);
} }
resolve(); resolve();
} }
@ -24,7 +24,7 @@ const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
if (tab) { if (tab) {
window.close(); window.close();
} else { } else {
// this case can happen if the tab was closed since being checked with `extension.tabs.get` // this case can happen if the tab was closed since being checked with `browser.tabs.get`
log.warn( log.warn(
`Setting current tab to onboarding initiator has failed; falling back to redirect`, `Setting current tab to onboarding initiator has failed; falling back to redirect`,
); );
@ -35,13 +35,13 @@ const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
export const returnToOnboardingInitiator = async (onboardingInitiator) => { export const returnToOnboardingInitiator = async (onboardingInitiator) => {
const tab = await new Promise((resolve) => { const tab = await new Promise((resolve) => {
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
extension.tabs.get(onboardingInitiator.tabId, (tab) => { browser.tabs.get(onboardingInitiator.tabId, (tab) => {
if (tab) { if (tab) {
resolve(tab); resolve(tab);
} else { } else {
// silence console message about unchecked error // silence console message about unchecked error
if (extension.runtime.lastError) { if (browser.runtime.lastError) {
log.debug(extension.runtime.lastError); log.debug(browser.runtime.lastError);
} }
resolve(); resolve();
} }

@ -12040,11 +12040,6 @@ extension-port-stream@^2.0.0, extension-port-stream@^2.0.1:
dependencies: dependencies:
webextension-polyfill-ts "^0.22.0" webextension-polyfill-ts "^0.22.0"
extensionizer@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/extensionizer/-/extensionizer-1.0.1.tgz#504544239a7610ba8404b15c1832091a37768d09"
integrity sha512-UES5CSOYqshNsWFrpORcQR47+ph6UvQK25mguD44IyeMemt40CG+LTZrH1PgpGUHX3w7ACtNQnmM0J+qEe8G0Q==
external-editor@^3.0.3: external-editor@^3.0.3:
version "3.0.3" version "3.0.3"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.0.3.tgz#5866db29a97826dbe4bf3afd24070ead9ea43a27" resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.0.3.tgz#5866db29a97826dbe4bf3afd24070ead9ea43a27"
@ -27761,6 +27756,11 @@ webextension-polyfill@^0.7.0:
resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.7.0.tgz#0df1120ff0266056319ce1a622b09ad8d4a56505" resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.7.0.tgz#0df1120ff0266056319ce1a622b09ad8d4a56505"
integrity sha512-su48BkMLxqzTTvPSE1eWxKToPS2Tv5DLGxKexLEVpwFd6Po6N8hhSLIvG6acPAg7qERoEaDL+Y5HQJeJeml5Aw== integrity sha512-su48BkMLxqzTTvPSE1eWxKToPS2Tv5DLGxKexLEVpwFd6Po6N8hhSLIvG6acPAg7qERoEaDL+Y5HQJeJeml5Aw==
webextension-polyfill@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.8.0.tgz#f80e9f4b7f81820c420abd6ffbebfa838c60e041"
integrity sha512-a19+DzlT6Kp9/UI+mF9XQopeZ+n2ussjhxHJ4/pmIGge9ijCDz7Gn93mNnjpZAk95T4Tae8iHZ6sSf869txqiQ==
webidl-conversions@^3.0.0: webidl-conversions@^3.0.0:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"

Loading…
Cancel
Save