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

chore: manifest v3 (#916) #1608

Open
wants to merge 3 commits into
base: v5
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/bg/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void (async function main() {
function initToolbarButton(): void {
Menu.createSettingsMenu()

browser.browserAction.onClicked.addListener((_, info): void => {
browser.action.onClicked.addListener((_, info): void => {
if (info && info.button === 1) browser.runtime.openOptionsPage()
else browser.sidebarAction.toggle()
})
Expand Down
9 changes: 6 additions & 3 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"manifest_version": 2,
"manifest_version": 3,
"browser_specific_settings": {
"gecko": {
"id": "{3c078156-979c-498b-8990-85f7987dd929}",
Expand Down Expand Up @@ -28,13 +28,13 @@
"storage",
"unlimitedStorage",
"sessions",
"scripting",
"menus",
"menus.overrideContext",
"search",
"theme"
],
"optional_permissions": [
"<all_urls>",
"proxy",
"webRequest",
"webRequestBlocking",
Expand All @@ -44,6 +44,9 @@
"history",
"downloads"
],
"host_permissions": [
"<all_urls>"
],
"sidebar_action": {
"default_icon": "./assets/logo-native.svg",
"default_title": "Sidebery",
Expand Down Expand Up @@ -424,7 +427,7 @@
"description": "__MSG_KbSortPanelTabsByTimeDes__"
}
},
"browser_action": {
"action": {
"default_icon": "./assets/logo-native.svg",
"default_title": "__MSG_ActionTitle__",
"default_area": "navbar",
Expand Down
16 changes: 12 additions & 4 deletions src/services/menu.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,23 @@ export function createSettingsMenu(): void {
id: 'open_settings',
title: translate('menu.browserAction.open_settings'),
icons: { '16': 'assets/logo-native.svg' },
onclick: () => browser.runtime.openOptionsPage(),
contexts: ['browser_action'],
contexts: ['action'],
})
browser.menus.create({
id: 'create_snapshot',
title: translate('menu.browserAction.create_snapshot'),
icons: { '16': 'assets/snapshot-native.svg' },
onclick: () => Snapshots.createSnapshot(),
contexts: ['browser_action'],
contexts: ['action'],
})
browser.menus.onClicked.addListener((info, tab) => {
switch (info.menuItemId) {
case 'open_settings':
browser.runtime.openOptionsPage()
break
case 'create_snapshot':
Snapshots.createSnapshot()
break
}
})
}

Expand Down
6 changes: 3 additions & 3 deletions src/services/search.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ export function start(): void {

const hasFocus = document.hasFocus()
if (!hasFocus) {
browser.browserAction.setPopup({ popup: SEARCH_URL })
browser.browserAction.openPopup()
browser.action.setPopup({ popup: SEARCH_URL })
browser.action.openPopup()
Search.reactive.barIsActive = true

// Reset browser action
setTimeout(() => browser.browserAction.setPopup({ popup: null }), 500)
setTimeout(() => browser.action.setPopup({ popup: null }), 500)
}

showBar()
Expand Down
48 changes: 28 additions & 20 deletions src/services/tabs.bg.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,22 +514,26 @@ export async function initInternalPageScripts(tabs: Tab[]) {

export function injectUrlPageScript(winId: ID, tabId: ID) {
try {
browser.tabs
.executeScript(tabId, {
file: '/injections/url.js',
runAt: 'document_start',
matchAboutBlank: true,
browser.scripting
.executeScript({
files: ['/injections/url.js'],
target: { tabId },
injectImmediately: true,
})
.catch(err => {
Logs.warn('Tabs.injectUrlPageScript: Cannot inject script, tabId:', tabId, err)
})
const initData = getUrlPageInitData(winId, tabId)
const initDataJson = JSON.stringify(initData)
browser.tabs
.executeScript(tabId, {
code: `window.sideberyInitData=${initDataJson};window.onSideberyInitDataReady?.()`,
runAt: 'document_start',
matchAboutBlank: true,
browser.scripting
.executeScript<[string], void>({
args: [initDataJson],
func: (initDataJson: string) => {
window.sideberyInitData = JSON.parse(initDataJson);
window.onSideberyInitDataReady?.()
},
target: { tabId },
injectImmediately: true,
})
.catch(() => {
Logs.warn('Tabs.injectUrlPageScript: Cannot inject init data, reloading tab (if active)...')
Expand Down Expand Up @@ -576,22 +580,26 @@ export async function injectGroupPageScript(winId: ID, tabId: ID): Promise<void>
injectingGroup.add(tabId)

try {
browser.tabs
.executeScript(tabId, {
file: '/injections/group.js',
runAt: 'document_start',
matchAboutBlank: true,
browser.scripting
.executeScript({
files: ['/injections/group.js'],
target: { tabId },
injectImmediately: true,
})
.catch(err => {
Logs.warn('Tabs.injectGroupPageScript: Cannot inject script, tabId:', tabId, err)
})
const initData = await getGroupPageInitData(winId, tabId)
const initDataJson = JSON.stringify(initData)
browser.tabs
.executeScript(tabId, {
code: `window.sideberyInitData=${initDataJson};window.onSideberyInitDataReady?.()`,
runAt: 'document_start',
matchAboutBlank: true,
browser.scripting
.executeScript<[string], void>({
args: [initDataJson],
func: (initDataJson: string) => {
window.sideberyInitData = JSON.parse(initDataJson);
window.onSideberyInitDataReady?.()
},
target: { tabId },
injectImmediately: true,
})
.catch(() => {
Logs.warn('Tabs.injectGroupPageScript: Cannot inject init data, reloading tab')
Expand Down
24 changes: 16 additions & 8 deletions src/services/tabs.fg.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,15 +1156,23 @@ export async function discardTabs(tabIds: ID[] = []): Promise<void> {

// Try to reset closing prevention and discard such tabs
if (Settings.state.forceDiscard && Permissions.allUrls && secondTryIds.length) {
const forceDiscardInjection =
'window.onbeforeunload=null;window.addEventListener("beforeunload", e => {e.returnValue=""})'
await Promise.allSettled(
secondTryIds.map(id => {
return browser.tabs.executeScript(id, {
code: forceDiscardInjection,
runAt: 'document_start',
allFrames: true,
})
secondTryIds.map(async (id) => {
return browser.scripting.executeScript({
func: () => {
window.onbeforeunload = null;
window.addEventListener("beforeunload", e => {
e.stopPropagation()
e.returnValue = ''
}, { capture: true })
},
injectImmediately: true,
target: {
tabId: id,
allFrames: true
},
world: 'MAIN'
}).then(console.log).catch(console.error)
})
)

Expand Down
Loading