Skip to content Skip to sidebar Skip to footer

Chrome Extension: Check If Background Script Is Running

I have a background script that uses the setInterval command to do a network request on a routine basis. I was wondering if the background script can detect if the os goes on slee

Solution 1:

Keep a local variable with the timestamp of the last interval run. On normal (no sleep) execution, the timestamp will be about now-period, but on sleep it will be older so you know you come from a sleep. Also do not rely on the interval as your 'tick' for calculating elapsed time Instead remember the starting timestamp and substract from now()


Post a Comment for "Chrome Extension: Check If Background Script Is Running"