0Pricing
Browser Extensions Development (Chrome & Edge) · Lesson

Scheduling Tasks with the Alarms API

Run periodic and delayed background work reliably in a Manifest V3 service worker using chrome.alarms.

Scheduling Tasks with the Alarms API is a free Browser Extensions Development (Chrome & Edge) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Browser Extensions Development (Chrome & Edge) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Not setInterval

In Manifest V3 the service worker unloads when idle, so setTimeout and setInterval are unreliable for scheduled work. The alarms API survives this by waking the worker when it is time to run.

Declaring the Permission

Add the alarms permission to the manifest before using the API.

{
  "permissions": ["alarms"]
}

Creating a One-Time Alarm

Use alarms.create with delayInMinutes for a single delayed task.

chrome.alarms.create('cleanup', { delayInMinutes: 5 })

Creating a Repeating Alarm

Add periodInMinutes to make the alarm fire again and again on a schedule.

chrome.alarms.create('sync', { periodInMinutes: 30 })

Handling the Alarm

Listen for onAlarm at the top level of your service worker. The alarm object tells you which one fired.

chrome.alarms.onAlarm.addListener((alarm) => {
  if (alarm.name === 'sync') {
    doSync()
  }
})

Register Listeners at the Top Level

Because the worker restarts, register onAlarm synchronously when the script first runs, not inside an async callback, or the wake-up may be missed.

// top of background.js, runs on every wake
chrome.alarms.onAlarm.addListener(handleAlarm)

Minimum Period

For packed extensions the smallest repeating period is about one minute. Shorter intervals are clamped, so do not rely on second-level timing.

chrome.alarms.create('tick', { periodInMinutes: 1 })

Inspecting Alarms

Use alarms.get or alarms.getAll to check what is scheduled, useful for avoiding duplicates.

const a = await chrome.alarms.get('sync')
if (!a) chrome.alarms.create('sync', { periodInMinutes: 30 })

Clearing Alarms

Remove a single alarm with clear or all of them with clearAll when a feature is turned off.

chrome.alarms.clear('sync')
chrome.alarms.clearAll()

Recreating on Install

Set up your alarms in the onInstalled event so they exist from the moment the extension is installed or updated.

chrome.runtime.onInstalled.addListener(() => {
  chrome.alarms.create('sync', { periodInMinutes: 30 })
})

Keeping Work Short

The worker may unload soon after the alarm. Keep the task quick, persist state to storage, and avoid long-running loops that could be cut off.

Quick Check

Test your alarms knowledge.

Recap

You learned reliable scheduling:

  • Use alarms.create with delay or period
  • Handle onAlarm registered at the top level
  • Respect the ~1 minute minimum period
  • Inspect, clear, and recreate alarms
  • Keep alarm work short

The alarms API makes background scheduling dependable under Manifest V3.

Frequently asked questions

Is the “Scheduling Tasks with the Alarms API” lesson free?

Yes — the full text of “Scheduling Tasks with the Alarms API” is free to read here on the web, and the Browser Extensions Development (Chrome & Edge) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Browser Extensions Development (Chrome & Edge) course, upgrade to CoddyKit PRO.

What will I learn in “Scheduling Tasks with the Alarms API”?

Run periodic and delayed background work reliably in a Manifest V3 service worker using chrome.alarms. You practise Browser Extensions Development (Chrome & Edge) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Browser Extensions Development (Chrome & Edge)?

No prior experience is required. Browser Extensions Development (Chrome & Edge) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Scheduling Tasks with the Alarms API” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Browser Extensions Development (Chrome & Edge) lesson?

Yes. Every Browser Extensions Development (Chrome & Edge) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Tab Management and Control
  2. Programmatic Form Submission
  3. Automating User Interactions
  4. Scheduling Tasks with the Alarms API
← Back to Browser Extensions Development (Chrome & Edge)