unixcorn
unixcorn

Reputation: 440

Notification.requestPermission() not requesting permission

enter image description here

The browser keeps forgoing to ask permission for notifications and just decides it's on default. How do I get it to ask for permission so I can actually accept?

Upvotes: 12

Views: 33850

Answers (3)

TOG
TOG

Reputation: 156

I experience the same/a similar issue in the "Samsung Internet" app on Android (current release). Notification.requestPermission() returns default but no prompt is actually shown.

This is my exact situation:

  • I created and released a web application with PWA capabilities some months ago. Within the app, users can trigger the Notification permission prompt and - when accepting the permission prompt - get WebPush Notifications.
  • I installed the PWA on my Android mobile using the "Samsung Internet" app and triggered/accepted the notification permission prompt.
  • Then I moved the web application to a new server. Since then Notification.requestPermission() returns default but no prompt is actually shown anymore.

My code works as expected in the desktop versions of Edge, Chrome and Firefox (even after moving the web application to the new server), just not in the "Samsung Internet" app on Android.

As per my understanding, if notifications were already accepted, then Notification.requestPermission() should return granted and of course no prompt should be shown. And if notifications were already rejected, then Notification.requestPermission() should return rejected and of course no prompt should be shown neither. But since Notification.requestPermission() actually returns default (I verified this on my mobile!), I would expect the prompt to be shown in any case. Is this expectation correct or am I missing something? Any idea why the prompt is not shown on my mobile in this situation?

Edit on April 19th, 2023: After I completely uninstalled the PWA and cleared the website data from the "Samsung Internet" app and installed the PWA again, it worked again. But still I wonder why the promt was not shown even if the Notification.requestPermission() returned default ...?

Upvotes: 2

itsfreddyrb
itsfreddyrb

Reputation: 99

I believe that you are already resolving the promise with the function inside then(). I'm testing your example by removing window. and it works for me.

Notification.requestPermission().then(function(getperm) 
{ 

    console.log('Perm granted', getperm) 

});

https://jsfiddle.net/freddyr0/x43j8tf5/

Upvotes: 1

YetAnotherBot
YetAnotherBot

Reputation: 2086

This works:

Notification.requestPermission().then(function(permission) { console.log('permiss', permission)});

Function inside .then() is already a resolve-handler to the promise initiated by requestPermission().

Browsers save your decision for the particular domain and will not ask for your permission again.

For them to ask again you would have to make them forget your last decision. This is how you can do it in Firefox:

enter image description here

Delete the permission here and reload the page for the browser to ask you again.

Upvotes: 10

Related Questions