Handle bot-blocked pages honestly: fetch fallback, degradation flags, thin threshold

- renderer: plain-fetch escalation when the browser render is blocked (4xx)
  or fails — some sites 403 automated browsers but serve plain HTTP clients
- orchestrator: blocked (>=400), empty, and thin results now appear in
  failed_urls and the degraded trace list instead of passing silently;
  blocked/thin results are never cached
- extractor: thin threshold raised to 500 chars (env: MIN_TEXT_CHARS) so
  block/challenge interstitials are flagged instead of passing as content

Outcome on TechPowerUp (fingerprints Chromium AND Firefox, JS-challenges
plain clients): still blocked — accepted per PRD §9 — but results are now
flagged thin/degraded so the calling LLM knows to rely on other sources.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
User 2026-07-06 00:12:36 -07:00
parent 4f3dc39088
commit 4bcbe8daff
3 changed files with 49 additions and 2 deletions

View file

@ -40,6 +40,30 @@ app.get("/health", async (req, res) => {
});
});
// Some sites (e.g. TechPowerUp) fingerprint and 403 automated browsers while
// serving plain HTTP clients normally. When the browser render is blocked or
// fails, escalate to a plain fetch — server-rendered pages still extract fine.
async function plainFetch(url, timeoutMs) {
const resp = await fetch(url, {
headers: {
"User-Agent":
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9",
},
redirect: "follow",
signal: AbortSignal.timeout(timeoutMs),
});
const html = await resp.text();
return {
html,
status: resp.status,
final_url: resp.url,
rendered_at: new Date().toISOString(),
via: "fetch",
};
}
app.post("/render", async (req, res) => {
const { url, wait_policy, timeout_ms, bypass_cache } = req.body ?? {};
if (!url || typeof url !== "string" || !/^https?:\/\//i.test(url)) {
@ -70,6 +94,18 @@ app.post("/render", async (req, res) => {
if (attempt < RETRIES) log("warn", "render retry", { url, attempt: attempt + 1 });
}
}
if (result && !result.via) result.via = "browser";
if (!result || (result.status && result.status >= 400)) {
try {
const fetched = await plainFetch(url, timeout_ms ?? TIMEOUT_MS);
if (fetched.status < 400 && fetched.html) {
log("info", "plain-fetch fallback succeeded", { url, browser_status: result?.status ?? null });
result = fetched;
}
} catch (err) {
log("warn", "plain-fetch fallback failed", { url, error: String(err.message) });
}
}
if (!result) throw lastErr;
await cache.set(cacheKey, JSON.stringify(result), CACHE_TTL);
res.json({ ...result, cache: "miss" });