I have a web app in which I am using HTML Notifications. It works fine if the user allows it for the first time and start using it, however if user blocks the notification the first time by clicking the block button and later on try to request permission again by some user gesture then the browser doesn't trigger (Allow/Block) popup.
Here is the second time I am triggering the permission.
if(Notification.permission == 'denied' || Notification.permission == 'default'){
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
console.log("Regranted");
}
});
}
It works fine for the default
case but not for the denied
case.
If you do not have a notification open, open Chrome on Android, tap the 3-dot menu, Settings, Site settings (under Advanced), Notifications, make sure it's set to "Ask before sending (recommended)". Find your site on the list, click the entry, and click Clear and Reset.
To do this, open Settings > Apps & notifications then tap the app you want to address. On the App info page, tap the Storage option, then on the next page select Clear Cache.
The behavior you’re seeing is by design, as an earlier comment points out. If you read step 2, substep 2 at https://notifications.spec.whatwg.org/#dom-notification-requestpermission you’ll see the spec requires that the only time a user is asked whether showing notifications is acceptable is when the permission value is default
. If the permission value is granted
or blocked
, that algorithm requires that the user is never asked again whether showing notifications is acceptable.
Users who do change their minds about notifications for a site they’ve blocked have the option to go into their browser settings and change their permission settings for that site themselves.
I would recommend having a button to turn notifications on, then checking the permission there, falling back if it's been previously denied.
ex:
if (Notification.permission === "denied") {
alert("Notifications blocked. Please enable them in your browser.");
}
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