Search code examples
javascriptgoogle-chromefirefox-addon-webextensionswebextension-polyfill

browser.alarms is undefined using webextension-polyfill


I'm trying to create an alarm using browser.alarms API for web extensions. To make the extension cross-browser, I am using webextension-polyfill and testing on Chrome.

My code to create an alarm within a background script is shown below:

browser.alarms.create('spline-items-notification', {
  periodInMinutes: 1
});

However, when I attempt to run this extension, I always get an error:

Uncaught TypeError: Cannot read property 'create' of undefined

I am loading webextension-polyfill before the background script in manifest.json, and other interfaces work, like browser.notifications.

I would like to know how to fix this if possible. Thank you.


Solution

  • alarms
    To use this API you need to have the "alarms" permission.

    Does the manifest.json have the "alarms" permission?