Service Worker Events Reference

All service worker lifecycle and functional event types with timing and scope.

Searchable reference for Service Worker events — install, activate, fetch, message, push, sync, periodicsync and notification events — with their interfaces, timing and waitUntil semantics.

What is the difference between lifecycle and functional events?

Lifecycle events — install and activate — fire once per worker version as it is set up and takes control. Functional events such as fetch, push and sync fire repeatedly while the worker is active to do its ongoing work.

Events that drive a service worker

A service worker is event-driven: it has no persistent state and wakes only to handle events, then may be terminated. Knowing which events exist, when they fire, and how to extend their lifetime is the core of building reliable offline-capable and push-enabled web apps. This searchable reference lists the lifecycle and functional events with their interfaces and timing.

How it works

Service worker events fall into two groups. Lifecycle events run once per worker version:

self.addEventListener("install", (event) => {
  event.waitUntil(caches.open("v1").then((c) => c.addAll(ASSETS)));
});

self.addEventListener("activate", (event) => {
  event.waitUntil(clients.claim());
});

Functional events fire repeatedly. The fetch event uses event.respondWith() to return a response synchronously, while push, sync, message and the notification events use event.waitUntil() to keep the worker alive while a promise resolves. Without one of these calls the browser may kill the worker before your asynchronous work finishes.

Tips and notes

  • Precache in install; purge old caches in activate. Call clients.claim() to control already-open pages.
  • fetch is the only event that uses respondWith() — everything else uses waitUntil().
  • A push handler must show a notification or the browser may flag your origin for silent pushes.
  • sync retries on a backoff if your promise rejects; periodicsync is throttled by engagement and battery and has limited support.