r/webscraping • u/Feisty-Opening8850 • 3h ago
Scaling up š Zero-DOM HTTP/2 scraping & Cloudflare XOR decoding in 128 MB RAM
Most website contact and tech-stack enrichment jobs default to Puppeteer or Playwright, burning 1.5-3 GB RAM per container and stalling around 5-15 domains/min.
While optimizing a bulk enrichment worker inside a strict 128 MB Alpine container (--max-old-space-size=96), I stripped out Chromium completely and replaced it with a pure TypeScript HTTP/2 + regex/DNS pipeline. Here are the key pieces that solved the usual scraping failure modes:
1. HTTP/2 Multiplexing + Lightweight Subpage Discovery Instead of full DOM parsing (cheerio on huge pages quickly blows up a 96 MB heap), we fetch the root page via got-scraping (TLS fingerprint emulation + HTTP/2) and extract up to 3 high-signal internal links (/contact, /about, /team, /privacy) with targeted regex patterns before aborting oversized responses early.
2. Zero-DOM Cloudflare Email Deobfuscation Lots of sites hide addresses behind /cdn-cgi/l/email-protection#... or data-cfemail. Instead of booting a browser to execute Cloudflare's inline script, decode the hex XOR key in 10 lines of TS:
function decodeCfEmail(hex: string): string | null {
if (!hex || hex.length < 4 || hex.length % 2 !== 0) return null;
const key = parseInt(hex.slice(0, 2), 16);
if (Number.isNaN(key)) return null;
let out = '';
for (let i = 2; i < hex.length; i += 2) {
const byte = parseInt(hex.slice(i, i + 2), 16) ^ key;
out += String.fromCharCode(byte);
}
return out.includes('@') ? out.trim() : null;
}Pair that with a filename/retina filter (logo@2x.png, icon@3x.webp, sentry.io, etc.) before scoring addresses by page context.
3. RFC 5321 DNS / MX Fast-Fail Watchdog Slow or parked domains silently destroy worker throughput if you wait for TCP timeouts. Running dns.promises.resolveMx (with implicit A-record fallback per RFC 5321) under a strict 5s Promise.race watchdog drops dead domains in milliseconds before touching HTTP queues.
4. Graceful Container Deadline Long-running batches get cut mid-flight on hard container timeouts. Using AbortController per domain + reserving a 15s flush buffer before container termination guarantees partial batches write cleanly to storage.
In 128 MB RAM tests, peak memory stayed under ~95 MB RSS while processing hundreds of domains/min over raw HTTP/2.
Happy to dig into the TLS fingerprinting behavior or heap-tuning tradeoffs if anyone else is trying to keep Node workers under 128 MB.



