From 394c23ece956b22500fbf1dbcfca4cd8af6056c1 Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Mon, 24 Jun 2024 22:29:47 -0400 Subject: [PATCH 1/6] Update manifest.json for manifest v3 https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/ --- manifest.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 2f62eed..7b974d4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "KeeWeb Connect", "version": "0.3.7", - "manifest_version": 2, + "manifest_version": 3, "description": "__MSG_description__", "icons": { "16": "icons/icon16.png", @@ -20,7 +20,9 @@ "contextMenus", "storage", "nativeMessaging", - "webNavigation", + "webNavigation" + ], + "host_permissions": [ "" ], "content_security_policy": "default-src 'self'", @@ -28,7 +30,7 @@ "page": "pages/options.html", "open_in_tab": true }, - "browser_action": { + "action": { "default_title": "__MSG_cmdSubmitAuto__" }, "default_locale": "en_US", @@ -64,4 +66,4 @@ "description": "__MSG_cmdInsertOther__" } } -} \ No newline at end of file +} From e391588ae63b2969811a3815e3ed139d7fda82b8 Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Mon, 24 Jun 2024 22:30:17 -0400 Subject: [PATCH 2/6] Update browser_style for manifest v3 --- src/background/ui.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/background/ui.ts b/src/background/ui.ts index 14a3d3b..61fff3f 100644 --- a/src/background/ui.ts +++ b/src/background/ui.ts @@ -96,7 +96,7 @@ export function createUIMenus(): void { } export function bindExtensionButtonClick(): void { - chrome.browserAction.onClicked.addListener(async (tab) => { + chrome.action.onClicked.addListener(async (tab) => { await runCommand({ command: 'submit-auto', tab }); }); } From 8b8b9106c42a0d635f7e2b6d2fbbbefbfb4ae8c4 Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Mon, 24 Jun 2024 22:57:10 -0400 Subject: [PATCH 3/6] Use Scripting API --- src/background/commands.ts | 19 ++++++++++++------- .../transport/transport-browser-tab.ts | 17 ++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/background/commands.ts b/src/background/commands.ts index 6fe13ec..d6b7078 100644 --- a/src/background/commands.ts +++ b/src/background/commands.ts @@ -97,11 +97,17 @@ function isValidUrl(url: string): boolean { async function getActiveFrame(tab: chrome.tabs.Tab): Promise { return new Promise((resolve) => { - chrome.tabs.executeScript( - tab.id || 0, + chrome.scripting.executeScript( { - frameId: 0, - code: "Array.from(document.querySelectorAll('iframe')).indexOf(document.activeElement)" + target: { + frameIds: [0], + tabId: tab.id || 0 + }, + func: () => { + Array.from(document.querySelectorAll('iframe')).indexOf( + document.activeElement as HTMLIFrameElement + ); + } }, (results: number[]) => { if (chrome.runtime.lastError) { @@ -189,9 +195,8 @@ async function sendMessageToTab( function injectPageContentScript(tab: chrome.tabs.Tab): Promise { return new Promise((resolve) => { - chrome.tabs.executeScript( - tab.id || 0, - { file: 'js/content-page.js', allFrames: true }, + chrome.scripting.executeScript( + { files: ['js/content-page.js'], target: { allFrames: true, tabId: tab.id || 0 } }, (results) => { if (chrome.runtime.lastError) { return resolve(0); diff --git a/src/background/transport/transport-browser-tab.ts b/src/background/transport/transport-browser-tab.ts index a56c85e..1493ff1 100644 --- a/src/background/transport/transport-browser-tab.ts +++ b/src/background/transport/transport-browser-tab.ts @@ -106,14 +106,17 @@ class TransportBrowserTab extends TransportBase { private injectContentScript(): Promise { return new Promise((resolve, reject) => { - chrome.tabs.executeScript(this._tab!.id!, { file: 'js/content-keeweb.js' }, () => { - if (chrome.runtime.lastError) { - const msg = `Content script injection error: ${chrome.runtime.lastError.message}`; - reject(new Error(msg)); - } else { - resolve(); + chrome.scripting.executeScript( + { files: ['js/content-keeweb.js'], target: { tabId: this._tab!.id! } }, + () => { + if (chrome.runtime.lastError) { + const msg = `Content script injection error: ${chrome.runtime.lastError.message}`; + reject(new Error(msg)); + } else { + resolve(); + } } - }); + ); }); } From b23f62894250a281e6e5e10d04e7a681aa31636d Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Mon, 24 Jun 2024 23:10:40 -0400 Subject: [PATCH 4/6] Bump chrome types --- package-lock.json | 14 +++++++------- package.json | 2 +- src/background/commands.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 144f63d..cfa431f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "tweetnacl": "^1.0.3" }, "devDependencies": { - "@types/chrome": "^0.0.134", + "@types/chrome": "^0.0.268", "@types/copy-webpack-plugin": "^8.0.0", "@types/node": "^20.12.10", "@types/webpack": "^5.28.5", @@ -1070,9 +1070,9 @@ "dev": true }, "node_modules/@types/chrome": { - "version": "0.0.134", - "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.134.tgz", - "integrity": "sha512-NlYHk+a0Bq6kTvGT4s2w1G3UuDBeoZJYJL1wzmEIusBKYyDDtdl37kOz3Hzb/NEC2KNdnOBVoYLS2opQYsF1Vw==", + "version": "0.0.268", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.268.tgz", + "integrity": "sha512-7N1QH9buudSJ7sI8Pe4mBHJr5oZ48s0hcanI9w3wgijAlv1OZNUZve9JR4x42dn5lJ5Sm87V1JNfnoh10EnQlA==", "dev": true, "dependencies": { "@types/filesystem": "*", @@ -11760,9 +11760,9 @@ "dev": true }, "@types/chrome": { - "version": "0.0.134", - "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.134.tgz", - "integrity": "sha512-NlYHk+a0Bq6kTvGT4s2w1G3UuDBeoZJYJL1wzmEIusBKYyDDtdl37kOz3Hzb/NEC2KNdnOBVoYLS2opQYsF1Vw==", + "version": "0.0.268", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.268.tgz", + "integrity": "sha512-7N1QH9buudSJ7sI8Pe4mBHJr5oZ48s0hcanI9w3wgijAlv1OZNUZve9JR4x42dn5lJ5Sm87V1JNfnoh10EnQlA==", "dev": true, "requires": { "@types/filesystem": "*", diff --git a/package.json b/package.json index e534704..b4835b1 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/antelle/keeweb-connect#readme", "devDependencies": { - "@types/chrome": "^0.0.134", + "@types/chrome": "^0.0.268", "@types/copy-webpack-plugin": "^8.0.0", "@types/node": "^20.12.10", "@types/webpack": "^5.28.5", diff --git a/src/background/commands.ts b/src/background/commands.ts index d6b7078..10f34fd 100644 --- a/src/background/commands.ts +++ b/src/background/commands.ts @@ -109,11 +109,11 @@ async function getActiveFrame(tab: chrome.tabs.Tab): Promise { ); } }, - (results: number[]) => { + (result: chrome.scripting.InjectionResult[]) => { if (chrome.runtime.lastError) { return resolve(0); } - resolve(results[0] + 1); // indexOf returns -1, then it's root document which is frameId:0 + resolve(Number(result[0]) + 1); // indexOf returns -1, then it's root document which is frameId:0 } ); }); From fd5251d11939d72c2c117147035ff6252c53d14c Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Mon, 24 Jun 2024 23:23:45 -0400 Subject: [PATCH 5/6] Type fixes --- src/background/commands.ts | 2 +- src/background/init.ts | 4 ++-- src/background/ui.ts | 2 +- src/options/components/shortcuts.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/background/commands.ts b/src/background/commands.ts index 10f34fd..4b921ec 100644 --- a/src/background/commands.ts +++ b/src/background/commands.ts @@ -53,7 +53,7 @@ async function runCommand(args: CommandArgs): Promise { await backend.connect(); if (backend.state !== BackendConnectionState.Connected) { - chrome.runtime.openOptionsPage(); + void chrome.runtime.openOptionsPage(); return; } diff --git a/src/background/init.ts b/src/background/init.ts index e54f39d..fbe702c 100644 --- a/src/background/init.ts +++ b/src/background/init.ts @@ -10,8 +10,8 @@ chrome.runtime.onStartup.addListener(startAndReportError); chrome.runtime.onInstalled.addListener((e) => { startAndReportError() .then(() => { - if (e.reason === 'install') { - chrome.runtime.openOptionsPage(); + if (e.reason === ('install' as chrome.runtime.OnInstalledReason)) { + void chrome.runtime.openOptionsPage(); } }) .catch(noop); diff --git a/src/background/ui.ts b/src/background/ui.ts index 61fff3f..77d3c3a 100644 --- a/src/background/ui.ts +++ b/src/background/ui.ts @@ -9,7 +9,7 @@ export function createUIMenus(): void { const command = e.menuItemId as string; if (command === 'settings') { - chrome.runtime.openOptionsPage(); + void chrome.runtime.openOptionsPage(); return; } diff --git a/src/options/components/shortcuts.tsx b/src/options/components/shortcuts.tsx index d20e648..8128dc5 100644 --- a/src/options/components/shortcuts.tsx +++ b/src/options/components/shortcuts.tsx @@ -6,7 +6,7 @@ import { canEditShortcuts, shortcutsCanBeEditedOnlyManually } from 'common/featu const Shortcuts: FunctionComponent = () => { const openShortcuts = (e: Event) => { e.preventDefault(); - chrome.tabs.create({ url: 'chrome://extensions/shortcuts', active: true }); + void chrome.tabs.create({ url: 'chrome://extensions/shortcuts', active: true }); }; return ( From 2389bd1c9075f86110411c7d6d085ef0376cb6c8 Mon Sep 17 00:00:00 2001 From: Kevin McCormack Date: Mon, 24 Jun 2024 23:29:20 -0400 Subject: [PATCH 6/6] Update manifest --- manifest.dev.json | 6 ++++-- manifest.json | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/manifest.dev.json b/manifest.dev.json index 547700d..b8310e3 100644 --- a/manifest.dev.json +++ b/manifest.dev.json @@ -1,3 +1,5 @@ { - "content_security_policy": "default-src 'self'; script-src 'self' 'unsafe-eval';" -} \ No newline at end of file + "content_security_policy": { + "extension_pages": "default-src 'self'; script-src 'self' 'unsafe-eval';" + } +} diff --git a/manifest.json b/manifest.json index 7b974d4..3711003 100644 --- a/manifest.json +++ b/manifest.json @@ -25,7 +25,9 @@ "host_permissions": [ "" ], - "content_security_policy": "default-src 'self'", + "content_security_policy": { + "extension_pages": "default-src 'self'" + }, "options_ui": { "page": "pages/options.html", "open_in_tab": true