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.
-
3Yes thats what they are for – Jonas Wilms Aug 29 '16 at 07:53
-
@Jonasw How to they move to inactive state? – Jagajit Prusty Aug 29 '16 at 07:59
-
http://stackoverflow.com/questions/39034950/google-chrome-push-notifications-not-working-if-the-browser-is-closed – Kevin Farrugia Aug 29 '16 at 11:31
-
@KevinFarrugia I understand that push notification will start popping once browser is started. But my question is will background sync of service worker will run even though browser is closed? – Jagajit Prusty Aug 29 '16 at 13:01
-
If not mistaken the same concept applies for any service worker API. – Kevin Farrugia Aug 29 '16 at 14:10
-
@KevinFarrugia That means, will background sync go to inactive state once the browser is closed? – Jagajit Prusty Aug 30 '16 at 05:02
-
@JagajitPrusty Try that demo using latest chrome\firefox https://wicg.github.io/BackgroundSync/demo/ Turn on airplane mode. Click register background sync. Then close browser. Then disable airplane mode. You should see a notification. – Kirill Reznikov Nov 24 '17 at 22:28
4 Answers
First thing to say is this depends somewhat on the platform. My understanding of chrome is:
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.
The above applies to any service worker api's.
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).

- 9,434
- 3
- 36
- 57
-
1I do work at Google and while I have a good understanding of how Chrome works, it's an ever evolving product and changes extremely quickly. Thanks for the heads up looks like my letsencrypt script has fallen over. – Matt Gaunt Aug 29 '16 at 22:16
-
@GauntFace If there is dot under chrome means it's still running so according to my understanding service worker can still perform background sync. But my query is if chrome is completely closed, can service worker perform background syncing? – Jagajit Prusty Aug 30 '16 at 05:01
-
-
Thanks for explanation. Please let me know if here can give some tip: https://stackoverflow.com/questions/58258677/how-can-i-wake-up-service-worker-when-browser-closed – Hhovhann Oct 06 '19 at 15:24
I don't think service worker will be able to run if browser is closed. Because service-worker is able to send push notification only after I open the browser. If it is running in the background then it could have send notification even after closing browser also.

- 2,070
- 2
- 21
- 39
-
within the w3c document (https://w3c.github.io/ServiceWorker/#user-agent-shutdown) it also states that the user agent should store the service worker state in case of a shut down. this implies in my oppinion that the service worker won't work in case the user agent shuts down. – gosua Mar 28 '17 at 07:50
-
@gosua Would you care to explain little bit and give a elaborate answer. – Jagajit Prusty Mar 28 '17 at 10:45
-
I couldn't find any more detailed information than these sentences in the specification. "the state must be stored after the user agent is about to shut down" sounds to me pretty much like that the service worker won't be there anymore if the user agent was shut down successfully. – gosua Mar 29 '17 at 12:58
Little offtopic but it is possible to write Chrome extension where background script can run if Chrome is allowed to run in the background (configurable in settings). It can also use GCM.

- 2,998
- 3
- 31
- 35
-
I interested to know the default behavior of Service worker. If we close chrome will service worker run? – Jagajit Prusty Sep 22 '16 at 10:33
-
I've tested it and in chrome Service Worker was running even if chrome was closed (but running in background). I could send a push and worker successfully showed a notification. – Martin Ždila Sep 23 '16 at 11:49
-
But I never seen a notification in chrome when it is closed. Once I open my chrome all push notification from different companies (viz. Facebook, Google) starts bombarding on my screen. so i assumed that service worker doesn't run when browser is closed – Jagajit Prusty Sep 24 '16 at 18:29
-
@PJagajitPrusty I've just found that there must be at least one extension installed with the `background` permission in Chrome for it to work. Then I see Chrome icon in system tray (Linux, Xfce). – Martin Ždila Sep 26 '16 at 07:24
In the context of receiving push messages on desktop, you will receive messages when the browser is running, i.e. has the marking underneath the icon.
This means the browser can have no windows open, and you'll still receive the push message in your service worker, because the browser in running in the background.
The only time a push won't be received is when the browser is completely closed, i.e. not running at all (no marking). The same applies for Windows, although it's a little trickier to determine whether or not Chrome is running in the background.
source https://web.dev/push-notifications-faq/#why-doesn't-push-work-when-the-browser-is-closed

- 1,219
- 1
- 15
- 17