Last active
January 28, 2022 12:19
-
-
Save steph-crown/bff38c0e1b14a3a5060aaabc77456081 to your computer and use it in GitHub Desktop.
A script to register a service worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Checks if we can use serviceWorker. | |
if ("serviceWorker" in navigator) { | |
navigator.serviceWorker | |
.register("sw.js") | |
.then((registration) => { | |
// The registration wass successful | |
console.log("Service worker registered"); | |
console.log(registration); | |
}) | |
.catch((err) => { | |
// The registration failed | |
console.log("Sercvice worker registration failed"); | |
console.error(err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment