问题描述
我仅在打开 chrome 时才能在 chrome 中看到 Facebook 网页的推送通知.我知道此通知是通过 service worker 发送的.我想知道这种后台同步是否会在浏览器关闭的情况下继续进行,还是仅在打开 chrome 时才进行,只有这些 service-worker 同步过程开始并开始发送推送通知.
I see push notification for Facebook web in chrome only when I open chrome. I know that this notification are sent through service worker. I am wondering whether this background sync goes on even though browser is closed or only on opening chrome only these service-worker sync process get started and start sending push notification.
推荐答案
首先要说的是这在某种程度上取决于平台.我对 chrome 的理解是:
First thing to say is this depends somewhat on the platform. My understanding of chrome is:
在 Windows 和 Mac OS X 等桌面平台上,浏览器需要运行一些后台进程才能让 Service Worker 运行.在 Mac OS X 上,这很容易检测到,因为浏览器可以不打开任何窗口,但浏览器下方仍然有发光点.
On desktop platforms like windows and Mac OS X the browser needs to have some background process running for a service worker to be able to run. On Mac OS X this is quite easy to detect as the browser can have no windows open but the browser still has the glowing dot beneath it.
在移动平台上,可以更轻松地侦听事件并以有效的方式处理它们,因此在这些情况下,平台可以唤醒浏览器,然后浏览器将处理任何相应的事件.
On mobile platforms it's easier to listen for events and handle them in an efficient manner, so in these cases the platform can wake up the browser which will then handle any corresponding events.
以上适用于任何 Service Worker api.
The above applies to any service worker api's.
在桌面上:如果浏览器完全关闭,那么 Service Worker 将无法运行并且不会调度任何事件(即没有推送或后台同步事件)
On Desktop: If the browser is completely closed then service workers can not run and will not dispatch any events (i.e. no push or background sync events)
在移动设备上:事件仍将被分派(即,当用户设备上线时将触发后台同步并接收推送并引发推送事件).
On Mobile: The events will still be dispatched (i.e. background sync will trigger when the users device comes online and push will be received and cause a push event).
这篇关于即使浏览器关闭,Service Worker 是否也在后台运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!