Vivek
Vivek

Reputation: 700

Context of scripts in Firefox extensions

I have a few queries related to contexts in Firefox extensions.

  1. 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?
  2. What is the lifetime of the script loaded from xul, popup and scripts loaded using the @mozilla.org/moz/jssubscript-loader;1 scriptloader?
  3. What is the best way to access the content in the web page from the popup which is non blocking?

Upvotes: 0

Views: 270

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57671

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?

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 global window and document variables refer to. You can access the currently selected browser tab via gBrowser.contentWindow and gBrowser.contentDocument (gBrowser is a reference to the <tabbrowser> element).

What is the lifetime of the script loaded from xul, popup and scripts loaded using the @mozilla.org/moz/jssubscript-loader;1 scriptloader?

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).

What is the best way to access the content in the web page from the popup which is non blocking?

This largely depends by what you consider "a popup". A XUL dialog? A XUL <panel>? A webpage opened in a new browser window?

Upvotes: 1

Related Questions