The reason the icon was reset to default, because I called setIcon before , the tab finishes loading and gets a “full” state.
I suppose that in the documentation on tabs or on the actions of the browser , but I did not find it: the default icon is actually applied in design - to a specific page after the download is complete. I moved the setIcon call to the setIcon handler and now the custom icon is saved.
This contradicts my previous understanding that the browser action icon is set on the basis of each tab, without changes on the page loaded in the tab and its state.
@KonradDzwinel has kindly provided a simple extension to verify the case (look at the comments). I modified its background.js script to demonstrate this behavior:
chrome.browserAction.onClicked.addListener(function(tab) { chrome.browserAction.setIcon({path: 'gfx/icon2.png', tabId: tab.id}); });
To reproduce this behavior, on any tab, click the browser action icon to change it. Then refresh the page. As a result, the browser action icon reset returns to default.
If this is explained in some documents, write it in the comments and I will update the answer. From what I have read so far, I was convinced that the default icon is set for the new tab at the time of its creation, and then any changes in it are exclusively controlled by the extension.
source share