Skip to content

Instantly share code, notes, and snippets.

@m3h0w
Last active December 1, 2020 11:18
Show Gist options
  • Save m3h0w/7a2f24c61d283379bca5aab313cf9391 to your computer and use it in GitHub Desktop.
Save m3h0w/7a2f24c61d283379bca5aab313cf9391 to your computer and use it in GitHub Desktop.
Register custom service worker when cra-append-sw operated in dev mode
if ('serviceWorker' in navigator && process.env.NODE_ENV !== 'production') {
console.log('Trying to register custom sw');
navigator.serviceWorker
.register('./firebase-messaging-sw.js')
.then(function (registration) {
console.log('Registration successful, scope is:', registration.scope);
})
.catch(function (err) {
console.log('Service worker registration failed, error:', err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment