I am interested in developing a small web application to explore the capabilities of Firebase Cloud Messaging for web apps. My intention is to utilize Firebase Hosting as the hosting platform for my app.
ISSUE:
Upon allowing the notification pop-up on my browser, I encountered the following error message:
FirebaseError: Messaging: The default service worker registration failed. An attempt to register a ServiceWorker for scope ('https://XXXX.firebaseapp.com/firebase-cloud-messaging-push-scope') with script ('https://XXXX.firebaseapp.com/firebase-messaging-sw.js') resulted in a bad HTTP response code (404). (messaging/failed-serviceworker-registration).
Heading
SOLUTION:
var firebaseConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function() {
return messaging.getToken();
}).then(function(token) {
console.log(token)
}).catch(function(err) {
console.log(err);
})