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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:15:47+00:00 2026-05-21T09:15:47+00:00

I need to be able to make an event such that every time a

  • 0

I need to be able to make an event such that every time a user loads a new page and closes firefox, I need it to call a method in my C# application that takes care of maintaining the user model. I know for sure I need to create some type of firefox extension where I use javascript to check such an event. However, I have no idea how I am going to integrate my C# application with the firefox extension. Can someone provide me with some guidance?

  • 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-21T09:15:48+00:00Added an answer on May 21, 2026 at 9:15 am

    I’ll help you out with the parts of the question that I’m familiar with (Javascript based add-ons), and offer some suggestions for the other parts. Here goes nothing!

    Add-ons

    Firefox add-ons easily provide the tools you need to detect page loads and opening / closing firefox.

    To detect page loads you can register a listener to the DOMContentLoaded event in window.

    window.addEventListener("DOMContentLoaded", function(event){
        var url = event.originalTarget.location.href;
        alert("Oh yeah, a document is loading: " + url);
    }, false);
    

    Alternatively, you can register a nsIWebProgressListener to listen for location changes. This probably closer to what you want, since DOMContentLoaded is also triggered for iframes.

    var listener = {
        //unimplemented methods (just give functions which do nothing)
        onLocationChange: function(aWebProgress, aRequest, aLocation){
            var url = aLocation.asciiSpec;
            alert("Oh yeah, a the location changed: " + url);
        }
    };
    gBrowser.addTabsProgressListener(listener);
    

    To detect firefox open / close you need to first understand how firefox add-ons work with respect to multiple windows. When a new window of firefox is launched, you basically have 2 separate copies of your code running. So, if you care about firefox windows being opened and closed you can simply do:

    window.addEventListener("load", function(event){ 
        alert("Looks like you just opened up a new window");
    }, false);
    
    window.addEventListener("unload", function(event){
        alert("Awh, you closed a window");
    }, false);
    

    But, most likely you want to detect opening / closing firefox as an entire application. This is achieved using a code-sharing mechanism called Javascript Modules. Javascript modules are loaded just once for the lifetime of the application. So, they enable you to share information between windows. Simply counting the number of windows opened and closed should be sufficient for this functionality.

    var EXPORTED_SYMBOLS = ["windowOpened", "windowClosed"];
    var windowsOpened = 0;
    function windowOpened(){
        if( windowsOpened === 0) {
            alert("The first window has been opened!");
        }
        windowsOpened++;
    }
    
    function windowClosed(){
        windowsOpened++;
        if( windowsOpened === 0) {
            alert("The last window has been closed!");
        }
    }
    

    Then you can simply attach the aforementioned event handlers to call these 2 methods from their corresponding load and unload events.

    So, this is all great and everything, but now you have to twiddle with the details of getting a baseline Firefox add-on setup. Fortunately, Mozilla has provided a handy Addon Builder to ease this. All the code about (except the Javascript module) should be placed in the ff-overlay.js file (assuming you use the linked builder).

    C# communication

    I’m a little less knowledgeable about the interprocess communication with C#. However, maybe I can point you in the right direction and let the smart people at SO fill in the rest.

    I believe COM Objects are a method of communication between processes on Windows. So, you could build in a Binary Component to your add-on to perform the communication. However, as far as I understand it, setting up binary components is much more difficult than a standard javascript-based add-on. Either way, Mozilla provides a guide for setting it up in Visual Studio.

    If you want to stay away from binary components you are left with the javascript enabled components of the SDK. This includes socket communication, files, pipes, a sqlite database etc. This SO question addresses exactly the question you’re asking. If it were me, I would choose them in this order.

    1. Sqlite Database
    2. Named Pipes
    3. Sockets

    (1) because there is a lot of code samples available for this, and would be easy to implement on both sides. (2) because this would be the way I’d implement IPC if I were given full control of both sides of the application. (3) is last because I hate that crap (maybe I’m biased from Distributed Systems in college).

    tl;dr

    The page load stuff should be pretty simple. Check out the Addon Builder to get going with a FF addon, and here to see about detecting page loads.

    The C# communication is doable, and addressed in this SO Question. I’d do it with a sqlite database for ease if it were me.

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

Sidebar

Related Questions

I need to be able to make a program that looks through a mailbox
I need to be able to make a tree like structure in the appengine
In my current project (presentation, slide software) I need to be able to make
We need to make our enterprise ASP.NET/NHibernate browser-based application able to function when connected
I need to be able to get at the full URL of the page
I need to be able to get a list of the groups a user
I tried to make an exception class (lets call it EXP) that will be
I have team members that need to be able to checkin VBA modules/classes created
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to

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.