tor-browser

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

register-rewrite-worker.html (1093B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8"/>
      3 <script>
      4 async function onLoad() {
      5  const params = new URLSearchParams(self.location.search);
      6  const scope = self.origin + params.get('scopepath');
      7  const script = './fetch-rewrite-worker.js';
      8  const reg = await navigator.serviceWorker.register(script, { scope: scope });
      9  // In nested cases we may be impacted by partitioning or not depending on
     10  // the browser.  With partitioning we will be installing a new worker here,
     11  // but without partitioning the worker will already exist.  Handle both cases.
     12  if (reg.installing) {
     13    await new Promise(resolve => {
     14      const worker = reg.installing;
     15      worker.addEventListener('statechange', evt => {
     16        if (worker.state === 'activated') {
     17          resolve();
     18        }
     19      });
     20    });
     21    if (reg.navigationPreload) {
     22      await reg.navigationPreload.enable();
     23    }
     24  }
     25  if (window.opener) {
     26    window.opener.postMessage({ type: 'SW-REGISTERED' }, '*');
     27  } else {
     28    window.top.postMessage({ type: 'SW-REGISTERED' }, '*');
     29  }
     30 }
     31 self.addEventListener('load', onLoad);
     32 </script>