Periodic background sync support with service workers
Asked Answered
H

2

6

I'd like to periodically ping a server using service workers.

At this current moment, Chrome supports "background syncing", but it cannot be used at situations like this, because it could be abused to mine crypto, for example.

I have read there were plans in 2015 to add periodic background syncing to Chrome - this would require user's permission, but would be very useful for some cases.

However, I cannot seem to find any actual documentation about it, or if it's even supported, since Chrome doesn't have "periodic background sync" or similar in the list of website permissions.

In a nutshell - is periodic background sync working on Chrome already? If so, is there any documentation on it?

Hara answered 1/3, 2018 at 16:9 Comment(0)
Q
2

According to Chrome Status, Periodic Background Sync is being released with Chrome version 80

https://www.chromestatus.com/feature/5689383275462656

More info here https://web.dev/periodic-background-sync/

Qualified answered 4/2, 2020 at 22:59 Comment(0)
F
6

I was experimenting with chrome background sync lately. Currently it doesn't seem to support periodic sync. I tried to use code snippet from the spec here. But it didn't work. See the screenshot below for understanding.

  navigator.serviceWorker.register("/sw.js");

  navigator.serviceWorker.ready.then(function(swRegistration) {
    console.log(swRegistration);
    console.log(typeof(swRegistration))
    swRegistration.periodicSync.register({
      tag: 'myFirstSync',
      minPeriod: 3000,
      powerState: 'avoid-draining',
      networkState: 'avoid-cellular' 
    }).then((periodicSyncReg) => {console.log('sucess')}, () => {console.log('some error occured.')});
  });

enter image description here

Footsie answered 10/5, 2018 at 4:38 Comment(0)
Q
2

According to Chrome Status, Periodic Background Sync is being released with Chrome version 80

https://www.chromestatus.com/feature/5689383275462656

More info here https://web.dev/periodic-background-sync/

Qualified answered 4/2, 2020 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.