tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

target_configuration_test_doc.sjs (2783B)


      1 "use strict";
      2 
      3 function handleRequest(request, response) {
      4   response.setHeader("Content-Type", "html", false);
      5 
      6   // Check the params and set the cross-origin-opener policy headers if needed
      7   const query = new URLSearchParams(request.queryString);
      8   if (query.get("crossOriginIsolated") === "true") {
      9     response.setHeader("Cross-Origin-Opener-Policy", "same-origin", false);
     10   }
     11 
     12   // We always want the iframe to have a different host from the top-level document.
     13   const iframeHost =
     14     request.host === "example.com" ? "example.org" : "example.com";
     15   const iframeOrigin = `${request.scheme}://${iframeHost}`;
     16 
     17   const IFRAME_HTML = `
     18     <!doctype html>
     19   <html>
     20     <head>
     21       <meta charset=utf8>
     22       <script>
     23         globalThis.initialMatchesPrefersDarkColorScheme =
     24           window.matchMedia("(prefers-color-scheme: dark)").matches;
     25         globalThis.initialMatchesCoarsePointer =
     26           window.matchMedia("(pointer: coarse)").matches;
     27         globalThis.initialDevicePixelRatio = window.devicePixelRatio;
     28         globalThis.initialUserAgent = navigator.userAgent;
     29       </script>
     30       <style>
     31         html { background: cyan;}
     32 
     33         button {
     34           font-size: 2em;
     35           padding-inline: 1em;
     36         }
     37 
     38         @media (prefers-color-scheme: dark) {
     39           html {background: darkred;}
     40         }
     41 
     42       </style>
     43     </head>
     44     <body>
     45       <h1>Iframe</h1>
     46       <button>Target</button>
     47     </body>
     48   </html>`;
     49 
     50   const HTML = `
     51   <!doctype html>
     52   <html>
     53     <head>
     54       <meta charset=utf8>
     55       <title>test</title>
     56       <script type="application/javascript">
     57         "use strict";
     58 
     59         /*
     60          * Store the result of dark color-scheme match very early in the document loading process
     61          * so we can assert in tests that the simulation starts early enough.
     62          */
     63         globalThis.initialMatchesPrefersDarkColorScheme =
     64           window.matchMedia("(prefers-color-scheme: dark)").matches;
     65         globalThis.initialMatchesCoarsePointer =
     66           window.matchMedia("(pointer: coarse)").matches;
     67         globalThis.initialDevicePixelRatio = window.devicePixelRatio
     68         globalThis.initialUserAgent = navigator.userAgent;
     69 
     70 
     71       </script>
     72       <style>
     73         iframe {
     74           display: block;
     75           margin-top: 1em;
     76         }
     77 
     78         button {
     79           font-size: 2em;
     80           padding-inline: 1em;
     81         }
     82 
     83         @media (prefers-color-scheme: dark) {
     84           html {
     85             background-color: darkblue;
     86           }
     87         }
     88       </style>
     89     </head>
     90     <body>
     91       <h1>Test color-scheme simulation</h1>
     92       <button>Target</button>
     93       <iframe src='${iframeOrigin}/document-builder.sjs?html=${encodeURI(
     94         IFRAME_HTML
     95       )}'></iframe>
     96     </body>
     97   </html>`;
     98 
     99   response.write(HTML);
    100 }