Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda