FCM "Messaging: We are unable to register the default service worker. The operation is insecure. (messaging/failed-serviceworker-registration)."
Help,
would like to ask, why i am getting this error, but in my local it's working fine. I check my firebase-messaging-sw.js and it's there. what would be the cause?
error message: code: "messaging/failed-serviceworker-registration" Messaging: We are unable to register the default service worker. The operation is insecure. (messaging/failed-serviceworker-registration).
thanks
this file is missing firebase-messaging-sw.js. please add firebase-messaging-sw.js file in root folder.
i think in server /var/www/... something it worked for me
it's in my root, when i type http://

can you check in dev-tools--->application-->service-workers is any worker is active.
like above image
// Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here, other Firebase libraries // are not available in the service worker. importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js'); // importScripts('/__/firebase/init.js');
// Initialize the Firebase app in the service worker by passing in the // messagingSenderId. firebase.initializeApp({ 'messagingSenderId': 'SENDER_ID' });
// Retrieve an instance of Firebase Messaging so that it can handle background // messages. firebase.messaging();
firebae-messing-sw.js file
You can only use service workers if you're serving your code via HTTPS, except when you're serving from localhost. See here for more details.
"You’ll also need to serve your code via HTTPS — Service workers are restricted to running across HTTPS for security reasons." and "In order to facilitate local development, localhost is considered a secure origin by browsers as well."
It does not work with Firefox or Safari, just Chrome supports localhost:"ANYPORT". If you try to substitute with ngrok it does not work either, and you get the error stated in the issue.
Please check:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1429714
If cookies are "Kept until I close Firefox," it will not work. You need to check if the option is switched on.
What I don't understand is why do I need this option (and save the cookie); if I get a new token whenever I start an FCM session?
@dkdndes please open a new issue if you're having this problem!
Unable to get permission to notify. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).
Any one got solution for this ???
Where did you put your firebase-messaging-sw.js?
Unable to get permission to notify. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).Any one got solution for this ???
You need to make sure the firebase-messaging-sw.js has existed in your public folder
Unable to get permission to notify. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).Any one got solution for this ???
yea have you found the solution??
you need to pass whole project config when doing
firebase.initializeApp({
apiKey: 'xxxx',
authDomain: 'xxxx.firebaseapp.com',
databaseURL: 'https://xxxx.firebaseio.com',
projectId: 'xxxx',
storageBucket: 'xxxx.appspot.com',
messagingSenderId: 'xxxx',
appId: 'xxxx'
});
hi in localhost i got both foreground and background notification but in production (https) i only got the background notification using FIREBASE 7.6.0 service worker also same
Works like a charm. Thanks @parth181195. 👍
For any one else stuck on this, my error was similar to this but slightly different. It stemmed from a problem with the firebase-messaging-sw.js file not being publicly accessible. This comment explains it clearly.
I fixed mine by moving the firebase-messaging-sw.js file up one folder so it was accessible via http://localhost:<PORT NUMBER>/firebase-messaging-sw.js instead of http://localhost:<PORT NUMBER>/messaging/firebase-messaging-sw.js
@parth181195 @mmermerkaya
I ve placed my service worker file in root folder and it s accessible in http://localhost:<PORT NUMBER>/firebase-messaging-sw.js also I ve passed the whole project config .
Unlike Chrome and Edge , it worked only on Firefox browser
I ve tried this options without a result :
- Update Google Chrome to latest
- Clear ssl cache
- Clear all browser cache and history
- Disabling QUIC Protocol wich provides TLS/SSL equivalent connection
- Reinstall Google Chrome Any Solution ??
If you're working with React and you've put your fireabse-messaging-sw.js in the public folder you cannot use proces.env to fetch the values for firebaseConfig (apiKey, authDomain, etc.), provided that you have stored them as an environment variable.
If you are using typescript with React, just put your firebase-messaging-sw.js in your public folder. And remember to turn "allowJs": true, in your tsconfig.json under compilerOptions.
Your firebase-messaging-sw.js should look like this:
`// Scripts for firebase and firebase messaging importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js');
// Initialize the Firebase app in the service worker by passing the generated config var firebaseConfig = { apiKey: "YOUR_API_KEY", authDomain: "YOUR_AUTH_DOMAIN", projectId: "YOUR_PROJECT_ID", storageBucket: "YOUR_STORAGE_BUCKET", messagingSenderId: "YOUR_MESSAGING_SENDER_ID", appId: "YOUR_APP_ID" };
firebase.initializeApp(firebaseConfig);
// Retrieve firebase messaging const messaging = firebase.messaging();
messaging.onBackgroundMessage(function(payload) { console.log('Received background message ', payload);
const notificationTitle = payload.notification.title; const notificationOptions = { body: payload.notification.body, };
self.registration.showNotification(notificationTitle, notificationOptions); });`
The script has an unsupported MIME type ('text/html').
==> Service worker registration failed, error: DOMException: Failed to register a ServiceWorker for scope ('http://localhost:3000/') with script ('http://localhost:3000/firebase-messaging-sw.js'): The script has an unsupported MIME type ('text/html').
Getting this error