Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resetting denied HTML notifications

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.

like image 284
firebolt_ash Avatar asked Jun 30 '15 08:06

firebolt_ash


People also ask

How to Reset notification permission in browser?

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.

How to Clear cache of notifications?

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.


2 Answers

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.

like image 161
sideshowbarker Avatar answered Nov 14 '22 22:11

sideshowbarker


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.");
  }
like image 33
xorneyToad 'satchel Avatar answered Nov 14 '22 23:11

xorneyToad 'satchel