Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase safari error Messaging: This browser doesn't support the API's required to use the firebase SDK

We are using the firebase 8.2.1 version.
We are developing using react and typescript.
The error occurs only when I view it in safari. The error is FirebaseError: Messaging: This browser doesn't support the API's required to use the firebase SDK.(messaging/unsupported-browser).
I looked at the following document, but only safari does not support cloud messages.
How can I solve this problem?
https://firebase.google.com/support/guides/environments_js-sdk?hl=ja[enter link description here]1

import firebase from 'firebase/app';
import 'firebase/messaging';
import { asyncNotificationToken } from 'apis/asyncNotificationToken';

const firebaseConfig = {
  apiKey: '******************',
  projectId: '******',
  messagingSenderId: '*******',
  appId: '********',
};

const VAPID_KEY =
  '******************************';

if (firebase.apps.length < 1) {
  firebase.initializeApp(firebaseConfig);
}

export const prepareNotification = () => {
  firebase
    .messaging()
    .requestPermission()
    .then(() => {
      prepareNotificationToken();
    })
    .catch(() => {
      console.log('Unable to get permission to notify.');
    });
};

export const prepareNotificationToken = () => {
  firebase
    .messaging()
    .getToken({ vapidKey: VAPID_KEY })
    .then((token) => {
      asyncNotificationToken(token).then(() => {
        console.log('Registed notification token.');
      });
    });
};

a

export const prepareNotification = () => {
  let messaging = null;
  if (firebase.messaging.isSupported()) {
    messaging = firebase.messaging();
  }
  firebase
    .messaging()
    .requestPermission()
    .then(() => {
      prepareNotificationToken();
    })
    .catch(() => {
      console.log('Unable to get permission to notify.');
    });
};

export const prepareNotificationToken = () => {
  firebase
    .messaging()
    .getToken({ vapidKey: VAPID_KEY })
    .then((token) => {
      asyncNotificationToken(token).then(() => {
        console.log('Registed notification token.');
      });
    });
};
like image 704
yut Avatar asked Oct 29 '25 20:10

yut


1 Answers

Sadly Push API is not yet supported on Safari, thus Messaging doesn't work.

Check compatibility before trying to use it.

let messaging = null;
if (firebase.messaging.isSupported()){
    messaging = firebase.messaging();
}

See the documentation for details on .isSupported().

There is a feature request to support safari push notification on Mac desktop.

like image 110
Daniyel.Me Avatar answered Nov 01 '25 09:11

Daniyel.Me