Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 579879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:24:46+00:00 2026-05-13T14:24:46+00:00

is it possible for Firefox extension (toolbar) to access document’s variables? detailed explanation follows..

  • 0

is it possible for Firefox extension (toolbar) to access document’s variables? detailed explanation follows..

loaded document:

<script type="text/javascript">
var variableForExtension = 'something';
</script>

extension:

var win = window.top.getBrowser().selectedBrowser.contentWindow;
alert(win.variableForExtension); // undefined

it was first thing to try, and it’s inaccessible this way because of security mechanisms (XPCNativeWrapper). i’ve read about accessing it trough wrappedJSObject and using events (adding listener to document and dispatching event from extension), but no luck. didn’t try too hard, though. so, before i dig deeper (‘events method’ sounds like a way to go) i’d like to know is this even possible?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:24:47+00:00Added an answer on May 13, 2026 at 2:24 pm

    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.

    1) If you control the web page and want to pass information to the extension, you should indeed use the events technique. This worked and was/is safe in all Firefox versions.

    2) If you want to read a value from the content document, you can just bypass the XPCNativeWrapper:

    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!
    

    This was unsafe prior to Firefox 3. In Firefox 3 and later it is OK to use, you get another kind of wrapper (XPCSafeJSObjectWrapper), 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.

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to 'translate' headers from this firefox extension into server side script?
Is it possible to make a Firefox extension so everytime you access a certains
Possible Duplicate: Google Analytics to track FireFox extension use I tried injecting a script
I'm working on a Firefox extension that will manipulate highlighted text. On a stand-alone
I was wondering if it's possible to write Firefox extension using .Net Framework? Had
I open my Firefox extension window in a browser's tab. Is it possible to
Is it possible to access Firefox info from my program? Specificly I need to
Is it possible to access Chrome/Firefox extensions/plugins like ghostery from a Java program? The
Is threaded behaviour for Firefox extension possible? I mean to have a thread running
For Firefox, it is possible to detect if a Firefox extension is installed using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.