in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/firebase-messaging-sw.js') .then((registration) => { messaging.useServiceWorker(registration); }) .then(() => { return messaging.requestPermission(); }) .then(() => { return messaging.getToken(); }) .then((token) => { database.ref('notification/' + token).set(true); }) .catch((err) => { console.log('ServiceWorker registration failed: ', err); }); }); };