DOSAYGO Studio

dn: A Crystal Rune in the Web’s Faerie Realm

By Cris, April 15, 2025

In the web’s faerie realm, where each page glimmers like a fleeting spell, I crafted dn (DownloadNet)—an intercepting proxy to capture these enchantments and etch them into a crystal archive. This rune preserves web requests and responses as you browse, storing them locally for offline access, a hidden magic woven as naturally as faeries dance in a moonlit glade.

The heart of dn lies in its ability to intercept requests, craft a unique key, and serialize responses to disk. Using the browser’s DevTools protocol, it pauses each web request, capturing its essence before it fades. From the request’s method and URL, a key is forged—a rune to identify and store the response. Headers and content are then preserved as JSON, like faerie dust sealed in a crystal vial, ready for later discovery.

async function cacheRequest(pausedRequest) {
  const { requestId, request } = pausedRequest;
  const key = serializeRequestKey(request);  // Create key from method and URL
  if (Mode == 'save') {
    const response = await getResponseData(requestId);
    const responsePath = await saveResponseData(key, request.url, response);
    State.Cache.set(key, responsePath);  // Store the path to the saved response
  }
  send(`Fetch.continueRequest`, { requestId });
}

function serializeRequestKey(request) {
  const { url, method } = request;
  return `${method}${url}`;  // Simple key from method and URL
}

async function saveResponseData(key, url, response) {
  const fileName = `${await sha1(key)}.json`;
  const responsePath = Path.resolve(originDir, fileName);
  await Fs.promises.writeFile(responsePath, JSON.stringify(response, null, 2));
  return responsePath;
}

This code reveals dn’s magic: intercepting requests with `Fetch.requestPaused`, crafting a key from the method and URL, and serializing the response—headers and content—to disk as JSON. These steps form a radiant rune, preserving the web’s glow in a local archive, a crystal of memory shimmering with privacy and precision.

dn in action: a browser history search interface, set against a backdrop of a moonlit glade with glowing crystals and faeries

With dn, I wove a tapestry of innovation—request interception, key generation, and response serialization—transforming transient web pages into a lasting archive. It’s a testament to the quiet power of crystal runes, capturing the web’s faerie whispers and guarding them in a hidden realm, as eternal as a glade’s soft light.