Skip to content
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
@ellisio

Description

@ellisio

Hello,

According to the MDN, Safari does not support the requestPermission().then() Promise version.

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission#Browser_compatibility

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

ellisio commented on Aug 21, 2017

@ellisio
Author

Hey @Nickersoft any update on this?

Nickersoft

Nickersoft commented on Aug 22, 2017

@Nickersoft
Owner

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

n3il commented on Sep 11, 2017

@n3il
Contributor

This looks ... promising
#120

Edit: that issue doesn't seem to be an attempt to fix Push.js for Safari.

n3il

n3il commented on Sep 14, 2017

@n3il
Contributor

Very helpful @basiclines.

I'm still testing, but I opened this PR #124.

n3il

n3il commented on Sep 15, 2017

@n3il
Contributor

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

n3il commented on Sep 18, 2017

@n3il
Contributor

@Nickersoft Thoughts?

You could even add a Push.js specific support table for browser notifications, using the Notifications API.

Nickersoft

Nickersoft commented on Sep 19, 2017

@Nickersoft
Owner

@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

n3il commented on Sep 19, 2017

@n3il
Contributor

@Nickersoft Thanks. I think we can close this ticket out then. Looking forward to it 👍

Nickersoft

Nickersoft commented on Sep 19, 2017

@Nickersoft
Owner

Cool beans :) Thanks for the contribution @n3il!

dsalzr

dsalzr commented on Oct 3, 2017

@dsalzr

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

lensisle commented on Jul 18, 2018

@lensisle

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

joshbeckman commented on Oct 17, 2018

@joshbeckman
Contributor

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 deprecated webkitNotification API without also updating to the modern Notification/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.

self-assigned this
on Oct 22, 2018
andresbravog

andresbravog commented on Apr 12, 2019

@andresbravog

this is still broken on last package version, can you release a new version?

mxshdev

mxshdev commented on Jun 20, 2019

@mxshdev

Also not working in last version package.

SohrabZ

SohrabZ commented on Jul 22, 2019

@SohrabZ

Any updates on this issue?

tuborgbeer

tuborgbeer commented on Aug 5, 2019

@tuborgbeer

Safari is shit abandon this browser. Forward this issue to Apple they must fix one

RajeshMalviya14

RajeshMalviya14 commented on Aug 30, 2019

@RajeshMalviya14

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);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @dsalzr@ellisio@andresbravog@basiclines@lensisle

    Issue actions

      Safari requestPermission() Promise not supported. · Issue #117 · Nickersoft/push.js