In a Firefox extension using jetpack, I have a panel with a contentScript attached. The panel is set to initially display an URL. If the panel changes its location (through a click on a link or a document.location=), I can’t emit messages to the contentScript anymore (it raises an ERR_DESTROYED, “The page has been destroyed and can no longer be used.”).
Is there a way to keep my contentScript working (or at least reload it) when the location changes? Or should I avoid changing location totally an only manipulate the original panel content?
Here’s a minimal script showing the behavior:
exports.main = function (options, callbacks) {
panel = require("panel").Panel({
contentURL: "http://stackoverflow.com/",
contentScript: 'self.port.on("foo", function() { console.log("foo received"); });'
});
widget = require("widget").Widget({
id: "test-panel",
label: "test panel",
contentURL: "http://stackoverflow.com/favicon.ico",
panel: panel
});
panel.on("show", function() {
panel.port.emit("foo");
});
};
Got an answer from Myk Melez on the Jetpack google group:
Or, as lcamacho said, I can use an iframe inside the panel.