Created
March 19, 2017 23:14
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('---') | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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>" | |
] | |
} |
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
Hmm, I take this back. It actuallyworks after restarting the browser and reloading the web extension