I am just starting to learn how to create my own addon in firefox. I'm using webExtensions, although I'm finding it hard to get comprehensive documentation (I think because it's still a new implementation?). The code all seems to work fine, and it completes an 'onExecuted' function after the executeScript call. But my injected script (output.js) doesn't seem to fire. After running the code I get the following error in the javascript console: "No matching message handler". I wasn't sure whether the injected script is supposed to be a self contained js file, or if it is just a collection of js commands. I tried the latter too (just a simple message box), and that didn't work either.
My code: manifest.json:
{
"manifest_version": 2,
"name": "ExportTabs",
"version": "0.9",
"description": "Export/Import Tabs",
"icons": {
"48": "icons/export48.png"
},
"permissions": [
"tabs",
"activeTab",
"<all_urls>"
],
"applications": {
"gecko": {
"id": "[email protected]"
}
},
"browser_action": {
"default_icon": "icons/export.png",
"default_popup": "popup/popup.html"
}
}
My popup.html when the addon button is pressed:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div>
<button onclick="save()">Save Tabs</button>
<button onclick="view()">View Tabs</button>
</div>
<script src="popup.js"></script>
</body>
</html>
The popup.js file:
function save() {
chrome.tabs.create({"url": chrome.extension.getURL("popup/output.html")}, onCreated);
}
function onCreated(newTab) {
chrome.tabs.executeScript(newTab.id, {
file: "popup/output.js",
allFrames: true
}, onExecuted);
}
function onExecuted(result) {
alert("inside onExecuted");
}
ouput.html for the newly created tab:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div>testing stuff</div>
<div id="output"></div>
</body>
</html>
output.js for the above page:
//output.js
(function() {
alert("inside output.js");
})();
I should add that I've got noscript addon, so have tried this with "allow scripts globally" and it still gives the same error. Cheers for any help.
edit: I tried replacing the file: "popup/output.js", in the executeScript method with code: 'alert("hello");', and it still didn't work.
Information moved from Answer posted by OP:
Bump. I tried this code out on another box with ff50.something (beta channel), and the injection doesn't even make 'onExecuted'. But it doesn't throw any errors. Basically the popup works, and then nothing happens after that.