summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/resources/notification-sw.js
blob: e9b1e2b9ddff9ea8389dea8ca8f09ffe2bc5bd2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
self.addEventListener('install', e => e.waitUntil(skipWaiting()));
self.addEventListener('activate', e => e.waitUntil(clients.claim()));

self.addEventListener('message', async event => {
  const method = event.data;

  if (method === 'constructor') {
    try {
      new Notification('test');
    } catch (e) {
      event.source.postMessage(e.message);
    }
  } else if (method === 'showNotification') {
    try {
      await self.registration.showNotification('test', {body: 'test'});
    } catch (e) {
      event.source.postMessage(e.message);
    }
  }
});