Chrome Extension error: “Unchecked runtime.lastError while running browserAction.setIcon: No tab with id”

后端 未结 1 887
不知归路
不知归路 2020-12-18 18:37

I\'m coding my Google Chrome Extension where I set the app\'s icon from the background script as such:

try
{
    objIcon = {
        \"19\": \"image         


        
相关标签:
1条回答
  • 2020-12-18 19:23

    Include a callback and check chrome.runtime.lastError.

    objIcon = {
        "19": "images/icon19.png",
        "38": "images/icon38.png"
    };
    
    function callback() {
        if (chrome.runtime.lastError) {
            console.log(chrome.runtime.lastError.message);
        } else {
            // Tab exists
        }
    }
    
    chrome.browserAction.setIcon({
        path: objIcon,
        tabId: nTabID
    
    }, callback);
    
    0 讨论(0)
提交回复
热议问题