tor-browser

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

file_broadcast_currenturi_onload.html (2093B)


      1 <!doctype html>
      2 <body>
      3 <script>
      4 
      5 const url = new URL(location.href);
      6 
      7 // Create a popup to broadcast the load's completion to the test document.
      8 //
      9 // NOTE: We're using a popup to ensure that the new document has the same origin
     10 // (http://mochi.test:8888/) as the original test document, so that we can use a
     11 // BroadcastChannel to communicate with the test page. We can't use an iframe as
     12 // the mixed content blocker will prevent embedding this URL in https://
     13 // documents.
     14 function sendPayload(payload) {
     15  let broadcastURL = new URL(url.pathname, "http://mochi.test:8888/");
     16  broadcastURL.search = "?payload=" + encodeURIComponent(JSON.stringify(payload));
     17  window.open(broadcastURL.href);
     18 }
     19 
     20 async function getURIs() {
     21  // Run the test and fetch the relevant information.
     22  const browsingContext = SpecialPowers.wrap(window).browsingContext;
     23  let [docURI, curURI] = await SpecialPowers.spawnChrome(
     24    [browsingContext.id], async id => {
     25      let bc = BrowsingContext.get(id);
     26      return [
     27        bc.currentWindowGlobal.documentURI.spec,
     28        bc.currentURI.spec,
     29      ];
     30    }
     31  );
     32  return { location: location.href, docURI, curURI };
     33 }
     34 
     35 addEventListener("load", async () => {
     36  // If a payload parameter was included, just send the message.
     37  const payloadStr = url.searchParams.get("payload");
     38  if (payloadStr) {
     39    const chan = new BroadcastChannel("test_broadcast_onload");
     40    chan.postMessage(JSON.parse(payloadStr));
     41    window.close();
     42    return;
     43  }
     44 
     45  // collect the initial set of URIs
     46  const result1 = await getURIs();
     47 
     48  const pushstateURL = new URL("after_pushstate", url.href);
     49  history.pushState({}, "After PushState!", pushstateURL.href);
     50  await new Promise(resolve => setTimeout(resolve, 0));
     51 
     52  // Collect the set of URIs after pushstate
     53  const result2 = await getURIs();
     54 
     55  window.location.hash = "#after_hashchange";
     56  await new Promise(resolve => setTimeout(resolve, 0));
     57 
     58  // Collect the set of URIs after a hash change
     59  const result3 = await getURIs();
     60 
     61  sendPayload([result1, result2, result3]);
     62  window.close();
     63 });
     64 </script>
     65 </body>