summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js
blob: a3d17b9c650adb5f889a51f1e73a4537a282161f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let promise_func = null;
let promise = new Promise(resolve => promise_func = resolve);

const SERVICE_WORKER_TEST_CHANNEL_NAME = 'service worker';
const bc3 = new BroadcastChannel(SERVICE_WORKER_TEST_CHANNEL_NAME);
bc3.onmessage = e => {
  bc3.postMessage('done');
  promise_func();
};
bc3.postMessage('from worker');

// Ensure that the worker stays alive for the duration of the test
self.addEventListener('install', evt => {
  evt.waitUntil(promise);
});