tor-browser

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

sw.js (873B)


      1 // Copyright 2025 The Chromium Authors
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 const pause_conditions = {};
      5 async function pause(condition) {
      6  if (condition)
      7    await new Promise(resolve => {
      8      pause_conditions[condition] = resolve;
      9    });
     10 }
     11 
     12 function resume(condition) {
     13  const resolve = pause_conditions[condition];
     14  if (resolve) {
     15    resolve();
     16    delete pause_conditions[condition];
     17  }
     18 }
     19 
     20 onmessage = async (message) => {
     21  if ('resume' in message.data) {
     22    resume(message.data.resume);
     23  }
     24 };
     25 
     26 onfetch = async (event) => {
     27  const response = fetch(event.request);
     28  if (!event.request.url.includes('pause')) {
     29    event.respondWith(response);
     30    return;
     31  }
     32 
     33  event.respondWith(pause(new URL(event.request.url).searchParams.get('pause'))
     34                        .then(() => response));
     35 };