if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("/sw.js", { scope: "/" })
.then((registration) => {
// registration worked
console.log("Registration succeeded.");
button.onclick = () => {
registration.update();
};
})
.catch((error) => {
// registration failed
console.error(`Registration failed with ${error}`);
});
}ServiceWorkerRegistration: update() method / notebook
ServiceWorkerRegistration: update() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.