setInterval, setTimeout and chrome.alarms API don't work in chrome extension background script after waking PC/Mac from long standby

Viewed 392

I develop a chrome extension. My chrome extension allows to open as much as you need extension instances (it means different chrome windows with one tab). All main extension logic (including authorization) stores in my background script. I should automatically refresh user token every hour. And I should to it inside background script because it can be the situation when there are 0 opened chrome extension windows. So the problem is that if I leave my iMac in sleep-mode for a long time (e.g. for overnight) when I wake my iMac and watch in the console of background script I don't see the logs that a regular interval callback runs. I tried to use both setInterval and chrome.alarms API. But nothing works.

There are too little information in the internet. But after reading at least what is on the Internet, I was able to conclude that since background.html script hasn't tab (if we consider it like simple web page) the Chrome browser can decide that the user is inactive because he doesn't work on background.html tab. And my another assumption is that Chrome browser can decide to clear interval or alarm due to long iMac standby and inactivity.

So the question is how I can implement the solution for token auto refreshing which will be stable?

P.S. I'm testing my chrome extension both on a PC and on a Mac (I have windows laptop and iMac). And for some reason I notice from the console logs that there is much more activity on the Mac during sleep mode. It often happens that on windows laptop I see console logs only when I wake up it after long standby (I notice it by checking the logs time). And on windows laptop I noticed once that the a regular interval callback worked after long standby. But it was only once, I test it every morning last several days.

P.S.S. Since I develop the chrome extension only the Chrome browser can be considered.

ENV info:

  • OS: Mac OS Big Sur 11.2
  • Chrome browser: Version 89.0.4389.82 (Official Build) (x86_64)
  • CPU: (4) x64 Intel(R) Core(TM) i7 CPU @ 4.0GHz
0 Answers
Related