Helper for chrome.alarms
API.
To use the chrome.alarms
API, declare the "alarms"
permission in the manifest:
{
"name": "My extension",
"permissions": ["alarms"]
}
You can install this library using npm:
npm install chrome-alarms
Key | Type | Optional | Description |
---|---|---|---|
name |
string | Name of this alarm. | |
periodInMinutes |
number | ◯ | If not null, the alarm is a repeating alarm and will fire again in periodInMinutes minutes. |
Creates an alarm. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
import { Alarm } from "chrome-alarms";
const name = "test";
const periodInMinutes = 1;
await Alarm.create(name, periodInMinutes);
Clears the alarm with the given name.
import { Alarm } from "chrome-alarms";
const name = "test";
await Alarm.clear(name);
Clears all alarms.
import { Alarm } from "chrome-alarms";
await Alarm.clearAll();
Retrieves details about the specified alarm.
import { Alarm } from "chrome-alarms";
const name = "test";
const alarm = await Alarm.get(name);
console.log(alarm);
// Output: Object{ name: "test", periodInMinutes: 1, scheduledTime: 1706435598914.826 }
Gets an array of all the alarms.
import { Alarm } from "chrome-alarms";
const alarms = await Alarm.getAll();
console.log(alarms);
// Output: Array[{ name: "test", periodInMinutes: 1, scheduledTime: 1706435598914.826 }]
Fired when an alarm has elapsed. Useful for event pages.
import { Alarm } from "chrome-alarms";
Alarm.onAlarm((alarm) => {
console.log(alarm);
});
// Output: Object{ name: "test", periodInMinutes: 1, scheduledTime: 1706435598914.826 }
This project is licensed under the MIT License - see the LICENSE file for details.