tor-browser

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

sandbox-iframe.html (1846B)


      1 <!DOCTYPE html>
      2 <script src="/common/utils.js"></script>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/get-host-info.sub.js"></script>
      6 <script src="/speculation-rules/prerender/resources/utils.js"></script>
      7 <script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script>
      8 <body>
      9 <script>
     10 
     11 async function main() {
     12  // Start loading a sandbox iframe, which is treated as cross-origin iframe.
     13  // The iframe messages us with the value of its document.prerendering,
     14  // which should be false since load is delayed until after activation.
     15  const sandboxIframe = document.createElement('iframe');
     16  sandboxIframe.sandbox = 'allow-scripts';
     17 
     18  const gotMessage = new Promise((resolve, reject) => {
     19    window.addEventListener('message', (e) => {
     20     if (e.data === 'document.prerendering: false')
     21       resolve();
     22     else
     23       reject('bad message: ' + e.data);
     24    });
     25  });
     26 
     27  sandboxIframe.src = 'post-message-prerendering-completion-notification.html';
     28  document.body.appendChild(sandboxIframe);
     29 
     30  // To give the test a chance to fail by giving enough time if it loads the
     31  // cross-origin iframe instead of deferring, wait for a same-origin iframe to
     32  // load before proceeding with the test.
     33  await createFrame('empty.html');
     34 
     35  // Start the event collector to trigger activation.
     36  const prerenderEventCollector = new PrerenderEventCollector();
     37  prerenderEventCollector.start(gotMessage, 'iframe loaded');
     38 }
     39 
     40 // The main test page (prerender/sandbox-iframe.html) loads the initiator
     41 // page, then the initiator page will prerender itself with the
     42 // `prerendering` parameter.
     43 const params = new URLSearchParams(location.search);
     44 if (!params.has('prerendering')) {
     45  loadInitiatorPage();
     46 } else {
     47  main();
     48 }
     49 </script>
     50 </body>