Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase on iPad's Safari; Can't find variable: Notification

I use Firebase's cloud messaging, but it won't work on iPad and iPhone. It's the simplest usage i can do with it. I just did all the tutorial about offsite notifications but i got this error directly in the Firebase's scriptenter image description here.

like image 243
Crak_mboutin Avatar asked Jan 05 '17 20:01

Crak_mboutin


2 Answers

iOS does not support the Notification API https://caniuse.com/#search=Notification

I created a function that lets you know if the user's browser supports it.

const isSupported = () =>
'Notification' in window &&
'serviceWorker' in navigator &&
'PushManager' in window

And the use it before using the Notification API

eg:

if (isSupported()) {
const hasPermission = Notification.permission === 'granted'}
like image 178
Jeremy Tenjo Avatar answered Nov 19 '22 12:11

Jeremy Tenjo


The firebase JavaScript library you're using is incompatible with Safari on iOS. The Safari browser that runs on iOS devices is not the same as the desktop build of the application and does not have the same feature set.

In this specific case, iOS Safari is throwing an error on your firebase.js library attempting to use the Web Notification APIs requestPermission() method in order to allow firebase to show notifications to the user. The Notification API doesn't exist though.

You can see the support for the Notification API here: http://caniuse.com/#search=Notification

You may have to look at an alternative or disable the firebase library when your web app is viewed on mobile devices which don't support it. If it's supposed to work on iOS Safari then you should file a bug with Firebase and see if there's a patch or update available which resolves the issue in the firebase.js library.

like image 24
Jeff U. Avatar answered Nov 19 '22 13:11

Jeff U.