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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:54:07+00:00 2026-06-11T09:54:07+00:00

I am making a Firefox add-on that will log how long the user keeps

  • 0

I am making a Firefox add-on that will log how long the user keeps a webpage open in his browser.

I was able to catch the link of every new webpage opening in the browser (both in new tab or in already opened one) by adding a progress listener:

addProgressListener(myAddon_urlBarListener,
                    Components.interfaces.nsIWebProgress.NOTIFY_ALL);

Then I use onLocationChange to get the new URL for a tab.

The problem is that I don’t know the old URL for the tab to be able to stop the timer and to calculate the duration for that webpage. Right now I am only able to calculate time if I close the tab of the webpage because I am able to catch closing tab event and what is the link in the page before closing.

I need a way to catch the URL of old webpage if I open an new URL in the same tab, and this needs to work even if more that one tab is opened in the browser. Btw, I am not working with jQuery but if it is required I will.

  • 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-06-11T09:54:09+00:00Added an answer on June 11, 2026 at 9:54 am

    What if the same URL is opened in two tabs? You should be focusing on tabs, not URLs. Your onLocationChange function should find the <browser> element associated with the tab and just remember its URL (as long as the time). Next time you see the same <browser> element you will have all the information you need. Best way to store data about the browser is currently WeakMap, and finding the <browser> element is possible using tabbrowser.getBrowserForDocument() method. So something like this should work:

    browsers: new WeakMap(),
    
    onLocationChanged: function(webProgress, request, location, flags)
    {
      if (typeof flags == "number" &&
          (flags & Components.interfaces.nsWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT))
      {
        // Ignore anchor changes
        return;
      }
    
      var doc = webProgress.DOMWindow.document;
      var browser = gBrowser.getBrowserForDocument(doc);
      if (this.browsers.has(browser))
      {
        // We know this tab already, record data for previous URL
        var data = this.browsers.get(browser);
        recordPageClosed(data.url, data.startTime);
      }
    
      // Start timer for this tab
      this.browsers.set(browser, {url: location.spec, startTime: Date.now()});
    }
    

    Of course you will still have to handle TabClose event. There you will need tabbrowser.getBrowserForTab() method to find the <browser> element by its corresponding <tab> element.

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

Sidebar

Related Questions

Im currently making a firefox extension that will let you choose what tabs you
I'm making a Firefox Browser Add-on and need to find the url of the
I am making an add-on for firefox and it loads a html page using
Hi I am making a firefox extension which needs to open a link in
I am making a Firefox add-on for which I need to add a pageload
I'm making a Firefox add-on using the Add-on SDK. I can't find a way
I'm working on making an image slider that loads the image the user clicks
Some context: I'm making an add-on for firefox. In firefox add-ons, js scripts can
I am making a software that comes bundled with a firefox extension. In my
I am thinking about making a Firefox add-on of my own and doing some

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.