Skip to content

Commit

Permalink
Update webextension-polyfill (#4320)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod authored Oct 8, 2024
1 parent c5e60a2 commit 16db6fa
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/adblocker-webextension-example/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { browser } from 'webextension-polyfill-ts';
import { browser } from 'webextension-polyfill';

import {
BlockingResponse,
Expand Down
3 changes: 2 additions & 1 deletion packages/adblocker-webextension-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
"dependencies": {
"@cliqz/adblocker-webextension": "^1.33.2",
"@cliqz/adblocker-webextension-cosmetics": "^1.33.2",
"webextension-polyfill-ts": "^0.26.0"
"webextension-polyfill": "^0.12.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^12.1.0",
"@types/chrome": "^0.0.277",
"@types/webextension-polyfill": "^0.12.1",
"eslint": "^9.3.0",
"rimraf": "^6.0.1",
"rollup": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/adblocker-webextension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ On Chromium-based browsers you will need a polyfill such as
`webextension-polyfill` to get this working:

```javascript
import { browser } from 'webextension-polyfill-ts';
import { browser } from 'webextension-polyfill';
import { WebExtensionBlocker } from '@cliqz/adblocker-webextension';

WebExtensionBlocker.fromPrebuiltAdsAndTracking().then((blocker) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/adblocker-webextension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.1",
"@types/node": "^22.0.2",
"@types/webextension-polyfill": "^0.12.1",
"chai": "^5.1.0",
"eslint": "^9.3.0",
"mocha": "^10.2.0",
Expand All @@ -63,7 +64,7 @@
"@cliqz/adblocker": "^1.33.2",
"@cliqz/adblocker-content": "^1.33.2",
"tldts-experimental": "^6.0.14",
"webextension-polyfill-ts": "^0.26.0"
"webextension-polyfill": "^0.12.0"
},
"contributors": [
{
Expand Down
18 changes: 15 additions & 3 deletions packages/adblocker-webextension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { Browser, Runtime, WebRequest, WebNavigation } from 'webextension-polyfill-ts';
import { Browser, Runtime, WebRequest, WebNavigation } from 'webextension-polyfill';
import { parse } from 'tldts-experimental';

import {
Expand Down Expand Up @@ -369,7 +369,13 @@ export class BlockingContext {
this.browser.runtime !== undefined &&
this.browser.runtime.onMessage !== undefined
) {
this.browser.runtime.onMessage.addListener(this.onRuntimeMessage);
this.browser.runtime.onMessage.addListener(
this.onRuntimeMessage as (
message: unknown,
sender: Runtime.MessageSender,
sendResponse: (response: unknown) => void,
) => Promise<unknown>,
);
}

if (this.onCommittedHandler) {
Expand All @@ -384,7 +390,13 @@ export class BlockingContext {
}

if (this.browser.runtime !== undefined && this.browser.runtime.onMessage !== undefined) {
this.browser.runtime.onMessage.removeListener(this.onRuntimeMessage);
this.browser.runtime.onMessage.removeListener(
this.onRuntimeMessage as (
message: unknown,
sender: Runtime.MessageSender,
sendResponse: (response: unknown) => void,
) => Promise<unknown>,
);
}

if (this.onCommittedHandler) {
Expand Down
2 changes: 1 addition & 1 deletion packages/adblocker-webextension/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import 'mocha';

import { WebRequest } from 'webextension-polyfill-ts';
import { WebRequest } from 'webextension-polyfill';
import { NetworkFilter } from '@cliqz/adblocker';

import {
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,12 @@ __metadata:
"@rollup/plugin-node-resolve": "npm:^15.2.3"
"@rollup/plugin-typescript": "npm:^12.1.0"
"@types/chrome": "npm:^0.0.277"
"@types/webextension-polyfill": "npm:^0.12.1"
eslint: "npm:^9.3.0"
rimraf: "npm:^6.0.1"
rollup: "npm:^4.0.2"
typescript: "npm:^5.5.2"
webextension-polyfill-ts: "npm:^0.26.0"
webextension-polyfill: "npm:^0.12.0"
languageName: unknown
linkType: soft

Expand All @@ -589,6 +590,7 @@ __metadata:
"@types/chai": "npm:^5.0.0"
"@types/mocha": "npm:^10.0.1"
"@types/node": "npm:^22.0.2"
"@types/webextension-polyfill": "npm:^0.12.1"
chai: "npm:^5.1.0"
eslint: "npm:^9.3.0"
mocha: "npm:^10.2.0"
Expand All @@ -598,7 +600,7 @@ __metadata:
tldts-experimental: "npm:^6.0.14"
tshy: "npm:^3.0.2"
typescript: "npm:^5.5.2"
webextension-polyfill-ts: "npm:^0.26.0"
webextension-polyfill: "npm:^0.12.0"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -2497,6 +2499,13 @@ __metadata:
languageName: node
linkType: hard

"@types/webextension-polyfill@npm:^0.12.1":
version: 0.12.1
resolution: "@types/webextension-polyfill@npm:0.12.1"
checksum: 10/80c1f81af272d378098474a41e0941bf9375261423ea289cd8250efc9a628cec4fa6083cb9cd5c62ff0f828ac235a044c0b95543c0606e894dfd485cea55b0aa
languageName: node
linkType: hard

"@types/yauzl@npm:^2.9.1":
version: 2.10.3
resolution: "@types/yauzl@npm:2.10.3"
Expand Down Expand Up @@ -10538,19 +10547,10 @@ __metadata:
languageName: node
linkType: hard

"webextension-polyfill-ts@npm:^0.26.0":
version: 0.26.0
resolution: "webextension-polyfill-ts@npm:0.26.0"
dependencies:
webextension-polyfill: "npm:^0.8.0"
checksum: 10/8bd18bfdb6b32161f7ac0e4ebe0aa67d494d369b080c73e4d3ef8160c695de50b124518a0d9d1396da3eaa9a0665a797dd9e49fd84be0817f3c845cf81d2863e
languageName: node
linkType: hard

"webextension-polyfill@npm:^0.8.0":
version: 0.8.0
resolution: "webextension-polyfill@npm:0.8.0"
checksum: 10/2ba19ab9246809cc2ec9795cad31728e98ea983b75efb0a1bb144567b95770648dc9a57aa91c11508d610989f7f11228b6a00513c0bae2afda9bc6e5bffd14b3
"webextension-polyfill@npm:^0.12.0":
version: 0.12.0
resolution: "webextension-polyfill@npm:0.12.0"
checksum: 10/77e648b958b573ef075e75a0c180e2bbd74dee17b3145e86d21fcbb168c4999e4a311654fe634b8178997bee9b35ea5808d8d3d3e5ff2ad138f197f4f0ea75d9
languageName: node
linkType: hard

Expand Down

0 comments on commit 16db6fa

Please sign in to comment.