Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda