Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Periodic background sync support with service workers

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?

like image 998
dukitieneflow Avatar asked Mar 01 '18 16:03

dukitieneflow


2 Answers

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

like image 195
bhanu Avatar answered Oct 01 '22 12:10

bhanu


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/

like image 38
Josh Avatar answered Oct 01 '22 13:10

Josh