How to call function in certain time interval Ask Question

I need to run a certain API function, in a certain time period once the access token is granted, and check the status and inform the user if there any changes.

So far i did it by clicking a button on popup window of the firefox addon and calling the functions background js files, so i can receive the info from the API and notify the user. But i need to automate this process in background js files.

Are there any firefox inbuild JS API or any other way to achieve this auto API request calling from addon background files?

One thought on “How to call function in certain time interval Ask Question”

  1. Yes, there is, the setInterval() function.

    let inter = setInterval(() => {
        console.log('HI!');
    }, 1000);
    

    To stop the timer, just call: clearInterval(inter);

    More info about setInterval() here.

Leave a Reply

Your email address will not be published. Required fields are marked *