Is it possible to change button background color on page load event but so far I did not find any such method at all. If it is not possible then I am happy to use some pre-defined images that loads up after page load.
I have tried the following, without success:
script.js
// chrome.browserAction.setIcon("red.png");
chrome.browserAction.setIcon({path:'red.png'});
manifest.json
{
"name": "Domain Colors",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [{
"matches": ["http://*/*"],
"js": ["script.js"]
}],
"permissions": [ "tabs", "http://*/*" ],
"browser_action": {
"default_title": "Colry",
"default_icon": "blue.png"
}
}
In order to use the
browserActionAPI, a background page is required. If you want to keep your current control flow (update icon via a content script), you need to pass messages. Here’s the bare minimum:The manifest file needs one additional entry:
You don’t need content scripts for the purpose of detecting page loads. A single event listener can be used (in the background page):
Have a close look at the documentation of
chrome.browserAction.setBadgeBackgroundColor. There are also lots of examples using the browserAction API, you should be able to get a working extension yourself by looking at these samples.