Update icon for Chrome extension

I am developing a Google Chrome extension that changes its icon depending on your IP localization. I am having problems updating after changing the extension icon.

The icon actually changes thanks to this command from my file background.js.

chrome.browserAction.setIcon ( { path: 'france.png' } );

Unfortunately, the command setIconseems asynchronous. Changing the icon actually appears a few seconds after changing the code. Is there a way to get chrome to update badges?

Many chrome extensions seem to be able to control this, but I could not figure out how they handle this.


More details:

To make it clearer, I deleted all my code javascriptfrom different files except the line setIcon. Here is the manifest line that declares my files javascript.

"background": { "scripts": [ "jquery.min.js", "popup.js", "background.js"] },

popup.js: background.js: :

console.log ("I'm background script");
chrome.browserAction.setIcon({path: 'france.png'});

. Chrome html background.js. , .

, , .

- , , , , .

+4
1

webNavigation script:

chrome.webNavigation.onCommitted.addListener(updateIcon);
chrome.webNavigation.onHistoryStateUpdated.addListener(updateIcon);
chrome.webNavigation.onBeforeNavigate.addListener(updateIcon);

function updateIcon(details) {
    if (details.frameId != 0) {
        return; // only update the icon for main page, not iframe/frame
    }
    chrome.browserAction.setIcon({
        path: {19: "france-19.png", 38: "france-38.png"},
        tabId: details.tabId
    });
}

manifest.json webNavigation, .

0

All Articles