So I have an extension I'm writing and I'm trying to execute a script when the user clicks on the pageAction icon. When the icon is clicked, the method calls chrome.tabs.executeScript(...). The problem is that the chrome.tabs.executeScript function is not executing and I can't tell why. I know that I'm getting to the code where it calls executeScript because I have an alert there that appears. Here is some of my code:
manifest.json
{ "manifest_version": 2, "name": "name here", "description": "description here", "version": "0.1", "permissions": [ "<all_urls>", "tabs" ], "icons": { "16" : "images/icon16.png", "48" : "images/icon48.png", "128": "images/icon128.png" }, "background": { "scripts": ["js/check.js"] }, "page_action": { "default_icon": { "19": "images/icon19.png", "38": "images/icon38.png" }, "default_title": "default title here" } } js/check.js
chrome.tabs.onUpdated.addListener(checkForValidUrl); function checkForValidUrl(tabId, changeInfo, tab) { if (tab.url.indexOf('g') > -1) { chrome.pageAction.show(tabId); } }; chrome.pageAction.onClicked.addListener(function(tab) { alert("hello world"); //this code is executed... //...this code is not chrome.tabs.executeScript(tab.id, {file: "save.js"}, function() { if(chrome.runtime.lastError) { console.error(chrome.runtime.lastError.message); } }); }); js/save.js
alert("hello world"); Like I say in the code, the hello world in my pageAction onClick function works. The executeScript method does not. Any idea about what is going on would be helpful.
console.error(...)code that should fire after theexecuteScript(...)method returns is never called, so that hasn't helped me.