javascript - 如何安排 Chrome 推送通知?

标签 javascript google-chrome google-cloud-messaging web-push push-api

我正在为我的网站用户实现 Chrome 推送通知。我可以通过 Service Worker 成功完成。我正在关注这些文章/教程

  1. https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web?hl=en
  2. http://www.html5rocks.com/en/tutorials/service-worker/introduction/

当我想现在发送通知时,这非常有效,即没有为 future 安排时间。

我的问题:

我想安排此通知在当天晚些时候重复出现,我可以通过 cron 来完成。但是 GCM 不会按照此处所述向您发送负载 https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web?hl=en我引用。

A downside to the current implementation of the Push API in Chrome is that you can’t send any data with a push message. Nope, nothing. The reason for this is that in a future implementation, payload data will have to be encrypted on your server before it’s sent to a push messaging endpoint. This way the endpoint, whatever push provider it is, will not be able to easily view the content of the push message. This also protects against other vulnerabilities like poor validation of HTTPS certificates and man-in-the-middle attacks between your server and the push provider. However, this encryption isn’t supported yet, so in the meantime you’ll need to perform a fetch to get information needed to populate a notification.

因此,我无法弄清楚我在浏览器中收到了哪个预定通知的推送事件。因为可能有多个通知发送到 GCM。

我正在获取通知表中的最后一条记录,即我总是显示最后一条记录数据。因为我不知道我在 Chrome 浏览器中收到了哪个通知的推送事件。

我的问题:

是否有解决方法来安排通知并向客户端/浏览器显示正确的通知?在原生 chrome 推送 api 中甚至有可能吗?

最佳答案

通过始终提供最新数据,您已经尽力而为。您可以考虑的一种替代方法是跟踪客户已被告知的事件,并在每次获取信息时转移到下一个事件。当然,这确实有可能会不同步。

我们计划在 Chrome 49 中提供对数据负载的支持(应该会在 3 月份进入稳定版)。这允许您在消息中包含最多 4KB 的数据,应该可以解决您的问题。

请注意,使用有效负载需要您对消息中包含的数据进行加密。我们将在发布时提供详尽的文章(类似于您链接到的文章)和库。

关于javascript - 如何安排 Chrome 推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34153287/

相关文章:

c# - <asp :Textbox> have a onFocusLost event? 是否

android - 为什么 PLAY_SERVICES_RESOLUTION_REQUEST 是 9000

java - App Engine 后端与 Google Cloud Messaging 向 1000 多名用户发送消息

javascript - fb分享不带og :image dynamically

c# - 使用参数从 JavaScript 调用 C# 方法

javascript - Chrome 中的循环结构到 JSON

google-chrome - Chrome devtools 配置文件火焰图中的这个差距是什么意思

android - 将 intent extras 从谷歌云消息接收器传递到 Activity 是空的

javascript - 在缺少尾部斜杠的页面中构建相对 URL/

browser - 如何指定网页的语言,以便 Google Chrome 不提供翻译功能