Martin Zvarík
Martin Zvarík

Reputation: 2479

Firebase Cloud Messaging - Messages don't show up, only if I close browser

The visitor subscribes and I retrieve FCM token.

$data = [
'to' => "xxxxxx-XbPk:APA91bHEJ1Kp8KLhOxVzRmNoAh6459DNCTeGB00jYOp_Ppd9AzTQGM5cU5kE4Pf3ivOhVZYkw-ao5h3R8H2y1yyNu0NdyIf8JiGvZXcxS-KDuaAVZ2ih1xzHGOcmGHRkfZeRdWXk4hM9",
"notification" => [
    "title"=> "Notification Title",
    "body"=> "Notification Body xx"
   ]
]

I push this message using POST to https://fcm.googleapis.com/fcm/send

It always says success=1,

but the message is in fact delivered only if the website is closed!

When I close the tab, and push message again, it is delivered.

Also if I open the site or I go to anywhere on that domain like http://example.org/whatever/, they are not delivered, but "success=1" is still returned.

Tested Chrome and Firefox and they work the same. I have to be on different website for the message to show up or the browser must be minimized.

What I doing wrong? I need messages to show up always.

Upvotes: 0

Views: 3148

Answers (2)

Martin Zvarík
Martin Zvarík

Reputation: 2479

Just tryed this Google's example: https://github.com/firebase/quickstart-js/tree/master/messaging

Basically in case the web is active (you can see running workers in Chrome console) server Push method doesn't show the notification, but runs a client function, which you can define like this:

messaging.onMessage(function(payload) {
    // ... show notification
});

Where you have to do it yourself.

Also good source that actually uses worker to do everything: https://gauntface.github.io/simple-push-demo/

Upvotes: 1

Martin Zvarík
Martin Zvarík

Reputation: 2479

This was the issue! messaging.setBackgroundMessageHandler was not fired.

https://github.com/firebase/quickstart-js/issues/71

Upvotes: 0

Related Questions