tor-browser

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

session-history-initiator.https.html (1938B)


      1 <!DOCTYPE html>
      2 <script src="/speculation-rules/prerender/resources/utils.js"></script>
      3 <script src="session-history-harness.js"></script>
      4 <body>
      5  <script>
      6    const urlParams = new URLSearchParams(window.location.search);
      7    const prerender = urlParams.get("prerender");
      8    const testName = urlParams.get("testName");
      9    const uid = urlParams.get("uid");
     10 
     11    const prerenderChannel = new PrerenderChannel(
     12      `prerender-channel-${testName}`, uid
     13    );
     14    const testChannel = new PrerenderChannel(`test-channel-${testName}`, uid);
     15 
     16    // Activate when a test sends a "activate" message.
     17    testChannel.addEventListener("message", (e) => {
     18      assert(e.data === "activate");
     19      window.location.href = `${prerender}?testName=${testName}&uid=${uid}`;
     20    });
     21 
     22    // Runs before and after the history manipulation in the prerender page to confirm
     23    // that the session history of the initiator page is not affected by any history
     24    // changes in the prerender page.
     25    function assertInitialHistoryState() {
     26      assert(history.length == 1, "Initial history length");
     27      assert(!history.state, "Initial history state");
     28    }
     29 
     30    async function startPrerenderingAndWaitTestResult() {
     31      const message = new Promise((resolve) => {
     32        prerenderChannel.addEventListener(
     33          "message",
     34          (e) => {
     35            resolve(e.data);
     36          },
     37          { once: true }
     38        );
     39      });
     40 
     41      assertInitialHistoryState();
     42 
     43      startPrerendering(`${prerender}?testName=${testName}&uid=${uid}`);
     44      const testResult = await message;
     45 
     46      assertInitialHistoryState();
     47 
     48      return testResult;
     49    }
     50 
     51    (async () => {
     52      try {
     53        testChannel.postMessage(await startPrerenderingAndWaitTestResult());
     54      } catch (e) {
     55        testChannel.postMessage("Failed: " + e.name + ": " + e.message);
     56      } finally {
     57        prerenderChannel.close();
     58      }
     59    })();
     60  </script>
     61 </body>