summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/support/prefetch-with-csp.html
blob: 8185a3abee8d9d9c256f3e150496ab748823bcb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html>
  <html>
    <head>
      <link id="prefetch" rel="prefetch" href="pass.png">
    </head>
    <body>
      <script>
        const bc = new BroadcastChannel(new URLSearchParams(location.search).get("uid"));
        document.getElementById("prefetch").addEventListener("error", e => bc.postMessage(false));
        const observer = new PerformanceObserver(entries => {
          const found = entries.getEntriesByName(new URL("pass.png", location.href).href);
          if (found.length)
            bc.postMessage(found[0].encodedBodySize > 0);
        });
        observer.observe({entryTypes: ["resource"]});
      </script>
    </body>
  </html>