push.js: Safari requestPermission() Promise not supported.
Hello,
According to the MDN, Safari does not support the requestPermission().then() Promise version.
So when Push.Permission.request() is called in Safari users get the following error:
undefined is not an object (evaluating 'this._win.Notification.requestPermission().then')
Due to this block: https://github.com/Nickersoft/push.js/blob/master/src/classes/Permission.js#L34-L39
Cheers, Andrew
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 18 (10 by maintainers)
Safari is shit abandon this browser. Forward this issue to Apple they must fix one
Hi !
I’m getting this error on safari too:
undefined is not an object (evaluating ‘this._win.Notification.requestPermission().then’)
any news about the status of this issue? I’ll be glad to help if there’s anything more to do to fix this problem.
Thanks!
Also not working in last version package.
this is still broken on last package version, can you release a new version?
So this PR (https://github.com/Nickersoft/push.js/pull/124) works and is tested against Chrome, Safari, and Firefox.
The Fix: Checking for Safari first means that it uses the callback method instead of the promise-based method which errors out. In addition, the
requestPermissionmethod doesn’t return the permission name in Safari. So we get it from window instead. Also a plus, assuming that Safari removeswebkitNotificationsentirely like Chrome did, the promise-based method will be used automatically on that Safari update.Also worth writing is that Safari is currently listed as having “No support” for promise-based Notifications. https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission