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 7681151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:16:36+00:00 2026-05-31T18:16:36+00:00

I am a Firefox C++ extension newbie. I need to get access to DOM

  • 0

I am a Firefox C++ extension newbie. I need to get access to DOM mutation events in my extension during page load. Firefox by default doesn’t send DOM mutation events during page load to improve page load performance.

I understand the reason, but understanding the consequences I still need access to the DOM mutation events. I read somewhere that nsIMutationObserver still gets invoked during page load (and is bit more efficient then DOM mutation events as don’t have to walk up the DOM tree looking for listeners), however it’s only available to native code.

So I have following questions :

  1. Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?
  2. If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?
  3. If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.
  4. Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?

BTW, I asked this question in Firefox’s extension forum, but no replies there.

Thanks in advance

  • 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-31T18:16:38+00:00Added an answer on May 31, 2026 at 6:16 pm

    Is nsIMutationObserver and nsIMutationObserver2 available to Firefox extensions?

    Yes, binary Firefox extensions can use it. Of course, the drawback is that your binary XPCOM component will only work with one Firefox release – it will have to be recompiled for each new release.

    If yes, how can I write a simple Firefox extension in C++ to get access to it and expose it to Javascript?

    You create an XPCOM component (see example code) and implement nsIMutationObserver interface. You then attach this mutation observer to documents like this:

    NS_IMETHODIMP
    MyMutationObserver::AttachToDocument(nsIDOMDocument* document)
    {
      nsCOMPtr<nsINode> node(do_QueryInterface(document));
      node->AddMutationObserver(this);
    }
    

    For reference: nsINode interface

    If folks can point me to a existing extension that does this forwarding from C++ land to JS, that will be highly appreciated.

    Sorry, don’t know any. But your XPCOM component can expose an additional interface that your JavaScript code will use – e.g. to register a callback. You have to consider that it might not be safe to run JavaScript when the mutation observer gets called. Important methods here: nsContentUtils::IsSafeToRunScript() and nsContentUtils::AddScriptRunner() (see nsContentUtils.h).

    Or can I use JS-CTypes to get access to that functionality from my Javascript based extension?

    No, you cannot. These are Gecko internals, they aren’t exposed to js-ctypes.

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

Sidebar

Related Questions

In my Firefox extension I need to get the element boundary on which the
I'm writing a firefox extension and really need to listen on TabOpen events and
I'm writing a firefox extension in javascript, from that script I need to access
Within my Firefox extension I'd like to detect the source of a page load
I am developing a Firefox extension and I need to perform some high-speed calculations
I'm writing a Firefox extension and I need to find the ip address of
I am developing a firefox extension, i need to detect which operating system firefox
I'm writing a Firefox extension that's to be used in house. Basically, I need
I'm developing a Firefox extension. There is a menu X which I need to
I am building a firefox extension and need to insert some elements and css

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.