相关疑难解决方法(0)

chrome.browserAction.setIcon没有做任何事情

我正在制作chrome扩展,扩展有两种模式:always on(alwaysOn),或者只有当用户点击它时(onClick).我想根据用户的模式将图标更改为蓝色或红色,以便他们可以一目了然地看到它.但是,添加该chrome.browserAction.setIcon()行后,图标仍然不会在需要时更改.它只是保留在默认徽标上.

这是我的background.js:

// Get the behavior of the plugin; the default is set to "onClick", the other option is "alwaysOn"
chrome.storage.sync.get({
    extensionBehavior: 'onClick'
}, function(items) {
    if(items.extensionBehavior == 'onClick'){
      chrome.browserAction.setIcon({path: "blue-logo.png"});
      chrome.browserAction.onClicked.addListener(function() {
        // When the extension icon is clicked, send a message to the content script
        chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
          chrome.tabs.sendMessage(tabs[0].id, {"message": tabs[0].url}, function(response){});
        });
      });
    }
    else {
      chrome.browserAction.setIcon({path: "red-logo.png"});
      chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {          
        if (changeInfo.status == 'complete') …
Run Code Online (Sandbox Code Playgroud)

javascript browser google-chrome google-chrome-extension google-chrome-devtools

6
推荐指数
2
解决办法
2223
查看次数