W3cubDocs

/Web APIs

ServiceWorkerContainer: controllerchange event

The controllerchange event of the ServiceWorkerContainer interface fires when the document's associated ServiceWorkerRegistration acquires a new active worker.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js

addEventListener("controllerchange", (event) => {});

oncontrollerchange = (event) => {};

Event type

A generic Event.

Example

js

navigator.serviceWorker.addEventListener("controllerchange", () => {
  console.log("The controller of current browsing context has changed.");
});

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
controllerchange_event 40 17 44 No 27 11.1 40 40 44 27 11.3 4.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/controllerchange_event