Definition
activate event (service worker)
The activate event fires after a service worker moves from "installed" to "activating", typically once the old worker's clients have all closed or skipWaiting() was called. Handlers commonly use it to clean up outdated Cache Storage entries left behind by earlier versions of the app shell.
A typical cleanup handler: self.addEventListener("activate", (event) => { event.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== "shell-v2").map((k) => caches.delete(k))))); });, which removes any cache whose name does not match the current version tag.
Deleting old caches in install instead of activate is unsafe, because the previous worker may still be serving pages from those caches until it is fully replaced.
Calling event.waitUntil(clients.claim()) inside activate lets the new worker start controlling already-open pages immediately, rather than waiting for the next navigation — this is the standard pairing with skipWaiting() for apps that want instant updates.
Errors thrown synchronously in the activate handler, or a rejected waitUntil promise, leave the worker in a failed state and it will be discarded on the next registration attempt.