Dmitrii G.
Dmitrii G.

Reputation: 899

chrome.tabs.executeScript doesn't work on load

I am trying to load content script from the background one. the execute function works in the icon click block, but i can't trigger the auto load part

var toggle = false;

//Works
chrome.browserAction.onClicked.addListener(function(tab) {
    toggle = !toggle;
    if (!toggle){
        chrome.browserAction.setIcon({path: "enabled.png"});
    }else{
        chrome.browserAction.setIcon({path: "disabled.png"});
        chrome.tabs.executeScript(null, { file: "script.js" });
        // chrome.tabs.executeScript({file : "script.js"});
    }
});


//Doesn't work
chrome.tabs.onUpdated.addListener(function(tab) {
    chrome.tabs.executeScript(null,{
        file: 'script.js'
    }); 
});

Upvotes: 1

Views: 820

Answers (1)

rsanchez
rsanchez

Reputation: 14657

The activeTab permission only grants access to to the currently active tab when the user invokes the extension - for example by clicking its browser action.

If you want to execute a script on any arbitrary tab without user intervention, then you'll need the <all_urls> permission.

Upvotes: 2

Related Questions