Skip to content

Commit a72b4f6

Browse files
authored
Fix Chrome MV3 deregistration + cleanup internal types (#57)
1 parent 5df5c68 commit a72b4f6

File tree

6 files changed

+59
-51
lines changed

6 files changed

+59
-51
lines changed

package-lock.json

Lines changed: 49 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@
6363
"dependencies": {
6464
"content-scripts-register-polyfill": "^3.2.2",
6565
"webext-additional-permissions": "^2.3.0",
66-
"webext-content-scripts": "^2.4.0",
66+
"webext-content-scripts": "^2.5.3",
6767
"webext-detect-page": "^4.0.1",
6868
"webext-patterns": "^1.2.0",
6969
"webext-polyfill-kinda": "^0.10.0"
7070
},
7171
"devDependencies": {
7272
"@parcel/config-webextension": "^2.8.2",
7373
"@sindresorhus/tsconfig": "^3.0.1",
74-
"@types/chrome": "^0.0.208",
75-
"@types/firefox-webext-browser": "^94.0.1",
74+
"@types/chrome": "^0.0.220",
75+
"@types/firefox-webext-browser": "^111.0.0",
7676
"@types/jest": "^29.2.5",
7777
"jest": "^29.3.1",
7878
"jest-chrome": "^0.8.0",

source/global.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

source/including-active-tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function injectToTabUnlessRegistered({id: tabId, origin}: ActiveTab): Prom
2828
: [{frameId: 0, url: origin}];
2929

3030
// .map() needed for async loop
31-
frames.map(async ({frameId, url}) => injectIfActive({frameId, url, tabId}));
31+
frames?.map(async ({frameId, url}) => injectIfActive({frameId, url, tabId}));
3232
}
3333

3434
async function injectIfActive(

source/inject-to-existing-tabs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {getTabsByUrl, injectContentScript} from 'webext-content-scripts';
22

3+
type ManifestContentScripts = NonNullable<chrome.runtime.Manifest['content_scripts']>;
4+
35
export async function injectToExistingTabs(
46
origins: string[],
57
scripts: ManifestContentScripts,

source/register-content-script-shim.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ export const chromeRegister = globalThis.chrome?.scripting?.registerContentScrip
44
export const firefoxRegister = globalThis.browser?.contentScripts?.register;
55

66
export async function registerContentScript(
7-
contentScript: ChromeContentScript,
7+
contentScript: Omit<chrome.scripting.RegisteredContentScript, 'id' | 'world'> & {matches: string[]},
88
): Promise<browser.contentScripts.RegisteredContentScript> {
99
if (chromeRegister) {
1010
const id = 'webext-dynamic-content-script-' + JSON.stringify(contentScript);
1111
try {
1212
await chromeRegister([{
13-
id,
1413
...contentScript,
14+
id,
1515
}]);
1616
} catch (error) {
1717
if (!(error as Error)?.message.startsWith('Duplicate script ID')) {
@@ -20,15 +20,15 @@ export async function registerContentScript(
2020
}
2121

2222
return {
23-
unregister: async () => chrome.scripting.unregisterContentScripts([id]),
23+
unregister: async () => chrome.scripting.unregisterContentScripts({ids: [id]}),
2424
};
2525
}
2626

2727
const firefoxContentScript = {
2828
...contentScript,
2929
js: contentScript.js?.map(file => ({file})),
3030
css: contentScript.css?.map(file => ({file})),
31-
};
31+
} as const;
3232

3333
if (firefoxRegister) {
3434
return firefoxRegister(firefoxContentScript);

0 commit comments

Comments
 (0)