Trying to modify my code for when the extension button is clicked, it will execute on all open tabs instead of only the active one.
background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, { file: "jquery-2.1.0.min.js" }, function() {
chrome.tabs.executeScript(null, {file: "change.js"});
});
});
manifest.json
{
"manifest_version": 2,
"name": "GSHOP",
"version": "2",
"description": "I do Stuff",
"background": {
"persistent": false,
"scripts": ["jquery-2.1.0.min.js", "background.js"]
},
"browser_action": {
"name": "Manipulate DOM",
"icons": ["icon.png"],
"default_icon": "icon.png"
},
"permissions": [
"activeTab",
"tabs",
"http://*/*", "https://*/*"
]
}
I believe I have the logic down I just can't figure how to do it. I believe I need to find how many tabs are open tabs.length?
and iterate over them, but I just cannot get it to work.
Doesn't Work
chrome.browserAction.onClicked.addListener(function(tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.executeScript(tabs[i].id, {file: "jquery-2.1.0.min.js" }, function() {
chrome.tabs.executeScript(tabs[i].id, {file: "change.js"});
});
}
});