blob: c2759d9630ea309b7ab2df65691df339a75c2d62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
self.addEventListener('install', e => e.waitUntil(skipWaiting()));
self.addEventListener('activate', e => e.waitUntil(clients.claim()));
self.addEventListener('message', async event => {
const method = event.data;
const {index} = self.registration;
const id = 'fenced-frame-id-sw';
let promise;
if (method === 'add') {
promise = index.add({
id,
title: 'same title',
description: 'same description',
url: 'resources/'
});
} else if (method === 'delete') {
promise = index.delete(id);
} else if (method === 'getAll') {
promise = index.getAll();
} else {
promise = Promise.resolve();
}
const message = await promise.then(() => 'success').catch(e => e.message);
event.source.postMessage(message);
});
|