From f00203b941ba27ade15c1c83fb9df86f40bf17a2 Mon Sep 17 00:00:00 2001 From: Daeho Kim Date: Wed, 27 Sep 2023 15:24:20 +0900 Subject: [PATCH] fix: migrate webextension-polyfill-ts to Mozilla's (#1723) --- package.json | 3 ++- src/background/index.ts | 2 +- .../service/keyring/eth-bitbox02-keyring.ts | 2 +- src/background/service/notification.ts | 2 +- src/background/service/preference.ts | 2 +- src/background/webapi/notification.ts | 4 ++-- src/background/webapi/storage.ts | 2 +- src/background/webapi/tab.ts | 2 +- src/background/webapi/window.ts | 2 +- src/content-script/index.ts | 1 - src/ui/utils/webapi.ts | 2 +- src/utils/index.ts | 2 +- src/utils/ledger.ts | 2 +- src/utils/matomo-request.ts | 2 +- src/utils/message/portMessage.ts | 2 +- yarn.lock | 20 +++++++++---------- 16 files changed, 25 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index f19b55f7e50..0ffba264dd0 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "uuid": "^9.0.0", "web3-eth-abi": "^1.7.0", "web3-utils": "^1.7.0", - "webextension-polyfill-ts": "^0.25.0" + "webextension-polyfill": "^0.10.0" }, "devDependencies": { "@sentry/webpack-plugin": "^1.18.9", @@ -135,6 +135,7 @@ "@types/react-router-dom": "^5.1.7", "@types/semver-compare": "^1.0.1", "@types/sinon": "^10.0.13", + "@types/webextension-polyfill": "^0.10.2", "@typescript-eslint/eslint-plugin": "^5.13.0", "@typescript-eslint/parser": "^4.22.1", "@welldone-software/why-did-you-render": "^6.2.1", diff --git a/src/background/index.ts b/src/background/index.ts index c8954149ffa..fcfb0b39163 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -1,7 +1,7 @@ import { groupBy } from 'lodash'; import 'reflect-metadata'; import * as Sentry from '@sentry/browser'; -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; import { ethErrors } from 'eth-rpc-errors'; import { WalletController } from 'background/controller/wallet'; import { Message } from '@/utils'; diff --git a/src/background/service/keyring/eth-bitbox02-keyring.ts b/src/background/service/keyring/eth-bitbox02-keyring.ts index bb495a8378f..df2ed344716 100644 --- a/src/background/service/keyring/eth-bitbox02-keyring.ts +++ b/src/background/service/keyring/eth-bitbox02-keyring.ts @@ -1,6 +1,6 @@ import 'regenerator-runtime/runtime'; import EventEmitter from 'events'; -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; import { BitBox02API, getDevicePath, constants } from 'bitbox02-api'; diff --git a/src/background/service/notification.ts b/src/background/service/notification.ts index 29e925c48e0..b280d56c59b 100644 --- a/src/background/service/notification.ts +++ b/src/background/service/notification.ts @@ -1,4 +1,4 @@ -import { Windows, browser } from 'webextension-polyfill-ts'; +import browser, { Windows } from 'webextension-polyfill'; import Events from 'events'; import { ethErrors } from 'eth-rpc-errors'; import { v4 as uuidv4 } from 'uuid'; diff --git a/src/background/service/preference.ts b/src/background/service/preference.ts index 801b94db766..469ce853d7b 100644 --- a/src/background/service/preference.ts +++ b/src/background/service/preference.ts @@ -9,7 +9,7 @@ import { } from './index'; import { TotalBalanceResponse, TokenItem } from './openapi'; import { HARDWARE_KEYRING_TYPES, EVENTS, CHAINS_ENUM, LANGS } from 'consts'; -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; import semver from 'semver-compare'; const version = process.env.release || '0'; diff --git a/src/background/webapi/notification.ts b/src/background/webapi/notification.ts index bccce9bd805..1d7e5ecea34 100644 --- a/src/background/webapi/notification.ts +++ b/src/background/webapi/notification.ts @@ -1,4 +1,4 @@ -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; import { createTab } from './tab'; browser.notifications.onClicked.addListener((url) => { @@ -17,7 +17,7 @@ const create = ( browser.notifications.create(url && `${url}_randomId_=${randomId}`, { type: 'basic', title, - iconUrl: browser.extension.getURL('./images/icon-64.png'), + iconUrl: browser.runtime.getURL('./images/icon-64.png'), message, priority, }); diff --git a/src/background/webapi/storage.ts b/src/background/webapi/storage.ts index 2d6284c3e17..7c3e02860d1 100644 --- a/src/background/webapi/storage.ts +++ b/src/background/webapi/storage.ts @@ -1,4 +1,4 @@ -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; let cacheMap; diff --git a/src/background/webapi/tab.ts b/src/background/webapi/tab.ts index b1d2a87b30b..7fc24597d85 100644 --- a/src/background/webapi/tab.ts +++ b/src/background/webapi/tab.ts @@ -1,4 +1,4 @@ -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; import { EventEmitter } from 'events'; const tabEvent = new EventEmitter(); diff --git a/src/background/webapi/window.ts b/src/background/webapi/window.ts index e2ea25bff8a..89542f65968 100644 --- a/src/background/webapi/window.ts +++ b/src/background/webapi/window.ts @@ -1,4 +1,4 @@ -import { browser, Windows } from 'webextension-polyfill-ts'; +import browser, { Windows } from 'webextension-polyfill'; import { EventEmitter } from 'events'; import { IS_WINDOWS } from 'consts'; diff --git a/src/content-script/index.ts b/src/content-script/index.ts index 9fa7187ee9e..6ef8159e257 100644 --- a/src/content-script/index.ts +++ b/src/content-script/index.ts @@ -1,6 +1,5 @@ import { Message } from '@/utils'; import { nanoid } from 'nanoid'; -import { browser } from 'webextension-polyfill-ts'; const channelName = nanoid(); diff --git a/src/ui/utils/webapi.ts b/src/ui/utils/webapi.ts index af6405a432d..94393bad4ff 100644 --- a/src/ui/utils/webapi.ts +++ b/src/ui/utils/webapi.ts @@ -1,4 +1,4 @@ -import { Tabs, browser, Windows } from 'webextension-polyfill-ts'; +import browser, { Tabs, Windows } from 'webextension-polyfill'; import { WalletController, WalletControllerType } from './index'; import { getOriginFromUrl } from '@/utils'; diff --git a/src/utils/index.ts b/src/utils/index.ts index 2670abe2db3..d3390c87d1e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,6 @@ import { CHAINS } from '@/constant'; import { keyBy } from 'lodash'; -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; import { ledgerUSBVendorId } from '@ledgerhq/devices'; import BroadcastChannelMessage from './message/broadcastChannelMessage'; diff --git a/src/utils/ledger.ts b/src/utils/ledger.ts index bae4eac452f..c74a63c73ee 100644 --- a/src/utils/ledger.ts +++ b/src/utils/ledger.ts @@ -1,7 +1,7 @@ import { ledgerUSBVendorId } from '@ledgerhq/devices'; import { useEffect, useState } from 'react'; import { hasConnectedLedgerDevice } from '@/utils'; -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; export enum LedgerHDPathType { LedgerLive = 'LedgerLive', diff --git a/src/utils/matomo-request.ts b/src/utils/matomo-request.ts index cb95849b16e..f443b6f54d2 100644 --- a/src/utils/matomo-request.ts +++ b/src/utils/matomo-request.ts @@ -1,5 +1,5 @@ import { customAlphabet, nanoid } from 'nanoid'; -import { browser } from 'webextension-polyfill-ts'; +import browser from 'webextension-polyfill'; const ANALYTICS_PATH = 'https://matomo.debank.com/matomo.php'; const genExtensionId = customAlphabet('1234567890abcdef', 16); diff --git a/src/utils/message/portMessage.ts b/src/utils/message/portMessage.ts index 2ea271107b0..77a0e651c43 100644 --- a/src/utils/message/portMessage.ts +++ b/src/utils/message/portMessage.ts @@ -1,4 +1,4 @@ -import { Runtime, browser } from 'webextension-polyfill-ts'; +import browser, { Runtime } from 'webextension-polyfill'; import Message from './index'; class PortMessage extends Message { port: Runtime.Port | null = null; diff --git a/yarn.lock b/yarn.lock index e6e11119181..2f4c5764248 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4702,6 +4702,11 @@ resolved "https://registry.yarnpkg.com/@types/web/-/web-0.0.80.tgz#bbf499be42b0e4ec1c417b89fde51e5afe062044" integrity sha512-HLbRwqCL5VVkmpAAzqRGXDkUO4teKhOOY2FJDHQl3k5OTuDTPzkI74AJSoGaS6oHOVVYhI/X5Ahw/ltC8KZQuw== +"@types/webextension-polyfill@^0.10.2": + version "0.10.2" + resolved "https://registry.yarnpkg.com/@types/webextension-polyfill/-/webextension-polyfill-0.10.2.tgz#14175d96d76339fce4d2b9b7837846148296cb5a" + integrity sha512-L+T72DVTi/1azY6gw7PRmL49kvobLKQQWfOmHDBRSCkAvaCV4wk222J3ZODYA9Gf/UqUvtItu8FPJgWX5ktO9g== + "@types/ws@^7.2.0": version "7.4.7" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.7.tgz#f7c390a36f7a0679aa69de2d501319f4f8d9b702" @@ -14871,13 +14876,6 @@ web3-utils@^1.6.0: randombytes "^2.1.0" utf8 "3.0.0" -webextension-polyfill-ts@^0.25.0: - version "0.25.0" - resolved "https://registry.yarnpkg.com/webextension-polyfill-ts/-/webextension-polyfill-ts-0.25.0.tgz#fff041626365dbd0e29c40b197e989a55ec221ca" - integrity sha512-ikQhwwHYkpBu00pFaUzIKY26I6L87DeRI+Q6jBT1daZUNuu8dSrg5U9l/ZbqdaQ1M/TTSPKeAa3kolP5liuedw== - dependencies: - webextension-polyfill "^0.7.0" - webextension-polyfill-ts@^0.26.0: version "0.26.0" resolved "https://registry.yarnpkg.com/webextension-polyfill-ts/-/webextension-polyfill-ts-0.26.0.tgz#80b7063ddaf99abaa1ca73aad0cec09f306612d3" @@ -14885,10 +14883,10 @@ webextension-polyfill-ts@^0.26.0: dependencies: webextension-polyfill "^0.8.0" -webextension-polyfill@^0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.7.0.tgz#0df1120ff0266056319ce1a622b09ad8d4a56505" - integrity sha512-su48BkMLxqzTTvPSE1eWxKToPS2Tv5DLGxKexLEVpwFd6Po6N8hhSLIvG6acPAg7qERoEaDL+Y5HQJeJeml5Aw== +webextension-polyfill@^0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz#ccb28101c910ba8cf955f7e6a263e662d744dbb8" + integrity sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g== webextension-polyfill@^0.8.0: version "0.8.0"