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?
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.')});
});
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With