Notification.requestPermission() not requesting permission

11,441

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.

Share:
11,441

Related videos on Youtube

unixcorn
Author by

unixcorn

Updated on June 04, 2022

Comments

  • unixcorn
    unixcorn almost 2 years

    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?

  • unixcorn
    unixcorn about 5 years
    Thank you for such a quick response; I still don't get a request. All that gets printed on my console is "Webconsole context has changed \n permiss default"
  • YetAnotherBot
    YetAnotherBot about 5 years
    which browser ?
  • YetAnotherBot
    YetAnotherBot about 5 years
    Also, could you please paste the above code directly in the browser console and test? It works for me.
  • unixcorn
    unixcorn about 5 years
    It's firefox. I just tried it and I get: > Promise { <state>: "pending} \n permiss default. No request for notification permissions whatsoever :(
  • YetAnotherBot
    YetAnotherBot about 5 years
    I just tried this. After fiddling around it seems browsers remember your decision and resolve your request on past decisions.
  • unixcorn
    unixcorn about 5 years
    The jsfiddle definitely works, in both chrome and firefox (this is for a firefox addon). The thing is, my addon still doesn't fire up a request. I got rid of 'window' and the console doesn't even print 'perm granted'. Just 'Webconsole context has changed'. Thank you for the help.
  • unixcorn
    unixcorn about 5 years
    I just tried adding another console.log statement before 'console.log('Perm granted', getperm). This console.log statement doesn't even get printed. I think I'm simply not entering the function.
  • unixcorn
    unixcorn about 5 years
    I thought so too, and reset firefox. I decided to post on SO after even that didn't work. Any suggestions?
  • YetAnotherBot
    YetAnotherBot about 5 years
    Check the latest answer.