angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Registering serviceWorker firebase-messaging-sw.js

Open neaptolem opened this issue 7 years ago • 3 comments

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?

neaptolem avatar Feb 26 '19 15:02 neaptolem

useServiceWorker should have you covered, see this answer on StackOverflow.

jamesdaniels avatar Mar 04 '19 20:03 jamesdaniels

it is deprecated so anyone can suggest any new solution to it?

mwaleed0517 avatar Jul 19 '23 17:07 mwaleed0517

(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.

DrLex0 avatar Apr 07 '24 20:04 DrLex0