Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extensions: Executing a script on every tab

I'm trying to develop a plugin that affects every tab and window in the browser when the browser action is clicked.

This is the code I currently have:

function updateIcon() {
  chrome.browserAction.setIcon({path:current});

  if (current == "icon-left.png") 
    { 
    current = "icon-right.png"; 
    chrome.tabs.executeScript(null, {file: "cursor.js"});
    }
  else 
    { 
    current = "icon-left.png";
    chrome.tabs.reload(null);
    }
}

Any suggestion?

Thanks

like image 359
slwr Avatar asked Dec 20 '25 05:12

slwr


1 Answers

I solved in this way:

    chrome.tabs.query({}, function (tabs) {
            for (var i = 0; i < tabs.length; i++) {
                chrome.tabs.executeScript(tabs[i].id, {file: "cursor.js"});
            }
        }
    );
like image 172
slwr Avatar answered Dec 21 '25 19:12

slwr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!