Skip to content

Unable to register the default service worker due to redirect or 404 #2582

Closed
@elliotsabitov

Description

@elliotsabitov

[REQUIRED] Describe your environment

  • Operating System version: MacOS 10.14.4
  • Browser version: Chrome 79.0.3945.130
  • Firebase SDK version: 6.6.2
  • Firebase Product: Cloud Messaging

[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!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions