-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to register the default service worker due to redirect or 404 #2582
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
The code change seems reasonable, but I'm double-checking that this change wouldn't break anyone else who is depending on it working the other way (absolute paths). In the meantime, I don't want you to be blocked, so are you able to work around this for now by creating and providing your own service worker to |
Can confirm, this is blocking. |
I'm planning to get someone to look at this soon, but does the workaround described in the above comment work for you, for now? |
We created a temporary script as a work around and we run it during build:
|
@elliotsabitovsulzer where you adding this code snippet? which file? |
@candidosales I assume you tried Matt's solution
(deprecated, now you would feed your sw-reg (located anywhere you want) through getToken) so something like
what's the error message you are seeing with this approach? |
is there any solution please? |
Have you tried the above solutions? If issue still persist, please consider filing a new ticket that include more details and minimal code to reproduce your issue |
if you using Webpack in your project go to the configuration and add the next line
|
To add detail to my previous comment, essentially we have a fix.firebase.js script that contains the code above in my previous comment. Then in package.json we have:
and so we are then able to call |
is there any better solution than manually fixing the path or just deploying the file on the root? |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
Steps to reproduce:
The issue is that firebase is unable to register service worker when the application is hosted within a sub directory. We have domain.com/path/index.html and firebase gives the following error:
Unable to get permission to notify. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('https://domain.com/firebase-cloud-messaging-push-scope') with script ('https://domain.com/firebase-messaging-sw.js'): The script resource is behind a redirect, which is disallowed. (messaging/failed-serviceworker-registration).
It is getting redirect, because we have it set up this way, but I looked around online and saw that users have also experienced the same issues with 404s.
Related tickets:
firebase/quickstart-js#109
Problem:
The compiled code has the following:
navigator.serviceWorker.register("/firebase-messaging-sw.js",{scope:"/firebase-cloud-messaging-push-scope"})
Solution:
Would be great if the compiled code had relative path:
navigator.serviceWorker.register("firebase-messaging-sw.js",{scope:"firebase-cloud-messaging-push-scope"})
Reason:
I looked around the firebase dependency code and saw the following in firebase/messaging/dist/src/models/default-sw.d.ts:
export declare const DEFAULT_SW_PATH = "/firebase-messaging-sw.js";
export declare const DEFAULT_SW_SCOPE = "/firebase-cloud-messaging-push-scope";
I think adjusting this and removing the leading slash "/" would resolve the issue.
Thank you very much in advance for your help!
The text was updated successfully, but these errors were encountered: