0

I have developed a Chrome extension on manifest v3, which is using two alarms to trigger simple events on schedule.

One alarm is scheduled to run every minute, another one every 20 minutes. Both of these alarms as well as the onAlarm event listener function are set up in the main service worker script.

However, occasionally (and I have yet to find any reproducible pattern for when it happens), my extension completely stops bothering about alarms. At some point, the onAlarm code just won't be invoked, not even with a delay.

  • I confirmed that the two alarms are properly set up by checking chrome.alarms.getAll(console.log) in the service worker console. Both show up with their next scheduled runtime.
  • I also confirmed that the alarm listeners are registered by my extension, both on chrome://extensions-internals and via chrome.alarms.onAlarm.hasListeners()

This usually doesn't happen right away, more so after a few hours or days. Thus, it could be that it's something that happens when my computer goes into sleep.
Still, I can't have my app stop working whenever I take a pause. In that case at least I would need some way to catch the behavior and restart the extension.


Some further observations:

  • although the alarms don't seem to fire an observable alarm event, they repeat as expected and an alarm for the next period is always correctly scheduled
  • I can add new alarm listeners which are also not triggered by my alarms - eg. chrome.alarms.onAlarm.addListener(console.info)
  • I can add new alarms, which also don't seem to trigger anything - eg. chrome.alarms.create("hello", { delayInMinutes: 1}) - they just silently disappear
  • I can dispatch an alarm event manually, which then causes all my registered handlers to run as expected - eg. chrome.alarms.onAlarm.dispatch({name: "yo"})
  • I do not get any error messages from my extension

What could cause this behavior? How can alarms be scheduled correctly, but not make it to onAlarm, except when events are fired manually?

Also, more importantly: how can I catch this behavior and make sure to get the alarms back up?


// Update (for reference):
I realized that my question has some overlap with the issues and solutions discussed here:

alex_jwb90
  • 1,663
  • 1
  • 11
  • 20
  • 1
    https://crbug.com/1368619 – wOxxOm Jun 26 '23 at 12:41
  • thx. trying to combat this with one of the solutions from the related thread: https://bugs.chromium.org/p/chromium/issues/detail?id=1316588#c113 - it seems that indeed, the issue appears only after a certain time of inactivity – alex_jwb90 Jun 26 '23 at 13:53

0 Answers0