2

I am trying to print some value in console, just to check whether the alarm is working or not, but the alarm does not fire and it doesn't print anything in console, is there anything which is missing?, Here is background.js file

`

// Running a code after every 1 minutes starts

chrome.alarms.create('Health Api Alarm', {
  periodInMinutes: 1,
});

console.log('In background.js');

chrome.alarms.getAll(function (alarms) {
  console.log('All alarms', alarms);
});

chrome.alarms.onAlarm.addListener(function (alarm) {
  console.log('Inside alarm function');
  if (alarm.name === 'Health Api Alarm') {
    let time = new Date().toLocaleTimeString();
    console.log('The current time is ' + time);
  }
});

// Running a code after every 1 minutes ends

`

I tried to print the current time after every one minute, but the alarm did not fired.

  • Why is this marked as duplicate? It's a highly distinct and relevant question about Chrome ManifestV3's unreliable behavior of the Alarm system. I'm also experiencing the Alarms not always firing off and may even completely stop firing after a certain point. I, then, have to restart the extension to get them working again. It's a horrible experience since MV3 is being enforced :/ Fight to get this re-opened. This is NOTHING like the "duplicate" that's pinned! – Prid Jan 06 '23 at 02:57
  • I am also experiencing an issue with chrome.alarms and MV3. Everything works well until I restart the browser. After that, although the alarm is set, it's either not firing at regular intervals or it's not caught by the listener – Sorix Mar 07 '23 at 15:42
  • @Sorix Please check whether you are clearing any alarms, as I was facing same issue, I was using chrome.alarms.clearAll in another file, that was the reason my alarm was not firing. – Saurabh Mhaske Mar 10 '23 at 05:27
  • 1
    @SaurabhMhaske thank you for this. My problem turned out to be related to my handler being registered inside a function, which is not recommended: https://developer.chrome.com/docs/extensions/mv3/service_workers/#listeners – Sorix Mar 10 '23 at 08:52

0 Answers0