I have a very strange problem and didn‘t find anything about this issue online. I‘m using Firebase Hosting, Cloud Function & Cloud Messaging for a website I set up. On this website, subscribed users regularly are notified with push notifications.
On Apple devices/iOS the push notifications are working perfectly, but on Android with Chrome I observe a very strange and irregular problem. When the website is in the background, the push notifications sometimes don‘t come through at all, sometimes they are delayed 5/10/20/… minutes and sometimes they appear right in time. I tested this on four Android devices with Chrome (0-6 years old, encountered the same problem everywhere)
My suspicion was that the chrome Webbrowser does not reliably know when it is in focus/foreground and when not, so I did some troubleshooting by implementing the FCM onMessage-function in my site’s js-file (not in the service worker file), by saving the time of onMessage-function call to a variable. When logging this variable I observe that the function is in deed most of the times called right after the Push notification was sent, even when the browser was in background when the notification was sent.(which should not be the case as onMessage should be called only when it is in focus)
I tried to trigger the push notification from the onMessage-function by calling the service worker from there but still no success!
My service worker does look exactly like described in FCM documentation, and I did not implement onBackgroundMessage as it is optional because I‘m not using data notifications (https://firebase.google.com/docs/cloud-messaging/js/receive?hl=de#web-namespaced-api_3)
Does anyone has any idea what could be the problem?