Skip to content

Instantly share code, notes, and snippets.

@Steph-crown
Last active Jan 28, 2022
Embed
What would you like to do?
A script to register a service worker
// 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