0

Can i make a service worker, that run in background and poll the server at specific interval and return response or show notification(push notification) when chrome browser is closed. I am working for a website, that ask for service worker permission and sync the request at specific intervals in background based on request received from server show the notification.

Edit 1: As of now i can see chrome is working on this, but the post is too old Dec 2015. They have written it that they will introduce it in first half of 2016. It is not available till yet.

We're aiming to ship background sync to a stable version of Chrome in the first half of 2016. But we’re also working on a variant, “periodic background sync”. This will allow you to request a “periodicsync” event restricted by time interval, battery state and network state. This would require user permission, of course, but it will also be down to the will of the browser for when and how often these events fire. E.g., a news site could request to sync every hour, but the browser may know you only read that site at 07:00, so the sync would fire daily at 06:50. This idea is a little further off than one-off syncing, but it’s coming.

karman
  • 346
  • 3
  • 20
  • With pure javascript it's impossible, every script stops when the browser stops – Bálint Dec 30 '16 at 10:08
  • @Bálint then how cnn.com is pushing the notifications – karman Dec 30 '16 at 10:10
  • They do it when Chrome is running. You simply can't do it when the user closes the browse – Bálint Dec 30 '16 at 10:16
  • https://developers.google.com/web/fundamentals/engage-and-retain/push-notifications/ – Bálint Dec 30 '16 at 10:17
  • @Bálint Yes, i had looked at it, its just push notification. I want to trigger sync event at regular intervals. So it polls the server(when browser closed) and get me new information available. – karman Dec 30 '16 at 10:20
  • 1
    Found this.. https://developer.mozilla.org/en-US/docs/Web/API/PeriodicSyncManager. but it is not available yet for any web browser – karman Dec 30 '16 at 12:11
  • That still doesn't work when the browser is closed, because it runs in a WebWorker. Please understand, **JavaScript doesn't run natively, it needs a browser, no matter what you do, when it closes, everything stops**. The only thing you can do is to literally install a virus-like program on the user's computer, but then we can't help you, and it's also illegal – Bálint Dec 30 '16 at 12:45

0 Answers0