Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manifest v3 #61

Merged
merged 6 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions manifest.dev.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"content_security_policy": "default-src 'self'; script-src 'self' 'unsafe-eval';"
}
"content_security_policy": {
"extension_pages": "default-src 'self'; script-src 'self' 'unsafe-eval';"
}
}
14 changes: 9 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -20,15 +20,19 @@
"contextMenus",
"storage",
"nativeMessaging",
"webNavigation",
"webNavigation"
],
"host_permissions": [
"<all_urls>"
],
"content_security_policy": "default-src 'self'",
"content_security_policy": {
"extension_pages": "default-src 'self'"
},
"options_ui": {
"page": "pages/options.html",
"open_in_tab": true
},
"browser_action": {
"action": {
"default_title": "__MSG_cmdSubmitAuto__"
},
"default_locale": "en_US",
Expand Down Expand Up @@ -64,4 +68,4 @@
"description": "__MSG_cmdInsertOther__"
}
}
}
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 15 additions & 10 deletions src/background/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function runCommand(args: CommandArgs): Promise<void> {

await backend.connect();
if (backend.state !== BackendConnectionState.Connected) {
chrome.runtime.openOptionsPage();
void chrome.runtime.openOptionsPage();
return;
}

Expand Down Expand Up @@ -97,17 +97,23 @@ function isValidUrl(url: string): boolean {

async function getActiveFrame(tab: chrome.tabs.Tab): Promise<number> {
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[]) => {
(result: chrome.scripting.InjectionResult<void>[]) => {
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
}
);
});
Expand Down Expand Up @@ -189,9 +195,8 @@ async function sendMessageToTab(

function injectPageContentScript(tab: chrome.tabs.Tab): Promise<number> {
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);
Expand Down
4 changes: 2 additions & 2 deletions src/background/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 10 additions & 7 deletions src/background/transport/transport-browser-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ class TransportBrowserTab extends TransportBase {

private injectContentScript(): Promise<void> {
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();
}
}
});
);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/background/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 });
});
}
2 changes: 1 addition & 1 deletion src/options/components/shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Loading