summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/cross-origin-embedder-policy/resources/navigate-none.sub.html
blob: f1437ba90a0b684c3b3f2e2472c9837c70d0cecb (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
<!doctype html>
<script>
  let current = new URL(window.location.href);
  let navigateTo = current.searchParams.get("to");
  let channelName = current.searchParams.get("channelName");
  let postMessageTo = current.searchParams.get("postMessageTo");
  current.search = "";
  if (navigateTo) {
    let next = new URL(navigateTo, current);
    window.addEventListener("load", () => {
      window.location.href = next.href;
    });
  }

  let target = undefined;
  if (channelName) {
    target = new BroadcastChannel(channelName);
  } else if (postMessageTo) {
    target = eval(postMessageTo);
  }

  if (target) {
    // Broadcast only once the DOM is loaded, so that the caller can
    // access reliably this document's body.
    window.addEventListener("DOMContentLoaded", () =>
      target.postMessage("loaded", "*"));

    // The page can also be restored from the back-forward cache:
    window.addEventListener('pageshow', function(event) {
      if (event.persisted)
        target.postMessage("loaded", "*");
    });
  }
</script>