The Notification.requestPermission()
has 3 possible results: granted
, denied
and default
.
In Chrome you get default
when the user close the permission dialog using the X instead of explicitly saying block
. But, if after getting default
as result, you call Notification.permission
you get denied
, making impossible to retry asking permission again in the future.
It this by design? is there a way to make chrome treating differently this two results? Firefox treats this in the right way (you can ask permissions until the user explicitly denied it)
I'll leave this just in case someone is looking for an answer:
When the user had closed the permission dialog for the third time Chrome will automatically set the permission to denied
(it shows a automatically blocked
message below on the permission popup from the navbar). So the first three times the user close the dialog you gets default
as result, but on the third time the permission are set to denied
.
The way I'm using to work with this logic is:
window.Notification.requestPermission().then((result) => {
if (result === 'denied') {
// the user has denied permission
return;
}
if (result === 'default') {
// the user has closed the dialog
if (window.Notification.permission === 'denied') {
// the browser has decided to automatically denied permission
}
return;
}
// the user has granted permission
});
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