tor-browser

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

send-beacon.https.html (2149B)


      1 <!DOCTYPE html>
      2 <title>Same-origin prerendering: sendBeacon</title>
      3 <meta name="variant" content="?target_hint=_self">
      4 <meta name="variant" content="?target_hint=_blank">
      5 <meta name="timeout" content="long">
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="/common/utils.js"></script>
      9 <script src="/common/dispatcher/dispatcher.js"></script>
     10 <script src="../resources/utils.js"></script>
     11 <script src="resources/utils.js"></script>
     12 <script>
     13 setup(() => assertSpeculationRulesIsSupported());
     14 
     15 promise_test(async t => {
     16  const STORE_URL = '/speculation-rules/prerender/resources/key-value-store.py';
     17 
     18  // Create a prerendered page.
     19  const rule_extras = {'target_hint': getTargetHint()};
     20  const {exec, activate} = await create_prerendered_page(
     21      t, undefined, undefined, rule_extras);
     22 
     23  // This test will send 3 beacons. Each beacon will be stored with these keys
     24  // on the server.
     25  const keys = [token(), token(), token()];
     26 
     27  // Ask the prerendered page to send beacons during prerendering and
     28  // prerenderingchange.
     29  await exec(async (store_url, keys) => {
     30    const url1 = `${store_url}?key=${keys[0]}&value=during-prerendering`;
     31    navigator.sendBeacon(url1);
     32 
     33    document.onprerenderingchange = _ => {
     34      const url2 = `${store_url}?key=${keys[1]}&value=onprerenderingchange`;
     35      navigator.sendBeacon(url2);
     36    };
     37  }, [STORE_URL, keys]);
     38 
     39  // Wait for the beacon sent during prerendering.
     40  assert_equals(await nextValueFromServer(keys[0]), 'during-prerendering');
     41 
     42  await activate();
     43 
     44  // Wait for the beacon sent during the prerenderingchange event.
     45  assert_equals(await nextValueFromServer(keys[1]), 'onprerenderingchange');
     46 
     47  // Ask the activated page to send a beacon.
     48  await exec(async (store_url, keys) => {
     49    const url3 = `${store_url}?key=${keys[2]}&value=after-activation`;
     50    navigator.sendBeacon(url3);
     51  }, [STORE_URL, keys]);
     52 
     53  // Wait for the beacon sent after activation.
     54  assert_equals(await nextValueFromServer(keys[2]), 'after-activation');
     55 }, 'Prerendering page should be able to send beacons');
     56 </script>
     57 <body>
     58 </body>