fcm & service-workers

257 views
Skip to first unread message

id...@soluto.com

unread,
May 7, 2017, 11:20:30 AM5/7/17
to Firebase Google Group
Hi,

I'm trying to use fcm to implement push notifications in a react.js web app.

when i followed the fcm docs and declared firebase.messaging.onMessage handler in the web app code, and setBackgroundMessageHandler in the service worker
push notifications did get to the right handler in different states of the app (is tab focused or not) but then service worker postMessage api doesn't work for me.

so i defined my own service worker and registered it with firebase.messaging.useServiceWorker and now postMessage works fine, but now all the push notifications gets
intercepted by the service worker and messaging.onMessage isn't called even when the app is in focus.

did anyone encounter that, or have any suggestion?

thanks!

Idan

Matt Gaunt

unread,
May 8, 2017, 1:17:56 PM5/8/17
to Firebase Google Group
Hi Idan,

Is there any chance you can provide an example of the use custom service worker with what you are trying to do?

There is a chance that the library is swallowing the post message's when using the firebase-messaging-sw.js file (although this behavior should change). The onMessage function works by the library in the service worker posting messages to the page.

With the custom service worker, I would have expected onMessage to work, but if that were correct, I would have expeceted your custom post messages to work.

I've raised an issue on the internal project to add tests to support both of these use cases.

Cheers,
Matt
Reply all
Reply to author
Forward
0 new messages