Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Safari support
Browse files Browse the repository at this point in the history
Fixes #10
fregante committed Jan 8, 2021
1 parent c0a84bf commit 442ded8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -89,17 +89,27 @@ function updateItem({tabId}: {tabId: number}): void {
}

async function togglePermission(tab: chrome.tabs.Tab, toggle: boolean): Promise<void> {
// Don't use non-ASCII characters because Safari breaks the encoding in executeScript.code
const safariError = 'The browser didn\'t supply any information about the active tab.';
if (!tab.url && toggle) {
throw new Error(`Please try again. ${safariError}`);
}

if (!tab.url && !toggle) {
throw new Error(`Couldn't disable the extension on the current tab. ${safariError}`);
}

const permissionData = {
origins: [
new URL(tab.url!).origin + '/*'
]
};

if (!toggle) {
return p(chrome.permissions.remove, permissionData);
return p(chrome.permissions.remove.bind(chrome.permissions), permissionData);
}

const userAccepted = await p(chrome.permissions.request, permissionData);
const userAccepted = await p(chrome.permissions.request.bind(chrome.permissions), permissionData);
if (!userAccepted) {
chrome.contextMenus.update(contextMenuId, {
checked: false

0 comments on commit 442ded8

Please sign in to comment.