我有一个网络通知脚本,工作正常。但是,当我在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这样的网站时,它们似乎工作正常。只有我的不工作
答案 0 :(得分:5)
我遇到过类似的问题。 你特别关注chrome版本43。
检查manifest.json
。既然你已经告诉过它适用于更高版本,我认为你已经错过了清单中的某些东西。在这个link中,Matt Gaunt建议如果清单出现问题可能会发生此错误。
确保最后没有逗号逗号。
此外,版本43不支持通知对象中的数据属性,并且不允许在点击通知时打开窗口,因此您也需要处理这些问题。 / p>
答案 1 :(得分:5)
我遇到过这个问题。 除了prajnavantha答案之外,这可能是由于在阻止它时意外点击浏览器通知引起的。 要在Chrome中修复此问题,请转到设置 - >点击'显示高级设置' - >在'隐私'点击'内容设置' - >然后点击'通知'选择'管理排除'。进入此处后,请允许通知受影响的网址。
答案 2 :(得分:0)
您可能还配置了Chrome以阻止所有通知。转到chrome://settings/content/notifications并确保滑块已滑动。
答案 3 :(得分:-1)