Skip to content

Commit

Permalink
Restore MV2 demo extension (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Jan 18, 2024
1 parent 8893525 commit b5ec864
Show file tree
Hide file tree
Showing 6 changed files with 2,583 additions and 1,450 deletions.
15 changes: 6 additions & 9 deletions demo/background.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import chromeP from 'webext-polyfill-kinda';
import addDomainPermissionToggle from '..';

console.log('Extension ready. Reload any tab to see the logs.');

addDomainPermissionToggle();

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (!tab.url) {
console.log('No access to tab', tabId);
return;
}

console.log('Access to tab', tabId, tab.url);
chrome.scripting.executeScript({
target: {tabId},
function() {
document.body.style.backgroundColor = 'yellow';
console.log('chrome.tabs.onUpdated was fired');
},
});
const why = await chromeP.permissions.contains({origins: [tab.url]}) ? 'granted' : 'just because of activeTab';
console.log('Access to tab', tabId, tab.url, why);
});
19 changes: 19 additions & 0 deletions demo/mv2/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "webext-domain-permission-toggle",
"version": "0.0.0",
"manifest_version": 2,
"permissions": [
"https://*.github.com/*",
"activeTab",
"contextMenus"
],
"browser_action": {},
"optional_permissions": [
"*://*/*"
],
"background": {
"scripts": [
"../background.js"
]
}
}
2 changes: 1 addition & 1 deletion demo/manifest.json → demo/mv3/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"*://*/*"
],
"background": {
"service_worker": "background.js",
"service_worker": "../background.js",
"type": "module"
}
}
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default function addDomainPermissionToggle(options?: Options): void {
// Remove any existing context menu item and silence any error
chrome.contextMenus.remove(contextMenuId, () => chrome.runtime.lastError);

const contexts: chromeP.contextMenus.ContextType[] = 'browser_action' in chrome
const contexts: chromeP.contextMenus.ContextType[] = manifest.manifest_version === 2
? ['page_action', 'browser_action']
: ['action'];

Expand Down
Loading

0 comments on commit b5ec864

Please sign in to comment.