I trying to implement Firebase Push Notification into Vue Js and after doing watching this video https://www.youtube.com/watch?v=XdzXaW8IbBM I tried to implement it, but after writing below code in firebase-messaging-sw.js it is giving me error on service worker. Both I have provided below.
Code firebase-messaging-sw.js
importScripts('/__/firebase/3.8.0/firebase-app.js');
importScripts('/__/firebase/3.8.0/firebase-messaging.js');
importScripts('/__/firebase/init.js');
firebase.messaging();
Error
Failed to register/update a ServiceWorker for scope ‘http://localhost:3000/firebase-cloud-messaging-push-scope’: Bad Content-Type of ‘text/html’ received for script ‘http://localhost:3000/firebase-messaging-sw.js’. Must be ‘text/javascript’, ‘application/x-javascript’, or ‘application/javascript’.
2nd Error
FirebaseError: Messaging: We are unable to register the default service worker.
The operation is insecure. (messaging/failed-serviceworker-registration).
Note: My application is on Vue Js + Nuxt Js
When I am trying to get the token on console I am getting below output.
Promise { <state>: "pending" }