-
Notifications
You must be signed in to change notification settings - Fork 930
Feature Requests: FCM for safari 16 #6620
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
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
isSupported function returns true for Safari 16. Does that mean that FCM supports Safari or that Safari just supports all required browser APIs for web push? |
The FCM quick start app runs background notifications successfully for me on Safari 16.2 with macOS Ventura. macOS 13 Ventura (released Oct 2022) is the minimum requirement according to Apple's documentation |
I tried firebase messaging v9.16.0 in my app and it seems to work in background (when delivered by the service worker) but in foreground only receives notifications 3 times (messaging.onMessage handler). |
I just tried on Safari tech preview 16.4 and I get this error, what version of firebase SDK you running? EDIT: It worked in 16.3 non preview.! |
Unfortunately it does not work on iOS 16.4 beta
|
What firebase version are you using? (i assume frontend and service worker would have the same version) |
Hi @andreififiita , both are running the latest (9.18.0) |
hello, quick question, i am using a java backend with java 7 (unfortunately) so I have the java sdk ver 8.2.0 and for the service worker I am running 9.16.0 compat version, on chrome it works fine but in Safari I don't receive any notifications. Token registration and everything else works fine. Is it a version problem? (Can't go to java 8) |
I managed to test firebase on iOS 16.4 and successfully receive notifications, but i do have a problem when application is in foreground: when the user is using the app (in focus), the notifications are received only 3 times (which come from data firebase messages). The notifications are displayed in the app's UI (for example the user is using a chat view to talk with another user, i do not display the notification in OS bar). This doesn't happen if the app is in background, when the notifications are delivered to the OS notification bar. But every time i tested on foreground, it fails receiving notifications more than 3 times. Also, if i call method to getToken() after this, firebase returns a new token (seems like the previous one is being invalidated). I have the same behavior on Safari on macos 13.3 Ventura. I am using 9.16.0 compat version (but i assume, using modular or compat versions shouldn’t have any behavioural differences, right?) EDIT: on Chrome and Firefox (MacOS) everything works fine, no issues there. |
@andreififiita did you change anything when you tried safari? Firebase on chrome with compat works for me. Safari background or foreground won't work whatever I do, network shows no notification. |
i fixed it, it was a stupid bug in my code, the 3 notifications problem occurs to me too, the reason it happens to you @andreififiita is because for some arbitrary reason the token resets after 3 notifications, I noticed it because when I refreshed a new token was created. |
Sorry, i forgot to explicitly mention: on Chrome and Firefox (MacOS) everything works fine, no issues there. But did you manage to find a solution or workaround for why the foreground notifications only come 3 times and then it stops? (invalidated firebase token it seems) |
Probably Safari deletes the token because it considers it spam? |
@andreififiita : I am also having the same issue, on chrome and mozilla firefox it works perfectly, but on safari it just receives three notifications and then stop. What I have found is, if we are not able to publish notification to the notification center, safari revokes the token and we have to follow the workflow again for getting the new token. If you watch this video (last 5-10 mins), they have explicitly mentioned that after 3 notifications they will revoke the token if notification is not published to notification center. My point is as we are using FCM (onMessage handler) and generating the notifications using the new Notification() constructor, it should go to the notification center. What I have observed and I did get more then 3 notifications is(background use case) : if we do not do any handling for the background message in service worker file, and just service worker do the work, we get the notifications without any issue. But for foreground(when tab is active) we have to do(onMessage handler), otherwise no message will be shown. |
Hi, i also tried creating "new Notification()" in the foreground onMessage() handler but it still failed. I believe i also tried sending a postMessage to the service worker (last test a few months ago), and still failed. So i am am not sure where exactly safari "counts 3 times". Also, from what i know, the service worker's messaging.onBackgroundMessage() won't be executed if the app is in foreground. Maybe is there a way to go around this, at least for the time being? |
Hello @andreififiita : With some work around, I am able to get the notifications on safari for both foreground and background message. Couple of observations that I have found :
So, my guess is safari think that when we use n = new Notification(in case of client.postMessage() or onMessage), we are not directly delivering it to the notification center. I have also tried with service worker registration -> show notification method in the onMessage call, it didn't work. Final Workaround :
Sample code in service worker : var title = 'Yay a message.'; |
I was thinking to bypass the fcm service worker handling as well, but i didn't know i needed event.stopImmediatePropagation(). Thanks for the this info. |
And also, i can't seem to find the FCM data in the push event. the "event.data" field seems to be empty. EDIT: |
Does anyone have a full/working example of what they needed to do to get this working? Any official response from Firebase yet? |
@lincolnthree : For safari, they might have to handle the foreground message differently, currently for foreground message handling, they use the client(browser) postMessage to send a message to the client, and in client side code, the developer handle it through listening on the "onMessage" hook, and then uses the browser notification API to generate the notification.. What can be done to make that working :
`self.addEventListener('push', function(event) { var title = 'Yay a message.'; |
I confirm this workaround worked for me. The caveat is that, when in foreground, i am obliged to show notifications in the OS notification bar all the time, even though use has the respective UI context which contains the data from the notification (a view or an activity or a popup or a page, according to your app's business logic) right in their face. |
Does anyone know if messages composed/sent using the Firebase console works with Safari and the above solution listening in on the EDIT: After testing sending a notification with the Java SDK, I get |
It's working well in Safari 16.5 but a note:
|
They have supported it starting from Safari 16.1 |
Hi, is anyone else experiencing issues with firebase messaging on safari 17.4? It seems firebase requests to https://fcmregistrations.googleapis.com/ are failing with 400 Bad Request. I tested so far in in Safari 17.4.1 MacOS Ventura 13.6.6 (22G630). I am using firebase 10.10.0: Specifically, requests to "https://fcmregistrations.googleapis.com/v1/projects/.../registrations/" seem to have missing data in the payload: Everything works well on chrome and firefox, latest versions. If someone managed to find a solution for this, please let me know. |
Does anyone have a working app online where firebase messaging actually works in Safari 17.4 or 17.5 (macos or ios)? |
@andreififiita I also use Safari 17.5 on macOS Ventura and observe something similar. Did you find a solution for this? I tried downgrading firebase-js-sdk but it produces the same results. Not having firebase messaging running on Safari is a huge limitation. |
I did not find a solution yet. What is interesting is that nobody else seem to comment on this a lot (i see almost no feedback anywhere, if it either works or not for them). I posted on stackoverflow also: https://stackoverflow.com/questions/78323312/firebase-cloud-messaging-web-issues-in-safari-17-4 |
Just to confirm, we are also waiting for Firebase to fix this. Push notifications on iOS work, but only once and then the subscription gets removed. So we currently disable push notification in our web app for iOS until this is fixed. |
@ljvanschie can you confirm that you do manage to get things working on Safari 16.4+ or 17? Just to confirm, for you, messaging works (all the time), only notifications are no longer received after a while, right? |
We've tested on several Safari versions but in none of them it worked without issues. I don't see a difference between messaging or notifications, we only use Firebase for web push notifications. These get sent the first time and appear correctly, but the registration gets removed so after receiving one, users need to register their device again (which is of course not a working solution). |
Thanks for the clarification. By notification vs. plain messages, I meant
Do you observe the same behavior (i.e. client getting somehow "unregistered") with both types of messages?
Not ideal, but doesn't re-registering after receiving every single message work? (why wouldn't it work?) |
Both @andreififiita and I seem to be using macOS Ventura (and Safari 17.4+). To all people subscribed to this issue: which macOS version are you using? Are you guys using macOS Sonoma? This could explain why only some of us experience problems with |
I have experienced the following:
I found that the firebase code is calling getToken when functions are initialized. async getContext(limitedUseAppCheckTokens) {
const authToken = await this.getAuthToken();
const messagingToken = await this.getMessagingToken();
const appCheckToken = await this.getAppCheckToken(limitedUseAppCheckTokens);
return { authToken, messagingToken, appCheckToken };
} This in some cases cause the following call: Then looking at the code I see that it is called when the token fetched is not valid. since the token is called as a side effect of getContext, no vapidKey is used, and the token probably does not match. So, as a workaround, I added as the first thing after initializing the app: const messaging = getMessaging(app);
messaging.vapidKey = 'BFMK8m...'; Now it seems to fine. const messaging = getMessaging(app);
messaging.vapidKey = 'BFMK8m...';
navigator.serviceWorker.register("my-service-worker.js", { scope: "<your-server>/firebase-messaging-sw.js"})
.then (swReg=>{
messaging.swRegistration = swReg;
}); [EDIT]:
const permission = Notification && Notification.permission;
if (permission === "granted") {
// here I also check if I have tokens persisted in my server, and if exist, I assume token exists
} in addition, here is my service-worker's code. I used postMessage to my site if notification is clicked: self.addEventListener('push', function (event) {
event.stopImmediatePropagation();
console.log('[Service Worker] Push Received.');
const payload = event.data.json();
const notificationTitle = payload.notification.title;
const notificationOptions = {
...payload.notification,
data: {
...payload.data,
click_url: payload.notification.click_action,
}
};
event.waitUntil(
self.registration.showNotification(notificationTitle, notificationOptions)
);
});
self.addEventListener('notificationclick', function (event) {
event.preventDefault();
console.log('Notification click Received.', event.notification.data);
event.notification.close();
event.waitUntil(
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (clientList) {
// Check if there is already a window/tab open with the target URL
for (let i = 0; i < clientList.length; i++) {
let client = clientList[i];
if (client.url.startsWith(event.notification.data.click_url) && client.focus) {
client.focus();
client.postMessage(event.notification.data);
return;
}
}
// If not, then open a new window/tab with the target URL
if (clients.openWindow) {
clients.openWindow(event.notification.data.click_url).then((windowClient) => {
windowClient.postMessage(event.notification.data);
});
}
})
);
}); and in my site's code: |
Honestly I've just been waiting, watching this thread until someone says they got it working without issues, because I don't have extra hours to try to figure this out :( |
still, almost 2025 not working correctly in safari (ios). |
same here |
I'm going to close this thread, not because there aren't any FCM bugs with Safari, but the opposite - and we should have specific issues threads for each specific FCM/Safari issue. The initial post is that FCM should officially support Safari as of the release of Safari 16 and Safari push notifications, and it is now officially listed as supported, so that feature request is outdated. The problem, of course, is there are still many issues and many people cannot get it to work. Here's a known issues page that covers several of the issues (especially with Safari-based PWAs): Quick quote of that page as of now:
If you have one of those issues, you can go to those issue links and read/post there. If you have an issue that isn't on that page, and can't be found by searching the issues here, create a new issue with the specific issue you are seeing and as much info as possible. |
这是来自洪俊贤的自动回复邮件。
|
As Safari 16 has now Push APIs support. Will FCM work for Safari 16?
Thanks
The text was updated successfully, but these errors were encountered: