Google chrome 网络推送 api 错误
Google chrome web push api bug
这是什么错误?发送网络推送浏览器时 Google Chrome "sometimes" 给出第二条消息,文本为:"This site has been updated in the background."
我想让它只有一条消息
我在源代码中找到的这段文字 Chrome
该站点已在后台更新。
github.com/scheib/chromium/blob/master/chrome/app/resources/generated_resources_en-GB.хтб
如何删除此消息。
它的工作方式是一项功能,而不是错误。
这是一个解释您在 Chrome 中的情况的问题:https://code.google.com/p/chromium/issues/detail?id=437277
Chromium 代码中更具体的代码注释:
https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/push_messaging/push_messaging_notification_manager.cc&rcl=1449664275&l=287
可能发生的情况是发送给客户端的一些推送消息没有显示通知。
希望对您有所帮助
经常发生这种情况的原因是返回给 event.waitUntil()
的承诺没有通过显示通知解决。
可能显示默认推送通知的示例:
function handlePush() {
// BAD: The fetch's promise isn't returned
fetch('/some/api')
.then(function(response) {
return response.json();
})
.then(function(data) {
// BAD: the showNotification promise isn't returned
showNotification(data.title, {body: data.body});
});
}
self.addEventListener(function(event) {
event.waitUntil(handlePush());
});
相反,您可以将其写为:
function handlePush() {
// GOOD
return fetch('/some/api')
.then(function(response) {
return response.json();
})
.then(function(data) {
// GOOD
return showNotification(data.title, {body: data.body});
});
}
self.addEventListener(function(event) {
const myNotificationPromise = handlePush();
event.waitUntil(myNotificationPromise);
});
之所以这一切都很重要,是因为浏览器等待传递给 event.waitUntil 的 promise 来解决/完成,因此他们知道服务工作者需要保持活动状态并且 运行.
当 promise 为推送事件解决时,chrome 将检查通知是否已显示,并且它属于竞争条件/特定情况,即 Chrome 是否显示此通知.最好的办法是确保你有一个正确的承诺链。
我在此 post 上对承诺做了一些额外的注释(参见:'Side Quest: Promises' https://gauntface.com/blog/2016/05/01/push-debugging-analytics)
这是什么错误?发送网络推送浏览器时 Google Chrome "sometimes" 给出第二条消息,文本为:"This site has been updated in the background."
我想让它只有一条消息
我在源代码中找到的这段文字 Chrome 该站点已在后台更新。 github.com/scheib/chromium/blob/master/chrome/app/resources/generated_resources_en-GB.хтб
如何删除此消息。
它的工作方式是一项功能,而不是错误。 这是一个解释您在 Chrome 中的情况的问题:https://code.google.com/p/chromium/issues/detail?id=437277
Chromium 代码中更具体的代码注释: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/push_messaging/push_messaging_notification_manager.cc&rcl=1449664275&l=287
可能发生的情况是发送给客户端的一些推送消息没有显示通知。
希望对您有所帮助
经常发生这种情况的原因是返回给 event.waitUntil()
的承诺没有通过显示通知解决。
可能显示默认推送通知的示例:
function handlePush() {
// BAD: The fetch's promise isn't returned
fetch('/some/api')
.then(function(response) {
return response.json();
})
.then(function(data) {
// BAD: the showNotification promise isn't returned
showNotification(data.title, {body: data.body});
});
}
self.addEventListener(function(event) {
event.waitUntil(handlePush());
});
相反,您可以将其写为:
function handlePush() {
// GOOD
return fetch('/some/api')
.then(function(response) {
return response.json();
})
.then(function(data) {
// GOOD
return showNotification(data.title, {body: data.body});
});
}
self.addEventListener(function(event) {
const myNotificationPromise = handlePush();
event.waitUntil(myNotificationPromise);
});
之所以这一切都很重要,是因为浏览器等待传递给 event.waitUntil 的 promise 来解决/完成,因此他们知道服务工作者需要保持活动状态并且 运行.
当 promise 为推送事件解决时,chrome 将检查通知是否已显示,并且它属于竞争条件/特定情况,即 Chrome 是否显示此通知.最好的办法是确保你有一个正确的承诺链。
我在此 post 上对承诺做了一些额外的注释(参见:'Side Quest: Promises' https://gauntface.com/blog/2016/05/01/push-debugging-analytics)