How to keep a contentScript working when the panel changes location

100 views
Skip to first unread message

Michael Witrant

unread,
May 14, 2011, 8:59:47 AM5/14/11
to mozilla-labs-jetpack
Hello,

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://google.com/",
contentScript: 'self.port.on("foo", function() { console.log("foo
received"); });'
});

widget = require("widget").Widget({
id: "test-panel",
label: "test panel",
contentURL: "http://google.com/favicon.ico",
panel: panel
});

panel.on("show", function() {
panel.port.emit("foo");
});
};

Myk Melez

unread,
May 14, 2011, 9:36:09 AM5/14/11
to mozilla-la...@googlegroups.com, Michael Witrant
On 05/14/2011 08:59 PM, Michael Witrant wrote:
> 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?
For now, you should avoid changing the panel's location and only
manipulate the original panel content, since there isn't a way to keep
the content scripts working. But we should probably make the panel's
content scripts get reloaded when its location changes.

-myk

lcamacho

unread,
May 14, 2011, 1:10:42 PM5/14/11
to mozilla-labs-jetpack
But what about if you use an iframe inside of panel and change that
content instead of panel content that probably works

Michael Witrant

unread,
May 15, 2011, 7:09:36 AM5/15/11
to mozilla-la...@googlegroups.com
On Saturday, May 14, 2011 7:10:42 PM UTC+2, lcamacho wrote:
But what about if you use an iframe inside of panel and change that
content instead of panel content that probably works

Indeed, using an iframe  works.

Thank you both.

Irakli Gozalishvili

unread,
May 17, 2011, 10:15:18 AM5/17/11
to mozilla-la...@googlegroups.com
Also please note that iframe is a better option if you need to store state on content side, as otherwise it will be lost on reload.


Regards
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.com/
Address: 29 Rue Saint-Georges, 75009 Paris, France

--
You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
To post to this group, send email to mozilla-la...@googlegroups.com.
To unsubscribe from this group, send email to mozilla-labs-jet...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mozilla-labs-jetpack?hl=en.

Reply all
Reply to author
Forward
0 new messages