tor-browser

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

worker.js (1215B)


      1 addEventListener("install", function (evt) {
      2  evt.waitUntil(self.skipWaiting());
      3 });
      4 
      5 addEventListener("activate", function (evt) {
      6  // We claim the current clients in order to ensure that we have an
      7  // active client when we call unregister in the fetch handler.  Otherwise
      8  // the unregister() can kill the current worker before returning a
      9  // response.
     10  evt.waitUntil(clients.claim());
     11 });
     12 
     13 addEventListener("fetch", function (evt) {
     14  // This worker may live long enough to receive a fetch event from the next
     15  // test.  Just pass such requests through to the network.
     16  if (!evt.request.url.includes("fake_download")) {
     17    return;
     18  }
     19 
     20  // We should only get a single download fetch event. Automatically unregister.
     21  evt.respondWith(
     22    registration.unregister().then(function () {
     23      return new Response("service worker generated download", {
     24        headers: {
     25          "Content-Disposition": 'attachment; filename="fake_download.bin"',
     26          // Prevent the default text editor from being launched
     27          "Content-Type": "application/octet-stream",
     28          // fake encoding header that should have no effect
     29          "Content-Encoding": "gzip",
     30        },
     31      });
     32    })
     33  );
     34 });