quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

setBackgroundMessageHandler not working

Open sidyyy911 opened this issue 9 years ago • 10 comments

I have used the default code as in the example app in quickstart-js on Github for my serviceWorker. But still see the notification coded in firebase-messaging.js when the app is in the background. I am serving the application from local server and am able to recieve messages sent through the fcm server, just can't override the default handler for notifications.

sidyyy911 avatar May 04 '17 14:05 sidyyy911

What is the request you are to the FCM API?

gauntface avatar May 04 '17 15:05 gauntface

POST /fcm/send HTTP/1.1 Host: fcm.googleapis.com Content-Type: application/json Authorization: key=MyServerKey - intentionally removed Cache-Control: no-cache Postman-Token: 7422a5f0-eb5a-ada3-8f3e-709eec2682c4

{"to": "eslQUUSpxTM:APA91bG7zgoU63XZTF5vbaxNkFTu9DG3WB9JJHFKxLuKN1UBlZ0RkUB6lD-wzQtMQVfw2lW0HcWWsok7fuU2717CS7j9klzf_OU3RQvoNauBDeMkdaYy4MF2wRkFdpDMz2ybmOyQWwxX", "notification": {"title": "Portugal vs. Denmark", "body":"5 to 1" } }

Used postman(for quick hits) Used java as well(same result)

sidyyy911 avatar May 04 '17 15:05 sidyyy911

Don't use the notification parameter if you want to handle the notification yourself.

Just use "data.

{"to": "eslQUUSpxTM:APA91bG7zgoU63XZTF5vbaxNkFTu9DG3WB9JJHFKxLuKN1UBlZ0RkUB6lD-wzQtMQVfw2lW0HcWWsok7fuU2717CS7j9klzf_OU3RQvoNauBDeMkdaYy4MF2wRkFdpDMz2ybmOyQWwxX",
"data":
{"title": "Portugal vs. Denmark",
"body":"5 to 1"
}
}

gauntface avatar May 04 '17 21:05 gauntface

That solved my problem. Thanks a lot.

sidyyy911 avatar May 05 '17 07:05 sidyyy911

So there's 2 background message handlers, one used by default when the user configures a notification parameter and optional custom handler (provided by an application) which is only ever invoked when the user provides a data parameter?

This behavior is really surprising to learn and doesn't seem to be very well documented, if at all, by Firebase.

Matt-Jensen avatar Jan 17 '18 22:01 Matt-Jensen

@gauntface Is there a way to disable the automatic notification handling/displaying from the client-side? I'm asking because removing the "notification" property impacts other apps that rely on the payload having the property.

kinkoazc avatar Jul 12 '18 12:07 kinkoazc

Please notify that setBackgroundMessageHandler under serviceworker on WebApp was totally not working. I've working on this successfuly but it totally not working by today, kindly fix it .TQ

koklimabc avatar May 21 '19 05:05 koklimabc

@gauntface setBackgroundMessageHandler working on only first time again send push notification is not responding, please help to fix.

/thanks

kumaravelcrayond avatar Oct 21 '19 11:10 kumaravelcrayond

Have you use below line because Visual studio din't manage to recognise the path easily under javascript.

messaging.useServiceWorker(register);

Have you set as below under your Page (not the master Template)

$(document).ready(function(){ messaging.onMessage(function (payload) { console.log("Received Messages in forground", payload); }); });

Don't forget to clear all browser settings. and also update via cache (during register your service worker), setting to cahes.remove() under your sw.js.

On Mon, Oct 21, 2019 at 7:02 PM kumaravelcrayond [email protected] wrote:

@gauntface https://github.com/gauntface setBackgroundMessageHandler working on only first time again send push notification is not responding, please help to fix.

/thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-js/issues/134?email_source=notifications&email_token=AATVJVSC4H76O4GHAAVRLV3QPWD4XA5CNFSM4DKDFM5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBZ5ZPQ#issuecomment-544464062, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATVJVXU3QOAY5AAZFWCZ7DQPWD4XANCNFSM4DKDFM5A .

koklimabc avatar Oct 28 '19 07:10 koklimabc

OnMessage is responsible to communicate with messaging.setBackgroundMessageHandler.

On Mon, Oct 28, 2019 at 3:31 PM Tan Kok Lim [email protected] wrote:

Have you use below line because Visual studio din't manage to recognise the path easily under javascript.

messaging.useServiceWorker(register);

Have you set as below under your Page (not the master Template)

$(document).ready(function(){ messaging.onMessage(function (payload) { console.log("Received Messages in forground", payload); }); });

Don't forget to clear all browser settings. and also update via cache (during register your service worker), setting to cahes.remove() under your sw.js.

On Mon, Oct 21, 2019 at 7:02 PM kumaravelcrayond [email protected] wrote:

@gauntface https://github.com/gauntface setBackgroundMessageHandler working on only first time again send push notification is not responding, please help to fix.

/thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-js/issues/134?email_source=notifications&email_token=AATVJVSC4H76O4GHAAVRLV3QPWD4XA5CNFSM4DKDFM5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBZ5ZPQ#issuecomment-544464062, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATVJVXU3QOAY5AAZFWCZ7DQPWD4XANCNFSM4DKDFM5A .

koklimabc avatar Oct 28 '19 07:10 koklimabc