The alarms API allows an extension to schedule code to run periodically or at a specific time in the future.
What it does
- Enables extensions to set, clear, and listen for timed events, similar to
window.setTimeoutandwindow.setInterval. - Alarms are persistent. They will fire even if the service worker is inactive — the browser wakes the service worker to handle the event.
- Alarms persist across browser restarts and extension updates. They are cleared on uninstall. As a defensive measure, extensions still commonly re-create critical alarms in
chrome.runtime.onInstalledandchrome.runtime.onStartup. - For published extensions, the minimum
periodInMinutesis0.5(30 seconds). Unpacked / dev-loaded extensions can go lower.
When to use it
Use the alarms API for tasks that need to run on a schedule, even when the extension is not actively being used.
Examples:
- An extension that periodically fetches data from a server (e.g., checking for new emails).
- A reminder or to-do list extension that needs to show a notification at a specific time.
- A "take a break" timer that reminds the user to step away from the screen every hour.
Manifest Declaration
{
"name": "My Alarms Extension",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"alarms"
],
"background": {
"service_worker": "background.js"
}
}Security & Privacy
Why is it not risky?
This permission simply lets an extension set a timer to perform a task at a specific time or on a regular schedule (e.g., check for new emails every 15 minutes).
The browser has built-in limits to prevent extensions from using this to slow down your computer. It doesn't give the extension access to your personal data.
API Usage Example
This example sets an alarm that fires every minute to fetch some data.
// background.js
// Create the alarm when the extension is installed
chrome.runtime.onInstalled.addListener(() => {
console.log('Creating a 1-minute alarm.');
chrome.alarms.create('fetchData', {
delayInMinutes: 1, // Fire for the first time after 1 minute
periodInMinutes: 1 // Then fire every 1 minute after that
});
});
// Listen for the alarm and act on it
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === 'fetchData') {
console.log('Alarm fired! Fetching data...');
// In a real extension, you would fetch data here.
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log('Data fetched:', data));
}
});Extensions with the alarms permission
Here are some popular browser extensions that use the "alarms" permission. To explore more, try our Advanced search.