summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/resources/serviceWorker-dedicated-worker-inner.html
blob: 02f28bd82ea2e0c6756af46d47fd1993fe27e4e2 (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
<!DOCTYPE html>
<script src="utils.js"></script>

<body>
  <script type="module">
    // Ask the worker to do a fetch request that will be handled by the service
    // worker via postMessage.
    const checkIfServiceWorkerCanControlWebWorker = async () => {
      const dedicated_worker = new Worker('serviceWorker-dedicated-worker.js');
      return new Promise((resolve, reject) => {
        dedicated_worker.addEventListener('message', e => {
          resolve(e.data)
        });
        dedicated_worker.postMessage('fetch');
      })
    }

    const [key] = parseKeylist();
    const url = new URL(location.href);
    if (url.searchParams.get('useServiceWorkerInFencedFrame')) {
      await navigator.serviceWorker.register('serviceWorker-dedicated-worker-sw.js');
      await navigator.serviceWorker.ready;
    }

    const result = await checkIfServiceWorkerCanControlWebWorker();
    writeValueToServer(key, result);
  </script>
</body>