Open wklm opened 8 years ago
I don't believe that periodic sync is implemented in any browser. Chrome has implemented one-shot sync, as defined in https://wicg.github.io/BackgroundSync/spec/. I believe that Mozilla is implementing one-shot as well.
@jkarlin background sync is marked as enabled in chrome 49 (https://www.chromestatus.com/feature/6170807885627392) Could you please suggest me how can I implement it in my app? Are there any good tutorials around?
What's implemented is the background sync specification, which currently only includes one-shot syncs.
The closest thing to a tutorial that I'm aware of is @jakearchibald 's article. There is also a demo.
@jkarlin thank you :+1:
Hi,
I've got a problem with requesting a periodic sync. Error message is:
Uncaught (in promise) TypeError: Cannot read property 'register' of undefined(…)
and my registration object looks like this:
ServiceWorkerRegistration {installing: null, waiting: null, active: ServiceWorker, scope: "http://localhost:3000/", onupdatefound: null…}
So it has no requested field "periodicSync"
this is my code:
if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw', { scope: '/' }); navigator.serviceWorker.ready.then(function(registration) { console.log(registration) registration.periodicSync.register({ tag: 'get-latest-news', // default: '' minPeriod: 1000, // default: 0 powerState: 'avoid-draining', // default: 'auto' networkState: 'avoid-cellular' // default: 'online' }).then(function(periodicSyncReg) { console.log("success"); }, function() { console.log("failure"); }) }); }
What am I doing wrong?