// Network layer for the page-reading and search tools. Order, cheapest and most private first: // 1. direct fetch() the visitor's own (residential) IP; works only when the site sends CORS headers (APIs, Wikipedia, ...) // 2. libcurl.js libcurl compiled to WebAssembly: it speaks TLS itself and tunnels TCP over a public WISP relay (a WebSocket // proxy), so it needs no CORS permission, returns the raw HTML and may set any header, User-Agent included. // Traffic then leaves from the relay's IP, which is why it only runs when step 1 failed. The TLS handshake // is inside the WebAssembly, so a relay sees which host is contacted, not the content. // (Jina Reader, defuddle.md and the Wayback Machine are tried by tools.js when both of these fail.) // The retry policy follows sharp-search (github.com/Belluxx/sharp-search, MIT): Safari-like request first; on 202/401/403/405/429 or a // bot-check page, retry as the link-preview crawlers many sites let through; keep whichever answer has the most text. export const SAFARI_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15'; export const BOT_UAS = ['facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)', 'Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)', 'Twitterbot/1.0']; const REFUSALS = new Set([202, 401, 403, 405, 429]); export const CHALLENGE = /(id="anubis_version"|anubis_challenge|making sure you(?:'|')re not a bot|_incapsula_resource|ak_bmsc|attention required! \| cloudflare|cf-browser-verification|just a moment\.\.\.|challenge-platform|captcha-delivery\.com|px-captcha)/i; // Public WISP relays (volunteer-run). Shuffled once per visit so no single relay takes everyone's traffic. const RELAYS = ['wss://wisp.mercurywork.shop/', 'wss://anura.pro/', 'wss://fern.best/', 'wss://wisp.terbiumon.top/wisp/', 'wss://tomp.app/wisp', 'wss://nebulaservices.org/wisp/', 'wss://relay.widgetry.org/', 'wss://linuxontab-net.fly.dev/wisp'].sort(() => Math.random() - 0.5); let relayAt = 0; const relay = () => RELAYS[relayAt % RELAYS.length]; function hopRelay() { // a different relay is a different exit IP relayAt++; try { lc().set_websocket(relay()); return true; } catch { return false; } } const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); const aborted = (signal) => { if (signal?.aborted) throw new DOMException('Stopped', 'AbortError'); }; const withTimeout = (signal, ms) => { // AbortSignal.any is not in every browser yet const c = new AbortController(), t = setTimeout(() => c.abort(), ms), on = () => c.abort(); signal?.addEventListener('abort', on, { once: true }); return { signal: c.signal, done: () => { clearTimeout(t); signal?.removeEventListener('abort', on); } }; }; // ------------------------------------------------------------------------------------------ libcurl.js loader let curlReady = null, curlDead = false; const lc = () => (typeof libcurl !== 'undefined' ? libcurl : null); // libcurl.js declares a top-level `const libcurl`: it is a global binding, not a window property export function ensureLibcurl() { // the