I have a few queries related to contexts in Firefox extensions.
- When we load the scripts from overlay xul do we get access to window/document? If yes, how can I access the web page content from this?
- What is the lifetime of the script loaded from xul, popup and scripts loaded using the
@mozilla.org/moz/jssubscript-loader;1scriptloader? - What is the best way to access the content in the web page from the popup which is non blocking?
Overlays typically apply to
browser.xul– the main browser window. Any scripts that they load are loaded in the context of the browser window which is what the globalwindowanddocumentvariables refer to. You can access the currently selected browser tab viagBrowser.contentWindowandgBrowser.contentDocument(gBrowseris a reference to the<tabbrowser>element).Script loader loads scripts into the context given by the second parameter to
loadSubScript(). If that parameter is omitted then it will load the script into the context of the caller. The script will stay around for at least as long as the context is still around – and longer if there are any external references to it (something that is usually not a good idea).This largely depends by what you consider “a popup”. A XUL dialog? A XUL
<panel>? A webpage opened in a new browser window?