-
Notifications
You must be signed in to change notification settings - Fork 923
iOS Web Push Device Unregisters Spontaneously #8010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looks like the same issue as #8013! |
This keeps happening to users. This is the extent of our code. Why would the device stop sending pushes?
|
We are also having the same issue, looks like it works about 3 times on iOS and then just stops until the app is then opened and the token refreshed again. messaging.onBackgroundMessage((payload) => {
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
icon: payload.notification.image ?? "/icon-256x256.png",
click_action: payload.data.link,
};
return self.registration.showNotification(
notificationTitle,
notificationOptions
);
}); |
Could this be related to this? https://dev.to/progressier/how-to-fix-ios-push-subscriptions-being-terminated-after-3-notifications-39a7 Not sure if the onBackgroundMessage message takes care of the waitUntil |
I suspect the issue is iOS thinks this is a invisible push notifications because firebase is doing it async, but until someone actually looks into, I don't know. We are debating moving off of FCM for this reason, it just stops working after some time. |
Alright that is indeed the issue, I just ran a bunch of test and I replace the onBackgroundMessage with this in my service worker:
This is working perfectly, so I just remove all trace of firebase in the service worker. All the notifications are coming in now in iOS. I think this need to be address in the firebase codebase. |
How do we get their attention! |
Yeah, seems like a big deal, since it is not working on iOS |
Wow this solved my exact problem. Thank you!! |
Not working for me. OK for Android but not in IOS. |
Hello. Possible to have a piece of code ? |
Update: After fixing some issues with my service worker and nixing my foreground notification handlers, it seems to work more reliably with the event.waitUntil() solution. Another Update: A notification failed to send after 44 restarts. I was able to reactivate by requesting another token (after an additional restart) but I don't know what causes it as I'm just calling FCM's getToken. I'm thinking of occasionally checking if the token changes against the one stored in local storage and replacing it when needed. More Findings: When FCM's getToken is called, it appears to update that client's token in Firebase's Topics. It's not reactivating the old token. The old token returns UNREGISTERED. The double notification might be that the token gets subscribed twice to a Topic (one is a new subscription, and the other one is mapped from the old one?). I also removed Firebase from the service worker. I then tested if notifications would break by restarting the iOS device over and over while also sending a notification between restarts. Eventually, a notification would fail. It is possible it triggered three silent notifications but I also noticed other PWAs on the same device would not be able to confirm the subscription status either. I don't believe this issue is specific to one PWA's implementation and it's just a bug with Safari. Or somehow another PWA's implementation is causing the others to fail on the same device. I also noticed that requesting a new messaging token seems to "reactivate" the old one. If you subscribe with this new token, and send a notification to the topic, the iOS device will get two separate notifications.
|
@rchan41 Hi! Sorry just to be clear did you get your PWA to send Push notifications to IOS ? Did it work? |
Yes, I didn't have issues sending push notifications to iOS. The issue I described with notifications after restarting the iOS device. However, these issues might be unrelated to the topic's issue. |
@DarthGigi This is working properly? What version of firebase are you using? I am still getting unregistering even when using simple code like:
|
@fred-boink this is the latest iteration of things on one of the projects that I'm working on. I wasn't the original developer so it's been quite a journey trying to troubleshoot. The current iteration of the firebase service worker is still leading to reports of notifications stopping after a while. Don't know what the secret sauce is. firebase-sw.js
Then there's also a component with the following:
|
@fred-boink I'm using Firebase version 10.12.2 which is the latest version at the time of writing. Safari unregistering is still an issue and I don't think we can easily fix it without firebase's help. |
@DarthGigi Yes, none of my changes have worked. They need to fix this, its. a major problem. Anyway we can get their attention? |
@fred-boink It is indeed a major problem, I thought this ticket would get their attention, I have no idea why it didn’t. I don’t know any other ways to get their attention other than mail them. |
Greetings. We have faced the same problem for our PWA on iOS. Code works perfect for Android, Windows, Mac and other systems, except iOS. Version of iOS is 17+ for all our devices. Unfortunately, it stopped to show notifications at all. Before we at least got some, but now we can't get even a single notification for iOS (thus we can see in logs that it was successfully send to FCM).
Can anyone please help? Or any advices how to get them? |
After some reproduction attempts, here's what I've found: Silent Push Device Restarts |
This is very frustrating for all of our iOS users... |
Oh my god same here, I hope this got fixed.... |
@dlarocque Any luck looking into this? Still not working properly on iOS Safari? |
@amoffat Have you logged an issue with Safari? I can up vote it and follow. |
Looks like the same issue |
I’m experiencing an issue with Firebase Cloud Messaging (FCM) push notifications on iOS Safari. Specifically, notifications stop working after the app receives three consecutive push messages while in the foreground. Notifications work as expected when the app is in the background.
My Assumption: From my understanding, iOS Safari might be unregistering the FCM token after three silent push notifications. It seems that notifications received while the app is in the foreground are treated as silent messages, which might cause the token to become invalidated per Apple’s guidelines. Goal: I need a way to display visible push notifications in the foreground using onMessage to ensure notifications are not treated as silent. This may prevent the token from being invalidated. |
@ChaeHoonK When you write "The messages are received successfully", are these messages regular Firebase messages, or Firebase notifications?
You need to show a notification by your own means when receiving a Firebase notification message and your app is in the foreground. Just handle When your app is in the foreground and you are receiving a Firebase regular message (with no notification payload), my understanding is that you can just process the message in |
@andynewman10 "The messages are received successfully" means that I can receive background push notifications more than 3 times (as many as I want) using Firebase messages (no notification payload). Here is the payload that I used to send data
The code below is how I handled onMessage. But I'm not sure if I'm handling it correctly to be permitted from Safari's silent push restriction.
Lastly, I wrote a simple service worker for background push message.
I still have the same issue. When receiving push messages while on foreground, fcm token is automatically unregistered by itself. |
What happens if you show a notification using eg. Notification.requestPermission().then(function(permission) {
if (permission === "granted") {
const notification = new Notification("Either a regular message or notification message was received", {
body: "You clicked this notification.",
});
}
}); If you always use this code for foreground ( (BTW, sorry about talking about flutter_local_notifications, I was reading a Flutter issue just a few minutes earlier) |
I've just tried it, but somehow I've tried different approach and it work pretty good. I would use this until either Firebase or Safari fix the issue.
|
Leaving this here because I've now spent far too long getting iOS Web Push to work reliably. It's still not perfect (I'm still hitting this: #8444) but it feels much more reliable When using Firebase's My solution was to update the Our use case is pretty simple, Send a notification -> Open the URL so this will likely be applicable to a few people here This lead me to believe that the flakiness of the push subscription wasn't being helped by Firebase's implementation. Here is my final
And then in my JS code, I just added:
Again, its not perfect, but what's not working seems to be an issue on Apple's end. This is much more reliable than using Firebase directly I hope this helps someone! |
I believe the problem is that Safari does not support silent/invisible push notifications, which FCM does support and incorrectly handles. As stated, after 3 invisible push notifications, Safari will revoke your app's notification permission; the user will have to go through setting up the permissions again. https://developer.apple.com/videos/play/wwdc2022/10098/?time=814
|
@DarthGigi I was not able to reproduce the Silent Push notification issue after several attempts when I last tried. Could you share a live website that I can use to reproduce the issue? If concerned about sharing it too publicly feel free to email dlarocque@google.com. I want to confirm at least one cause of this issue is Silent Push. |
@dlarocque May I ask what exactly you tried? I believe the issue lies in the
This only happens when the user has the webapp open and active (so not in the background). If still needed, I could try to make a minimal repro? |
What @DarthGigi mentioned is what I experienced too. I was handling I was only able to replicate when the app was in the foreground |
I am working on Safari support for a web app and things appear to be working, but my testing has been very limited (to almost non existent) so far and production code doesn't have Safari enabled. @DarthGigi @smlparry could it be that Safari just demands us to always display a notification through Could it be this reason? |
@andynewman10 Yes, as explained in my earlier comment, Safari demands you to show a native push notification when the service worker has been invoked. |
Anyone tried switching to another service to see if it resolves these issues with IOS? Considering moving to Pusher Beams (https://pusher.com/docs/beams/getting-started/web/sdk-integration/?ref=web). Theoretically if this is a webkit bug then Pusher Beams will have the same bugs as FCM (https://github.com/firebase/firebase-js-sdk/wiki/Known-Issues#fcm-in-ios-progressive-web-apps-pwas) but if it's an FCM bug then using Pusher Beams or another equivalent service should fix it? |
Vindicated. Apple tacitly admits a fault in their push notification processing. https://webkit.org/blog/16535/meet-declarative-web-push/
Emphasis mine. So a "networking condition" or "local device condition" can prevent or delay a showNotification, and Apple punishes your PWA for it by revoking the subscription. |
They go on to explain that Apple's ITP (Intelligent Tracking Prevention) will nuke all of your PWA's data, including push subscriptions:
So if someone wants push notifications from you, they go through the rigamarole of install the PWA and approving notifications, then if they don't visit your site in "a while", Apple wipes all website data, including the push notification subscription, making it completely useless. |
Awesome, thanks for sharing that @amoffat. Looks like we just need to implement this new Declarative Web Push standard and then web push will actually work on iOS :) Huge news if true. |
Okay so I think I got a little ahead of myself with the celebration. We need updates to this SDK and the firebase admin SDK to support Declarative Web Push. |
@amoffat Thank you for sharing this! Unfortunately for us, it's challenging to know whether issues like these are caused by 1) intentional privacy protecting features 2) a bug in WebKit 3) a bug in the Firebase JS SDK. @ehtodd, If you believe supporting Declarative Web Push solves issues in WebKit, please open a new feature request in this SDK and in the Admin SDK so that we can track it separately from this bug. |
It should be assumed that iOS is unreliable until declarative web push is implemented, given that they have listed 2 cases (ITP and device delays) where the subscription can be revoked outside of the developer's control. Even if Firebase SDK is flawless, developers will still have issues. Focus on declarative web push and I suspect many of the current iOS issues will vanish. |
Can anybody please confirm the present issue does not affect macOS Safari, and only affects iOS? |
@andynewman10 it affects all platforms that have Safari and support Web Push |
Hello everyone I am also struggling with getting notifications on my react native app as well and wait until was working well until recently, however I have run into problem with notifications on iOS again. |
Operating System
iOS 18.4+
Browser Version
Safari
Firebase SDK Version
10.7.2
Firebase SDK Product:
Messaging
Describe your project's tooling
NextJS 13 PWA
Describe the problem
Push notifications eventually stop being received until device is re-registered. Can take a few hours and lots of messages to occur but eventually stops receiving push.
People mention this can be a cause, Silent Push can cause your device to become unregistered:
https://dev.to/progressier/how-to-fix-ios-push-subscriptions-being-terminated-after-3-notifications-39a7
https://developer.apple.com/documentation/usernotifications/sending_web_push_notifications_in_web_apps_and_browsers
Possible that Firebase does not waitUntil and WebKit thinks its a invisible push?
Steps and code to reproduce issue
public/firebase-messaging-sw.js
The text was updated successfully, but these errors were encountered: