tor-browser

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

partitioned-service-worker-third-party-window.html (1050B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: 3P window for partitioned service workers</title>
      3 <script src="./test-helpers.sub.js"></script>
      4 <script src="/common/get-host-info.sub.js"></script>
      5 
      6 
      7 <body>
      8 This page should be opened as a third-party window. It then loads an iframe
      9 specified by the query parameter. Finally it forwards the postMessage from the
     10 iframe up to the opener (the test).
     11 
     12 <script>
     13 
     14 async function onLoad() {
     15  const message_promise = new Promise(resolve => {
     16    self.addEventListener('message', evt => {
     17      resolve(evt.data);
     18    });
     19  });
     20 
     21  const search_param = new URLSearchParams(window.location.search);
     22  const iframe_url = search_param.get('target');
     23 
     24  var frame = document.createElement('iframe');
     25  frame.src = iframe_url;
     26  frame.style.position = 'absolute';
     27  document.body.appendChild(frame);
     28 
     29 
     30  await message_promise.then(data => {
     31    // We're done, forward the message and clean up.
     32    window.opener.postMessage(data, '*');
     33 
     34    frame.remove();
     35  });
     36 }
     37 
     38 self.addEventListener('load', onLoad);
     39 
     40 </script>
     41 </body>