tor-browser

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

partitioned-service-worker-nested-iframe-child.html (1864B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: Innermost nested iframe for partitioned service workers</title>
      3 <script src="./test-helpers.sub.js"></script>
      4 <script src="/common/get-host-info.sub.js"></script>
      5 <script src="./partitioned-utils.js"></script>
      6 
      7 <body>
      8 Innermost 1p iframe (A2) with 3p ancestor (A1-B-A2-A3): this iframe will
      9 register a service worker when it loads and then add its own iframe (A3) that
     10 will attempt to navigate to a url. ServiceWorker will intercept this navigation
     11 and resolve the ServiceWorker's internal Promise. When
     12 ThirdPartyStoragePartitioning is enabled, this iframe should be partitioned
     13 from the main frame and should not share a ServiceWorker.
     14 <script>
     15 
     16 async function onLoad() {
     17  // Set-up the ServiceWorker for this iframe, defined in:
     18  // service-workers/service-worker/resources/partitioned-utils.js
     19  await setupServiceWorker();
     20 
     21  // When the SW's iframe finishes it'll post a message. This forwards
     22  // it up to the middle-iframe.
     23  self.addEventListener('message', evt => {
     24      window.parent.postMessage(evt.data, '*');
     25  });
     26 
     27  // Now that we have set up the ServiceWorker, we need it to
     28  // intercept a navigation that will resolve its promise.
     29  // To do this, we create an additional iframe to send that
     30  // navigation request to resolve (`resolve.fakehtml`). If we're
     31  // partitioned then there shouldn't be a promise to resolve. Defined
     32  // in: service-workers/service-worker/resources/partitioned-storage-sw.js
     33  const resolve_frame_url = new URL('./partitioned-resolve.fakehtml?FromNestedFrame', self.location);
     34  const frame_resolve = await new Promise(resolve => {
     35    var frame = document.createElement('iframe');
     36    frame.src = resolve_frame_url;
     37    frame.onload = function() { resolve(frame); };
     38    document.body.appendChild(frame);
     39  });
     40 }
     41 
     42 self.addEventListener('load', onLoad);
     43 </script>
     44 </body>