tor-browser

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

sw_reroute.js (1300B)


      1 var gRegistration;
      2 var iframe;
      3 
      4 function testScript(script) {
      5  var mode = location.href.includes("http2") ? "?mode=http2&" : "?";
      6  var scope = "./reroute.html" + mode + "script=" + script.replace(".js", "");
      7  function setupSW(registration) {
      8    gRegistration = registration;
      9 
     10    iframe = document.createElement("iframe");
     11    iframe.src = scope;
     12    document.body.appendChild(iframe);
     13  }
     14 
     15  SpecialPowers.pushPrefEnv(
     16    {
     17      set: [
     18        ["dom.serviceWorkers.enabled", true],
     19        ["dom.serviceWorkers.testing.enabled", true],
     20        ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     21        ["dom.serviceWorkers.idle_timeout", 60000],
     22      ],
     23    },
     24    function () {
     25      var scriptURL = location.href.includes("sw_empty_reroute.html")
     26        ? "empty.js"
     27        : "reroute.js";
     28      if (location.href.includes("http2")) {
     29        scriptURL += "?mode=http2";
     30      }
     31      navigator.serviceWorker
     32        .register(scriptURL, { scope })
     33        .then(swr => waitForState(swr.installing, "activated", swr))
     34        .then(setupSW);
     35    }
     36  );
     37 }
     38 
     39 function finishTest() {
     40  iframe.remove();
     41  gRegistration.unregister().then(SimpleTest.finish, function (e) {
     42    dump("unregistration failed: " + e + "\n");
     43    SimpleTest.finish();
     44  });
     45 }
     46 
     47 SimpleTest.waitForExplicitFinish();