Does service worker runs on background even if browser is closed?

20,252

Solution 1

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).

Solution 2

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.

Share:
20,252
Jagajit Prusty
Author by

Jagajit Prusty

Updated on April 19, 2020

Comments

  • Jagajit Prusty
    Jagajit Prusty about 4 years

    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.