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.');
});
});
};
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With