As per the guidelines, in order for firebase messaging to function, the file file "firebase-messaging-sw.js" should be included at root level.
As you can see from this screenshot, I have included the same
The firebase app get's initialized in my app.component.ts and all of it's services work fine. However, the minute I try to fetch a messaging token .. i get the following error:
user.service.ts:26 ERROR requesting token FirebaseError {code: "messaging/failed-serviceworker-registration", message: "Messaging: We are unable to register the default s…t. (messaging/failed-serviceworker-registration).", browserErrorMessage: "Failed to register a ServiceWorker: A bad HTTP res…code (404) was received when fetching the script.", __zone_symbol__currentTask: ZoneTask, stack: "FirebaseError: Messaging: We are unable to registe…ttp://localhost:4200/polyfills.bundle.js:2776:47)"}browserErrorMessage: "Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script."code: "messaging/failed-serviceworker-registration"message: "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)."__zone_symbol__currentTask: ZoneTaskstack: "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).↵ at http://localhost:4200/vendor.bundle.js:96127:44↵
The problem as I understand is that the firbase messaging system is unable to locate the file, firebase-messaging-sw.js
Include the service worker file under scripts in angular-cli.json ... does NOT work
See Screenshot
Generate a distribution of the app and then MANUALLY place the service worker file in the dist folder
THIS WORKS! BUT is not a feasible for two reasons
Does anyone know of a solid solution for this issue ?
How about: "firebase-messaging-sw.js" as it should already be relative to src
And also try adding it to assets
Documentation related to asset configuration can be found here: https://github.com/angular/angular-cli/wiki/stories-asset-configuration
Closing as above.
Thanks @intellix and @clydin .. issue resolved
I am also facing this issue
Notification permission granted.
A bad HTTP response code (404) was received when fetching the script.
/firebase-messaging-sw.js Failed to load resource: net::ERR_INVALID_RESPONSE
(index):242 An error occurred while retrieving token. V {code: "messaging/failed-serviceworker-registration", message: "Messaging: We are unable to register the default s…t. (messaging/failed-serviceworker-registration).", browserErrorMessage: "Failed to register a ServiceWorker: A bad HTTP res…code (404) was received when fetching the script.", stack: "FirebaseError: Messaging: We are unable to registe…sejs/3.6.3/firebase.js:529:225↵ at
(index):243 Uncaught (in promise) ReferenceError: showToken is not defined
at (index):243
at
(anonymous) @ (index):243
Promise rejected (async)
(anonymous) @ (index):241
Promise resolved (async)
(anonymous) @ (index):217
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
And also try adding it to assets