tor-browser

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

fs-remove_dir.sub.html (1397B)


      1 <!doctype html>
      2 <html>
      3  <title>Remove dusty-dir-handle</title>
      4  <head>
      5    <script src="/resources/testharness.js"></script>
      6  </head>
      7  <body>
      8    <div id="log"></div>
      9    <script>
     10      const params = new URLSearchParams(window.location.search);
     11 
     12      const channelName = params.get("channel");
     13      if (!channelName) {
     14        // On irrecoverable errors, window is closed: parent should check this.
     15        window.close();
     16 
     17        throw new Error("Unknown channel name");
     18      }
     19 
     20      const opName = params.get("op");
     21      if (!opName || "remove" != opName) {
     22        // On irrecoverable errors, window is closed: parent should check this.
     23        window.close();
     24 
     25        throw new Error("Unknown operation name");
     26      }
     27 
     28      const channel = new BroadcastChannel(channelName);
     29      const dirHandleName = "dusty-dir-handle-" + channelName;
     30 
     31      channel.onmessage = async ev => {
     32        if (ev.data == "cleanup") {
     33          channel.postMessage("done");
     34        }
     35      };
     36 
     37      window.addEventListener("load", async () => {
     38        try {
     39          const rootDir = await navigator.storage.getDirectory();
     40 
     41          // Let's do some clean up!
     42          await rootDir.removeEntry(dirHandleName, { recursive: true });
     43 
     44          channel.postMessage("200 OK");
     45        } catch (err) {
     46          channel.postMessage(err.message);
     47        }
     48      });
     49    </script>
     50  </body>
     51 </html>