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

121
Views
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 answers
Answer question

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 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!