This repository was archived by the owner on Jul 8, 2024. It is now read-only.
This repository was archived by the owner on Jul 8, 2024. It is now read-only.
Safari requestPermission() Promise not supported. #117
Closed
Description
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
Activity
ellisio commentedon Aug 21, 2017
Hey @Nickersoft any update on this?
Nickersoft commentedon Aug 22, 2017
Hi @ellisio! Sorry, I've been busy lately! You're totally right... I'll see if I can get a fix out by the end of the week. I think if the browser supports the promises API it throws a depreciation warning, so some extra logic will need to be added to prevent that. It's actually surprising, as Safari is one of the browsers testing this library on BrowserStack and all tests pass... maybe the permission tests need to be revisited.
n3il commentedon Sep 11, 2017
This looks ... promising
#120
Edit: that issue doesn't seem to be an attempt to fix Push.js for Safari.
basiclines commentedon Sep 13, 2017
Looks like the official Safari web documentation uses a callback for the
requestPermission
function.https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/NotificationProgrammingGuideForWebsites/LocalNotifications/LocalNotifications.html#//apple_ref/doc/uid/TP40012932-SW1
n3il commentedon Sep 14, 2017
Very helpful @basiclines.
I'm still testing, but I opened this PR #124.
n3il commentedon Sep 15, 2017
So this PR (#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
requestPermission
method doesn't return the permission name in Safari. So we get it from window instead.Also a plus, assuming that Safari removes
webkitNotifications
entirely 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
n3il commentedon Sep 18, 2017
@Nickersoft Thoughts?
You could even add a Push.js specific support table for browser notifications, using the Notifications API.
Nickersoft commentedon Sep 19, 2017
@n3il I went ahead a merged your PR (sorry I've been so busy lately.. taken me awhile to get around to it). I like your idea of a support table. I'll see if I can put one together and post it on pushjs.org.
n3il commentedon Sep 19, 2017
@Nickersoft Thanks. I think we can close this ticket out then. Looking forward to it 👍
Nickersoft commentedon Sep 19, 2017
Cool beans :) Thanks for the contribution @n3il!
dsalzr commentedon Oct 3, 2017
I'm also getting this error:
undefined is not an object (evaluating 'this._win.Notification.requestPermission().then')
Looks like you committed some code to fix it. Are you planning on releasing 1.0.5 soon?
Thanks!
lensisle commentedon Jul 18, 2018
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!
joshbeckman commentedon Oct 17, 2018
It seems the thinking here was that the
webkitNotification
API with callback-based permissions would be kept to support older Safari. The assumption was that Safari would not drop the deprecatedwebkitNotification
API without also updating to the modernNotification
/promise-based permissions API.That didn't happen. :(
Safari (in Mojave, at least) dropped the webkit prefix but also still used the old callback-based permissions API.
andresbravog commentedon Apr 12, 2019
this is still broken on last package version, can you release a new version?
mxshdev commentedon Jun 20, 2019
Also not working in last version package.
SohrabZ commentedon Jul 22, 2019
Any updates on this issue?
tuborgbeer commentedon Aug 5, 2019
Safari is shit abandon this browser. Forward this issue to Apple they must fix one
RajeshMalviya14 commentedon Aug 30, 2019
This is working for me
if (Notification.permission === "granted") {
console.log('allow', result);
return true;
}
if (!Notification.requestPermission()) {
return true;
}
Notification.requestPermission().then(function (result) {
if (result === 'denied') {
console.log('denied', result);
return;
}
if (result === 'granted') {
console.log('allow', result);
}
}