tor-browser

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

partitioned-service-worker-third-party-iframe-getRegistrations.html (1404B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: 3P 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  This iframe will register a service worker when it loads and then will use
      9  getRegistrations to get a handle to the SW. It will then postMessage to the
     10  SW to retrieve the SW's ID. This iframe will then forward that message up,
     11  eventually, to the test.
     12  <script>
     13 
     14    async function onLoad() {
     15      const scope = './partitioned-'
     16      const absoluteScope = new URL(scope, window.location).href;
     17 
     18      await setupServiceWorker();
     19 
     20      // Once the SW sends us its ID, forward it up to the window.
     21      navigator.serviceWorker.addEventListener('message', evt => {
     22        window.parent.postMessage(evt.data, '*');
     23      });
     24 
     25      // Now get the SW with getRegistrations.
     26      const retrieved_registrations =
     27        await navigator.serviceWorker.getRegistrations();
     28 
     29      // It's possible that other tests have left behind other service workers.
     30      // This steps filters those other SWs out.
     31      const filtered_registrations =
     32        retrieved_registrations.filter(reg => reg.scope == absoluteScope);
     33 
     34      filtered_registrations[0].active.postMessage({type: "get-id"});
     35 
     36    }
     37 
     38    self.addEventListener('load', onLoad);
     39  </script>
     40 </body>