简体   繁体   English

ServiceWorker生命周期和推送通知

[英]ServiceWorker LifeTime & Push Notifications

i have a question regarding to ServiceWorkers. 我对ServiceWorkers有疑问。 I know that those Workers may be terminated by the user agent. 我知道这些工作人员可能会被用户代理终止。 Will a so terminated ServiceWorker be able to still receive Push Notifications and wake up to them? 这样终止的ServiceWorker是否仍可以接收推送通知并唤醒它们?

If not, are there any information about how long the service is allow to run usually? 如果不是,是否提供有关该服务通常可以运行多长时间的信息? I'm targeting Chrome on Desktop as well as Chrome Mobile. 我的目标是桌面版Chrome和移动版Chrome。

I'm curious about how much i can rely on the workers and how much i can integrate them in my further apps. 我很好奇我能在多大程度上依靠这些工人,以及能将他们整合到我的其他应用程序中的程度。

Edit: What i really did not expected: If i go to this example and manually stop the Service Worker (should be equal to termination trough user agent) and then submit a push notification, the service worker gets resumed. 编辑:我真的没想到的是:如果我转到此示例并手动停止Service Worker(应等于终止用户代理终止),然后提交推送通知,则Service Worker将恢复。

Therefore i assume that Push Notifications can wake up a terminated service worker. 因此,我认为推送通知可以唤醒终止的服务人员。 Is there any limitation? 有什么限制吗?

A terminated service worker is still capable of handling a push event. 终止的服务人员仍然能够处理push事件。 The browser will start up the appropriate service worker when it detects an incoming push notification from the Web Push server (eg, Google Cloud Messaging). 当浏览器检测到来自Web Push服务器(例如Google Cloud Messaging)的传入推送通知时,它将启动适当的服务程序。 The incoming push message includes registration information, which allows the browser to figure out which specific service worker to start up. 传入的推送消息包括注册信息,该信息使浏览器可以确定要启动哪个特定的服务工作者。

There are some requirements to fulfill in order for the browser to receive the incoming push notification from the Web Push server. 为了使浏览器从Web Push服务器接收传入的推送通知,需要满足一些要求。

On desktop operating systems, the actual browser process needs to be running. 在桌面操作系统上,实际的浏览器进程需要运行。 So, for example, if you're a Chrome on OS X user and you quit Chrome, you won't receive any push notifications until you start up Chrome again. 因此,例如,如果您是OS X上的Chrome用户并且退出了Chrome,则只有重新启动Chrome才能收到任何推送通知。 (At which point, a bunch might all flow in at once.) (此时,一堆可能会全部流入。)

On Android, the connection with the Web Push server is handled via the operating system, and Chrome (and I believe Firefox) does not have to be "running" in order to process the incoming notification and start up the correct service worker. 在Android上,通过操作系统处理与Web Push服务器的连接,并且Chrome(我相信Firefox)不必“运行”即可处理传入的通知并启动正确的服务程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM