Skip to content

Instantly share code, notes, and snippets.

@mchubby
Created March 19, 2017 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchubby/280102dcba6b209accb46d861304933f to your computer and use it in GitHub Desktop.
Save mchubby/280102dcba6b209accb46d861304933f to your computer and use it in GitHub Desktop.
insertCSS-all-testcase: manifest.json permission testcase (https://developer.chrome.com/extensions/declare_permissions)
const CSS = "body { background-color: #999; }"
// update when the extension loads initially (all tabs)
browser.tabs.query({}).then((tabs) => {
for (tab of tabs) {
initializePageAction(tab);
}
});
/*
// also listen to tab URL changes, same handler
browser.tabs.onUpdated.addListener((id, changeInfo, tab) => {
if (!changeInfo.url || changeInfo.status !== "status") {
return;
}
initializePageAction(tab);
});
*/
function initializePageAction(tab) {
if (!tab.url.match(/^about:/)) {
console.log('::: insertCSS on tab #' + tab.id)
console.log(tab)
browser.tabs.insertCSS(tab.id, {code: CSS});
console.log('---')
}
}
{
"manifest_version": 2,
"name": "insertCSS-all testcase",
"description": "A testcase for insertCSS",
"version": "1.0",
"applications": {
"gecko": {
"strict_min_version": "54.0a1"
}
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"<all_urls>",
"activeTab",
"storage",
"tabs"
]
}
{
"manifest_version": 2,
"name": "insertCSS-all testcase",
"description": "A testcase for insertCSS",
"version": "1.0",
"applications": {
"gecko": {
"strict_min_version": "54.0a1"
}
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"activeTab",
"storage",
"tabs",
"<all_urls>"
]
}
@mchubby
Copy link
Author

mchubby commented Mar 19, 2017

Hmm, I take this back. It actuallyworks after restarting the browser and reloading the web extension

@mchubby
Copy link
Author

mchubby commented Mar 20, 2017

Well, it seems to be iffy. Sometimes works, but rarely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment