Chrome Alarms not running every second.

270 views
Skip to first unread message

Bernard Cena

unread,
Nov 7, 2022, 3:07:47 AM11/7/22
to Chromium Extensions
Hi all,

I am having a problem with the chrome alarms. To give context I am using the chrome alarms as a workout for the service worker's limited lifespan. 

I have multiple alarms (mostly max of two running at a time), the first alarm runs every 1 minute. I used it for API calls to update the data in extension, and the second alarm runs when the user performs a certain transaction. The second alarm runs every second and the way I configured or assigned the value periodInMinutes: 1/60. My extension works as intended, I can see the timer updates every second without any issues.

Now the problem is when I submitted my extension for review last weekend. While waiting I just wanted to test the extension using the generated main.crx (the image below). Direct download won't load the crx file. So what I did is after downloading, in chrome I went to the manage extension and drag and dropped the main.crx file which allows me to install it and when I tried it the chrome alarm timer does not run every second (much slower).

Capture.JPG
(I used the main.crx file from draft to test my extension)


My question are
  • Does chrome api behave differently if I used crx instead of dist folder?
  • Does this bug only appear because I installed an unverified crx file?
  • Any work around for this one because if I installed the dist folder generated by webpack it works alright but the moment I used the main.crx from my pending review chrome alarms does not run every second even if I set it to every second.
Sorry for my bad english.

Thanks,
Bernhard Cena

Juraj M.

unread,
Nov 7, 2022, 3:21:08 AM11/7/22
to Chromium Extensions, bern...@playcash.finance
From the docs:

In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after "now" without warning but won't actually cause the alarm to fire for at least 1 minute.

To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.


Juraj M.

unread,
Nov 7, 2022, 3:34:17 AM11/7/22
to Chromium Extensions, Juraj M., bern...@playcash.finance
What exactly are you trying to do that needs 1 second repeating?
There may be multiple workarounds available...

wOxxOm

unread,
Nov 7, 2022, 5:02:43 AM11/7/22
to Chromium Extensions, bern...@playcash.finance
If the periodic work cannot be offloaded to a content script, you'll have to force the worker to stay alive, see https://stackoverflow.com/a/66618269
Reply all
Reply to author
Forward
0 new messages