Maxim Salnikov
@webmaxru
I want to have the possibility run some webapp code in the background
Developer Engagement Lead at Microsoft Norway
Server command
Time event
Other event?
Push?
Geofence?
Battery status?
Network status?
Generic schedule?
Periodic events
const registration = await navigator.serviceWorker.ready;
if ('periodicSync' in registration) {
try {
await registration.periodicSync.register('content-sync', {
// An interval of one day.
minInterval: 24 * 60 * 60 * 1000,
});
} catch (error) {
// Periodic background sync cannot be used.
}
}
self.addEventListener('periodicsync', (event) => {
if (event.tag === 'content-sync') {
// Think before you sync!
event.waitUntil(syncContent());
}
});
Maxim Salnikov
@webmaxru