firebase / firebase/codelab-friendlychat-web

Step #11 Error: "Unable to get messaging token. FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope..."

Open
#575 0 comments 0 reactions 0 assignees View on GitHub
codelab
Dominant language
JavaScript
Stars
1.9k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

### [REQUIRED] Codelab info

https://codelabs.developers.google.com/codelabs/firebase-web/#10

I encountered this problem on **"Step 11. Show notifications"**

### [REQUIRED] Project setup

As instructed, I've created `firebase-messaging-sw.js` in `web-start\public`. Ie. Loading this works for me:
`http://localhost:5000/firebase-messaging-sw.js`

I am working on localhost in `Chrome Version 87.0.4280.88 (Official Build) (64-bit)`.

### [REQUIRED] Describe the problem

On Step 11, I am currently on the step: **"Get your device token."** But after I refresh my browser (Chrome) and allow notifications, I am getting this error in the console:

![image](https://user-images.githubusercontent.com/45280066/104352159-50c7bf80-54d4-11eb-8ae2-e50e33bb5e22.png)

Per the codelab tutorial, after clicking "Allow" (notifications in the browser), I was expecting in my console:
`4. Open the JavaScript console of your browser. You should see the following message: Got FCM device token: cWL6w:APA91bHP...4jDPL_A-wPP06GJp1OuekTaTZI5K2Tu`

## What I've tried:

I saw there was a previous closed issue: https://github.com/firebase/codelab-friendlychat-web/issues/208

I've tried copying my firebaseConfig var and manually initializing it again but it didn't work for me. Ie. This _**didn't**_ work for me:

![image](https://user-images.githubusercontent.com/45280066/104352669-f54a0180-54d4-11eb-9095-7e3ab073f295.png)

PS. Obviously, I went to my Firebase project console and copied over my actual project parameters. Ie. The javascript object given under:

![image](https://user-images.githubusercontent.com/45280066/104353742-40184900-54d6-11eb-81a1-bbcc98324da3.png)

The only other change was in the codelab, in `firebase-messaging-sw.js` the firebase versions were hardcoded to `6.0.4` but I went ahead and updated those to `8.2.2`.

### [Optional] Suggested fix
Unsure. Please help. Thank you! Everything else in the codelab was terrific so far. I know I'm a decade late to Firebase but this is amazing! Thank you for putting it together! 🙏🙏🙏

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.