【发布时间】:2021-12-29 04:55:24
【问题描述】:
这发生在仅限 Chrome(应用程序目前不支持任何其他浏览器)和最新版本上。
我无法重现此问题,但它会定期出现在我们随机用户的监控仪表板中。
错误信息:“AbortError: 注册失败 - 推送服务错误”
以下代码块在页面加载时运行:
const currentNotificationsPermission = await navigator.permissions.query({ name: 'notifications' });
currentNotificationsPermission.onchange = function onchange() {
// Update the internal state, this can happen after user interaction (clicking a "Allow notifications" button)
};
这在页面加载时运行(当内部状态为 granted 时),或者在用户手势后内部状态 更改 为 granted 时:
navigator.serviceWorker.register('/serviceworker.js', { scope: '/myScope' });
navigator.serviceWorker.ready.then((registration) => {
const subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: 'myKey',
};
return registration.pushManager.subscribe(subscribeOptions);
}).then((pushSubscription) => {
// Send pushSubscription to server, doesn't run in case of AbortError
}).catch((err) => {
console.log(err); // AbortError, randomly
});
【问题讨论】:
标签: javascript service-worker web-push