Definition
install event (service worker)
The install event fires on the ServiceWorkerGlobalScope the first time a browser registers a new or updated service worker script. Handlers typically call event.waitUntil(caches.open(...).then(cache => cache.addAll([...]))) to pre-cache the app shell before the worker is allowed to move to the "installed" state.
A minimal handler looks like: self.addEventListener("install", (event) => { event.waitUntil(caches.open("shell-v1").then((cache) => cache.addAll(["/", "/app.css", "/app.js"]))); });. If any addAll request fails, the whole install step fails and the new worker is discarded.
Install runs for every updated script, not just the very first registration — the browser detects an update by byte-comparing the new script against the previously stored one, and re-runs install whenever they differ.
A newly installed worker does not take over existing open pages immediately; it enters the "waiting" state until all clients controlled by the old worker are closed, unless the code calls self.skipWaiting().
See the MDN Service Worker API lifecycle documentation for the full event sequence: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers.