Push notifications in Apple Safari with FCM

26,828

Solution 1

While Service Workers now work on Safari, they are not enough.

The documentation says:

The FCM JavaScript API lets you receive notification messages in web apps running in browsers that support the Push API. This includes the browser versions listed in this support matrix.

Safari doesn't support web push, which FCM relies on for browser support. So that means that Safari can't receive FCM notifications.

Solution 2

Safari still does not support Web Push API, thus Firebase Cloud Messaging service.

Here is supported browsers in Firebase: https://firebase.google.com/support/guides/environments_js-sdk#browsers

I'd suggest using .isSupported() instead of other solutions.

if (firebase.messaging.isSupported())
    const messaging = firebase.messaging();
}

See the documentation for details on .isSupported().

Solution 3

I'm not sure about this new Safari and Service Workers situation, but I tried to implement FCM push-notifications in my iOS app and had to experience that you need an APN (Apple-Push-Notification) certificate first. I'm not sure if this is needed if you're working with Safari, but I could imagine that Apple also wants it's push notifications first to be redirected to the APN servers.

Share:
26,828

Related videos on Youtube

Nicolas Rojo
Author by

Nicolas Rojo

Updated on January 26, 2022

Comments

  • Nicolas Rojo
    Nicolas Rojo over 2 years

    We implemented push notifications using FCM in chrome and firefox and it worked fine, but Safari doesn't support Service Workers which is mandatory for FCM.

    Did anyone deal with this kind of issues? any suggestions?

  • KayKay
    KayKay about 6 years
    Yes, to work with push notifications on Safari (desktop) we need the APN certificates generated for Web Push notifications from Apple Dev. console.
  • Evan Kirkwood
    Evan Kirkwood almost 6 years
    Is this still the case? According to the release notes for Safari 11.1, Service Workers are now supported. However, calling firebase.messaging().requestPermission throws an error: "messaging/unsupported-browser". Is there some other API support still missing?
  • Dimitrij Agal
    Dimitrij Agal almost 6 years
    Service Workers are supported in Safari 11.1 but it seems that it still doesn't support the Push API (caniuse.com/#feat=push-api).
  • Isaiah
    Isaiah almost 3 years
    In my case, I needed a version lock at 8.2.9 per github.com/firebase/firebase-js-sdk/issues/4633