Jorge Montalvão
Jorge Montalvão

Reputation: 125

firebase messaging.getToken() return null

I am following this tutorial Set Up a JavaScript Firebase Cloud Messaging Client App. When I ran the page for the first time, I clicked on "Block" rather than "Allow" when the page asked me to show notifications. After removing the site from the Chrome blocked list Turn notifications on or off, messaging.getToken() always returns null.

I tried messaging.deleteToken() but this requires a valid (not null) token anyway.

How to solve this?

Upvotes: 2

Views: 3909

Answers (3)

Asal Romi
Asal Romi

Reputation: 1

Don't forget to make a firebase-messaging-sw.js file in your root repo or public folder inside root repo. And then, open that file via your localhost server. Ex : localhost:5000/firebase-messaging-sw.js.

If you still get an error page, you need to create manifest.json file. In this file, put your gcm_sender_id or messagingSenderID.

{
     "gcm_sender_id" : "587997283287" 
}

In my case, I can resolve this problem.

Upvotes: 0

ztvmark
ztvmark

Reputation: 1434

You must start a server in the folder of your project

php -S 127.0.0.1:8080

and access like this http://127.0.0.1:8080/

It will NEVER work if you sign in from another folder like this http://127.0.0.1/miproyecto/ http://localhost/myproject/

remember to create the file firebase-messaging-sw.js in the root https://firebase.google.com/docs/cloud-messaging/js/receive?hl=en-419


Debes iniciar un servidor en la carpeta de tu proyecto

php -S 127.0.0.1:8080

y acceder así http://127.0.0.1:8080/

NUNCA funcionara si accedes desde otra carpeta así http://127.0.0.1/miproyecto/ http://localhost/miproyecto/

recuerda crear el archivo firebase-messaging-sw.js en la raiz https://firebase.google.com/docs/cloud-messaging/js/receive?hl=es-419

Upvotes: 1

Jorge Montalvão
Jorge Montalvão

Reputation: 125

  1. Click "View site information" icon
  2. Set Notification to "Allow" Allow Notification
  3. Click on Cookies
  4. Select the host name (localhost in my case) remove cookies
  5. Click on Remove
  6. Click on Done

Upvotes: 0

Related Questions