Reputation: 7109
I have done the Firebase Messaging tutorial and all required steps. I get the request for permissions and a Token from the messaging service.
But if I want to try to send a message to my browser with CURL (or via javascript fetch method) the "onMessage
" and the "firebase-messaging-sw
" are not getting called.
The Curl response seems is OK: {"multicast_id":xxx,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"xxx"}]}
So I get success:1 but it doesn't work.
Can anyone help why this does not work and where I can check for the problem?
I am working on a local machine Windows 10 with the Chrome Browser and "firebase serve
" command.
The local website url is http://localhost:5000!
The curl I am using in the command window is:
curl -X POST -H "Authorization: key=server-key" -H "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{ \"notification\": { \"title\": \"Test\", \"body\": \"TestBody\", \"icon\": \"firebase-logo.png\", \"click_action\": \"http://localhost:8081\" }, \"to\": \"tokenId\"}"
Update:
I have alos tried the quickstart sample and it does not work. I get the same response success:1 back but I don't see any notification in my browser.
https://github.com/firebase/quickstart-js/tree/master/messaging
Upvotes: 1
Views: 3338
Reputation: 7109
Found the problem and the solution.
Problem was:
The GCM connection status was "not connected" inside Chrome
How to find the status and solve this:
Open Chrome and enter this URL "chrome://gcm-internals".
Here you will see all status and messages.
Important is the "Connection state".
I had "WAITING FOR BACKOFF"!
This is the problem because you should see here "CONNECTED".
How to solve this:
First try deleting the GCM Store folder on your PC.
You can find the GCM Store folder in the Chrome profile for that user. Below would be for the default otherwise it will be Profile 1, Profile 2 and so on.
On Windows 10 / 8 / 7 / Vista:
C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default
After deleting this folder restart Chrome and check again in "chrome://gcm-internals" if you see "CONNECTED".
If not try to sign out from Chrome and log in again.
Now it should work and show connected.
Upvotes: 5