summaryrefslogtreecommitdiffstats
path: root/dom/serviceworkers/test/isolated/multi-e10s-update/file_multie10s_update.html
blob: d611b01b59a1b4603b535643328b9f01de584f4b (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
29
30
31
32
33
34
35
36
37
38
39
40
<html>
<body>
<script>

var bc = new BroadcastChannel('start');
bc.onmessage = function(e) {
  // This message is not for us.
  if (e.data != 'go') {
    return;
  }

  // It can happen that we don't have the registrations yet. Let's try with a
  // timeout.
  function proceed() {
    return navigator.serviceWorker.getRegistrations().then(regs => {
      if (!regs.length) {
        setTimeout(proceed, 200);
        return;
      }

      bc = new BroadcastChannel('result');
      regs[0].update().then(() => {
        bc.postMessage(0);
      }, () => {
        bc.postMessage(1);
      });

      // Tell the coordinating frame script that we've kicked off our update
      // call so that the SW script can be released once both instances of us
      // have triggered update() and 1 has failed.
      const blockingChannel = new BroadcastChannel('update');
      blockingChannel.postMessage(true);
    });
  }

  proceed();
}
</script>
</body>
</html>