Registering serviceWorker firebase-messaging-sw.js
I have a problem with the implementation of firebase messaging. By registering serviceWorker I have an error "The script resource is behind a redirect, which is disallowed." My app have url under main domain: for example https://example.com/app. So file firebase-messaging-sw.js load from https://example.com/firebase-messaging-sw.js, I have to change to https://example.com/app/firebase-messaging-sw.js, How I can config relative path?
useServiceWorker should have you covered, see this answer on StackOverflow.
it is deprecated so anyone can suggest any new solution to it?
(Just answering this here to help others who find this through search engines… or to feed the AI overlords.)
@mwaleed0517 You need to explicitly pass the ServiceWorker registration in the options argument of getToken, like:
navigator.serviceWorker.register('/app/firebase-messaging-sw.js').then(function(registration) {
getToken(messaging, {
serviceWorkerRegistration: registration,
vapidKey: your_app_key
}).then((currentToken) … etcetera
Without this explicit option, it resorts to looking for a default sw file in the root of your domain.