I'm working on my first Chrome extension. I have a default popup popup.html
which loads popup.js
.
I used serg's answer to Chrome's tabs.executeScript - passing parameters and using libraries? as inspiration for the popup->page interaction.
The problem is that the following click handler in popup.js
works:
function click(e) {
chrome.browserAction.setBadgeText ( { text: "loading" } );
chrome.tabs.executeScript(null,
{code:"globalVarName = {'scriptOptions': {...}};" },
chrome.tabs.executeScript(null, {file: "js/script.js"},
chrome.browserAction.setBadgeText ( { text: "done" } ))
);
window.close();
}
But the following does not:
function click(e) {
chrome.browserAction.setBadgeText ( { text: "loading" } );
chrome.tabs.executeScript(null,
{code:"globalVarName = {'scriptOptions': {...}};" },
chrome.tabs.executeScript(null, {file: "js/script.js"},
function(){chrome.browserAction.setBadgeText ( { text: "done" } );})
);
window.close();
}
I want to be able to do more than one thing on completion.
Edit:
I've realised that the first case immediately executes chrome.browserAction.setBadgeText()
, not when the script has finished executing. So that case can be ignored. I've reworded the question title to reflect this.
What I'm looking for is why the second case's callback doesn't execute at all.