Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Document device sleep and persistence behaviour of alarms API #7776

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions site/en/docs/extensions/reference/alarms/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ To use the `chrome.alarms` API, declare the `"alarms"` permission in the [manife
}
```

## Concepts and usage

### Device sleep

The behavior of alarms when a device goes to sleep is currently undefined. An alarm will never fire
early but may fire significantly later than expected if a device went to sleep after an alarm was
scheduled.

### Persistence

Alarms generally persist until an extension is updated. However, this is not guaranteed, and alarms
may be cleared when the browser is restarted. Consequently, consider setting a value in storage
when an alarm is created, and then ensure it exists each time your service worker starts up. For example:

```js
const STORAGE_KEY = "user-preference-alarm-enabled";

async function checkAlarmState() {
const { alarmEnabled } = await chrome.storage.get(STORAGE_KEY);

if (alarmEnabled) {
const alarm = await chrome.alarms.get("my-alarm");

if (!alarm) {
await chrome.alarms.create({ periodInMinutes: 1 });
}
}
}

checkAlarmState();
```


## Examples

The following examples show how to use and respond to an alarm. To try this API,
Expand Down
Loading