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

180
Views
Script run in background without waiting for input

so I managed to my script work even when when popup is closed but the script doesnt react on button it keeps refreshing the site, could you guys help me and tell me what is wrong in this background.js? I have separate content.js and html file.


function startref() {

    let intervalId = setInterval(function () {
        chrome.tabs.query({ active: true, currentWindow: true }, function (arrayOfTabs) {
            var code = 'window.location.reload();';
            chrome.tabs.executeScript(arrayOfTabs[0].id, { code: code });


        });

    }, 3000);
    localStorage.setItem('refresh', intervalId);
}


function stop() {
    const intervalId = localStorage.getItem("refresh");
    clearInterval(intervalId);
}

window.onload = function () {
    var sta = document.getElementById("startbtn");
    var sto = document.getElementById("stopbtn");
    document.addEventListener('DOMContentLoaded', function () {
        sta.addEventListener('click', startref);

    });


    document.addEventListener('DOMContentLoaded', function () {
        sto.addEventListener('click', stop);

    });
    if (localStorage.getItem("refresh")) {
        startref();
        

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