1

The following manifest is supposed to load the off.png browser action icon, but when I shut Chrome down while the on.png icon is active, it loads the same on icon automatically for some reason when I start up Chrome.

Is this some sort of a bug?

Manifest:

{
"background": {
   "scripts": ["js/bg/bg.js" ],
   "persistent": false
},
"browser_action": {
  "default_icon": "style/off.png",
  "default_title": "__MSG_mainTitle__"
},
"default_locale": "en",
"description": "__MSG_description__",
"icons": {
  "128": "style/on.png"
},
"manifest_version": 2,
"name": "__MSG_name__",
"offline_enabled": true,
"version": "2.5.5"
}

bg.js:

chrome.browserAction.onClicked.addListener(function(){
    chrome.browserAction.setIcon({path: "/style/" + 'on' + ".png"})
});
Niko
  • 369
  • 1
  • 3
  • 14
  • I think this is not a bug, I've tested some extensions that I am using and it behaves differently. It may depend on how you code it. Some extension retains the icon based on the last status (e.g. **keep the browser screen on**) or some refresh the icon once the browser is closed (e.g. **page refresher**). – Mr.Rebot Apr 09 '18 at 16:56
  • @Mr.Rebot The code I've presented is the simplest way I know to change an icon on click. If this doesn't work, I can't understand how other code does. Have you found a pattern that always work? – Niko Apr 10 '18 at 11:07
  • You have to use either local storage or [`chrome.storage` API](https://developer.chrome.com/extensions/storage) to retain the status of your chrome extension. You can check [Xan's answer](https://stackoverflow.com/a/23341124/5995040) he gave a details instruction when using either of the two method. – Mr.Rebot Apr 10 '18 at 11:48

0 Answers0