summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive/test/browser/doc_with_remote_iframe_and_isolated_cross_origin_capabilities.sjs
blob: ba53928bed16332582160eb5bab3c0e18d5818dd (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
41
42
43
44
45
46
47
48
49
50
51
"use strict";

function handleRequest(request, response) {
  response.setHeader("Content-Type", "html", false);

  // Check the params and set the cross-origin-opener policy headers if needed
  const query = new URLSearchParams(request.queryString);
  if (query.get("crossOriginIsolated") === "true") {
    response.setHeader("Cross-Origin-Opener-Policy", "same-origin", false);
  }

  // We always want the iframe to have a different host from the top-level document.
  const iframeHost =
    request.host === "example.com" ? "example.org" : "example.com";
  const iframeOrigin = `${request.scheme}://${iframeHost}`;

  const IFRAME_HTML = `
    <!doctype html>
  <html>
    <head>
      <meta charset=utf8>
      <script>
        globalThis.initialOrientationAngle = screen.orientation.angle;
        globalThis.initialOrientationType = screen.orientation.type;
      </script>
    </head>
    <body>
      <h1>Iframe</h1>
    </body>
  </html>`;

  const HTML = `
  <!doctype html>
  <html>
    <head>
      <script>
        globalThis.initialOrientationAngle = screen.orientation.angle;
        globalThis.initialOrientationType = screen.orientation.type;
      </script>
      <meta charset=utf8>
    </head>
    <body>
      <h1>Top-level document</h1>
      <iframe src='${iframeOrigin}/document-builder.sjs?html=${encodeURI(
    IFRAME_HTML
  )}'></iframe>
    </body>
  </html>`;

  response.write(HTML);
}