Notification.requestPermission() 未请求许可

Notification.requestPermission() not requesting permission

浏览器一直放弃请求通知权限,只是决定它处于默认状态。我怎样才能让它请求许可,这样我才能真正接受?

这个有效:

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

.then() 中的函数已经是 requestPermission() 发起的承诺的解析处理程序。

浏览器会保存您对特定域的决定,不会再次请求您的许可。

要让他们再次询问,您必须让他们忘记您上次的决定。 在 Firefox 中,您可以这样做:

删除这里的权限,重新加载页面让浏览器再次询问你。

我相信您已经在使用 then() 中的函数解析 promise。我正在通过删除 window 来测试您的示例。它对我有用。

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

    console.log('Perm granted', getperm) 

});

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