Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, accessing a JS variable in content is and always was possible. Doing this the naive way wasn't safe (in the sense that a malicious web page could get chrome privileges) in older Firefox versions.</p> <p>1) If you control the web page and want to pass information to the extension, you should indeed use the <a href="https://developer.mozilla.org/En/Code_snippets:Interaction_between_privileged_and_non-privileged_pages#Sending_data_from_unprivileged_document_to_chrome" rel="noreferrer">events technique</a>. This worked and was/is safe in all Firefox versions.</p> <p>2) If you want to read a value from the content document, you can just bypass the XPCNativeWrapper:</p> <pre><code>var win = window.top.getBrowser().selectedBrowser.contentWindow; // By the way, this could just be // var win = content; // or // var win = gBrowser.contentWindow; alert(win.variableForExtension); // undefined win.wrappedJSObject.variableForExtension // voila! </code></pre> <p>This was unsafe prior to Firefox 3. In Firefox 3 and later it is OK to use, you get another kind of wrapper (<a href="https://developer.mozilla.org/en/XPConnect_wrappers#XPCSafeJSObjectWrapper" rel="noreferrer">XPCSafeJSObjectWrapper</a>), which looks the same as the object from the content page to your code, but ensures the content page won't be able to do anything malicious.</p> <p>3) If you need to call a function in a content web page or run your own code in the page's context, it's more complicated. It was asked and answered elsewhere many times, but unfortunately never documented fully. Since this is unrelated to your question, I won't go into the details.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload