blob: 5b0c791f0d5f2bf062e997b8ab9fee4c3010d574 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import {getOneShotSyncPromise, getPeriodicSyncPromise} from './background-sync-helper.js';
self.addEventListener('install', e => e.waitUntil(skipWaiting()));
self.addEventListener('activate', e => e.waitUntil(clients.claim()));
self.addEventListener('message', async e => {
const {method, isPeriodic} = e.data;
const promise = isPeriodic ?
getPeriodicSyncPromise(self.registration, method) :
getOneShotSyncPromise(self.registration, method);
const message =
await promise
.then(() => {
return `[background synnc ${method}] Unexpectedly started`;
})
.catch((e) => {
return e.message;
});
e.source.postMessage(message);
});
|