Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
How to get the time spent on a tab in Chrome?

I am working on a chrome extension, and I need the time spent on each tab. I'm using chrome.tabs api.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Maybe like a "chronometer", init a new Date() when your user open a tab and subtract a new Date() with the init time when your user close a tab?

about 4 years ago · Santiago Trujillo Report

0

You need a timer, storage and tabs permissions and background Script.

The bg script needs an event and then check if its the desired URL:

window.addEventListener('load', function () {
    chrome.tabs.getSelected(null,function(tab){
        myURL=tab.url;
    });

If the desired URL is met, retrieve current timestamp and save it to a variable.

If the user closes the tab or chrome window catch it:

chrome.tabs.onRemoved.addListener(function(tabid, removed) {
 alert("tab closed")
})

chrome.windows.onRemoved.addListener(function(windowid) {
 alert("window closed")
})

Wihtin the catch you get the current timestamp again, calculate end - start and you could save it to e.g. sessionStorage.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!