Definition
Service worker registration
Registration happens when a page calls navigator.serviceWorker.register("/sw.js", { scope: "/app/" }). The scope option (defaulting to the directory the script is served from) determines which pages the worker is allowed to control — a worker at /sw.js served with no scope option can normally only control /*, but serving it with the Service-Worker-Allowed HTTP header lets it claim a scope above its own script location.
register() returns a promise that resolves to a ServiceWorkerRegistration object once the browser has at least accepted the script for install; it does not wait for the install or activate steps to finish.
A page can only be controlled by one active service worker at a time; registering a second worker at an overlapping scope replaces the first one for new navigations once the update cycle completes.
Scope is matched by URL prefix, so a worker registered with scope "/app/" controls "/app/settings" but not "/blog/post-1", even if both are served from the same origin.
You can inspect live registrations from the browser with navigator.serviceWorker.getRegistrations(), which is often the first debugging step when a PWA seems to be running stale code.