Example 1 — Feature Detection
MDN’s beginner check before any register call.
if ("serviceWorker" in navigator) {
console.log("Supported!");
} else {
console.log("Service workers are not supported.");
} How It Works
- Ask the browser. The
inoperator checks whether the property exists. - Gate your code. Only call
register()inside the supported branch. - Private mode. Some browsers omit the API — this check catches that.
- No side effects. Detection does not install a worker.

