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

117
Vistas
How to keep a function running in background.js even when popup.html is out of view

how to keep this timer running even when popup.html is closed?

i am saving the last time in storage so that it resumes from last stopped point but how to keep the setinterval keep running manifest has persistence as true. and this script in background

function timer(){
  if(localStorage.getItem('tile')==null){
    secs=32400;
    }
    
    if(localStorage.getItem('tile')!=null){
      secs=localStorage.getItem('tile');
    }
    console.log(secs);
    if(secs!==0){
     
    function z(n) { return (n < 10 ? '0' : '') + n; }
    var sign = secs < 0 ? '-' : '';
    secs = Math.abs(secs);
    secs = secs-1;
    


chrome.storage.local.get(["actualtime"],function (result){aht = (((Number(result.actualtime))*((13/8)*60))/(28800-secs)/60);
document.getElementById("time2").innerHTML = aht.toFixed(2);
    })
    aht2 = (((secs/60))*((13/8)))/(28800/60);
    document.getElementById("time3").innerHTML = aht2.toFixed(2);
    document.getElementById("counter").innerHTML= sign + z(secs / 3600 | 0) + ':' + z((secs % 3600) / 60 | 0) + ':' + z(secs % 60);
    console.log(localStorage.getItem('actualtime'));
   
    localStorage.setItem('tile',secs);
}

}

setInterval(timer,1000);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

cant use the same js for background as well as for popup.html //mistake i made. ran a seperate js for background and a js for popup.html used msg parsing to communicate between them Background one kept running and the js for popup.html gets called only when popup.html is opened.(and stops when closed)

about 4 years ago · Juan Pablo Isaza 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