views:

402

answers:

2

I'm trying to run a hosted script with content privileges in my Firefox extension. To do this, I create a content iframe in the hidden window pointed at a html file that pulls the script. This script requires the 'history' be available, but the iframes created in the hidden window have no history for some reason.

Chromebug reports this for the iframe's contentWindow.history:

object does not support history (nsIDOMHistory)

And the script gives this error when its not available:

Error: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHistory.length]

Any ideas?

A: 

A <browser type="content"> will automatically wire up session history by default, while an <iframe type="content"> will not, but you could always wire it up yourself manually.

Don't forget to ensure that your element is created in the XUL namespace. I believe the hidden window is the about:blank HTML document except on the Mac.

Neil
I've tried this with the same result. Here was the code I used for that, where doc is the hidden window's document. var browser = doc.createElementNS(XUL_NS_URI, 'browser') browser.setAttribute('type', 'content'); browser.setAttribute('disablehistory', false); browser.setAttribute('src', url); doc.documentElement.appendChild(browser);
Jon
A: 

It turns out that the hidden window's URL used to be about:blank, but this was apparently a security flaw, so it is now resource://gre/res/hiddenWindow.html (or resource://gre-resources/hiddenWindow.html on trunk) so it doesn't have the chrome privileges that a XUL browser element needs in order to be able to wire up its own session history, or even to access its own content document.

Even using a XUL iframe element you have to be careful since none of its properties work, again because it is running without chrome privileges. So you have to do stuff like iframeElement.boxObject.QueryInterface(Components.interfaces.nsIContainerBoxObject).docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow) to retrieve its content window.

Neil
Trying to edit in an update to my post, but stack overflow is giving errors when I try. You're right about the hidden window. My extension has a chrome iframe in the hidden window (used as a singleton js context). I can embed the browser there and wire in the sessionHistory manually. It works! Thank you.
Jon