mazey
    Preparing search index...

    Function watchServiceWorkerUpdates

    • Watch a service-worker registration for an update ready to activate.

      Existing waiting workers and newly installed workers are reported only when the page already has a controller, which distinguishes updates from a first installation. Activation, UI, status copy, and reload policy remain under caller control.

      Usage:

      import { watchServiceWorkerUpdates } from "mazey";

      const watcher = watchServiceWorkerUpdates(
      registration,
      navigator.serviceWorker,
      {
      onUpdateAvailable() {
      console.log("Update available");
      },
      onControllerChange() {
      console.log("Controller changed");
      },
      }
      );

      watcher.activateWaiting();
      watcher.dispose();

      Parameters

      • registration: ServiceWorkerRegistration

        Service-worker registration to observe.

      • container: ServiceWorkerContainer

        Service-worker container that owns the page controller.

      • callbacks: ServiceWorkerUpdateCallbacks

        Update and optional controller-change callbacks.

      Returns ServiceWorkerUpdateWatcher

      Controls for requesting activation and disposing all listeners.

      If required registration, container, or callback methods are missing.

      This helper does not register a service worker, mutate the DOM, reload the page, or decide when an update should activate. activateWaiting returns false when no update is waiting or postMessage fails.