我有一个运行良好的网络通知脚本。但是,当我在 chrome 版本 43 中进行测试时,我收到错误“DOMException:注册失败 - 权限被拒绝”。此错误发生在订阅阶段。
这是通常的注册过程的代码片段
navigator.serviceWorker.register('sw.js').then(function(reg) {
console.log('[ServiceWorker] Registration Obj', reg);
reg.pushManager.subscribe({
userVisibleOnly: true
}).then(function(sub) {
//This never executes and catch gets called
console.log('Subscription successful, Subscription endpoint:', sub.endpoint);
}).catch(function(error) {
console.log("Error during subscription ", error);
});
}).catch(function(error) {
if (Notification.permission === 'denied') {
console.warn('Permission for Notifications was denied');
} else {
console.error('Unable to subscribe to push.', error);
}
});
在上面的代码中,错误发生在我执行
reg.pushManager.subscribe()
的步骤中。 .[注意] 我认为这是 chrome 版本 43 的一般问题,但是当我检查 goroost.com 和 pushcrew 等网站时,它们似乎工作正常。只有我的不工作
最佳答案
我遇到过这个问题。
除了般若答案外,这可能是由于浏览器通知在屏蔽与否时不小心点击造成的。
要在 Chrome 中解决此问题,请转到设置->单击“显示高级设置”->在“隐私”下单击“内容设置”->然后在“通知”下选择“管理异常”。进入此处后,允许通知受影响的 URL。
关于javascript - DOMException : Registration failed - permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36126541/