问题
Since last night, i'm getting this error out of the blue, when trying to communicate with a content script, after the "ready" event is fired in the tab that loads the page to which the script is being attached to.
console.error:
JPM [error] Message: TypeError: this.sandbox is undefined
Stack:
receive@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/content/worker-child.js:87:7
emitOnObject@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:112:9
emit@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:89:38
messageReceived@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/remote/child.js:67:37
In desperation i even tried copy pasting the code from the mozilla website:
in index.js:
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
contentScriptFile: data.url("element-getter.js"),
onAttach: function(worker) {
worker.port.emit("myCustomEvent", "mymessage");
worker.port.on("backEvent", function(content) {
console.log(content);
});
}
});
in element.getter.js:
self.port.on("myCustomEvent", function(message) {
self.port.emit("backEvent", "newMessage");
});
Same error appears wen trying to communicate via workers, between main script and content scripts, using the "tabs" sdk module.
EDIT: Can someone else please if confirm/deny this behavior?
Any ideas are welcome!
I've submitted a bug report here: https://bugzilla.mozilla.org/show_bug.cgi?id=1314557
回答1:
Soo.. if you don't "jpm init" in the new folder, and copy-paste the contents of another, previously initialized folder, inside - you get the above error. Mistake on my part.
来源:https://stackoverflow.com/questions/40375547/firefox-sdk-extension-jpm-error