web-request returns an internal error for any text/html response that isn’t HTML, including every HTML page over 1 MB
Summary
When a response is labelled text/html but its body isn't HTML, web-request fails with web-request post-processing error: Cannot destructure property 'firstElementChild' of 'documentElement' as it is null. This happens for block pages (e.g. a 403 "Access denied"), empty bodies, plain text served as HTML, and every HTML page over 1 MB, because the body of an oversized response is replaced with a size note that is then parsed as HTML.
The agent gets an internal error instead of the status, the text, or a clear "too large" message, so it can't tell a blocked or oversized page from a tool fault, or recover by itself.
Environment
- App: Flow (internal editorial app built on Agent-Native)
@agent-native/core:0.207.0(theweb-requestcode is unchanged since0.205.0)
Steps and observed behavior
Seen in our app: asking the agent to read https://en.wikipedia.org/wiki/United_States (2,980,114 bytes of HTML) returns:
Error running web-request: web-request post-processing error: Cannot destructure property 'firstElementChild' of 'documentElement' as it is null. (errorCode: web_request_processing_failed)
To isolate it, we called the real tool from @agent-native/core/fetch-tool with fetch stubbed to return each response below. A public IP literal was used as the URL so the SSRF check passes without DNS.
| Response | Result |
|---|---|
Article page, text/html, 0.95 MB |
✅ Article text |
Same page, 1.05 MB (with or without content-length) |
❌ post-processing error: Cannot destructure property 'firstElementChild'… (web_request_processing_failed) |
| Long article, all text, 1.02 MB | ❌ Same error |
403, text/html, body "Access denied" |
❌ Same error (http_403) |
403, text/html, empty body |
❌ Same error (http_403) |
200, text/html, plain-text body |
❌ Same error |
200, text/html, empty body |
❌ Same error |
200, text/plain |
✅ Text |
| PDF or JSON over 1 MB | ✅ (response too large - 1200009 bytes, max 1048576) |
Minimal reproduction
import { createFetchToolEntry } from "@agent-native/core/fetch-tool";
const tool = createFetchToolEntry()["web-request"];
globalThis.fetch = async () =>
new Response("Access denied", { status: 403, headers: { "content-type": "text/html" } });
await tool.run({ url: "https://93.184.215.14/" });
// throws: web-request post-processing error: Cannot destructure property 'firstElementChild' of 'documentElement' as it is null.
Expected behavior
- A response that isn't parseable HTML returns its status and raw text, e.g.
HTTP 403 Forbidden+Access denied, or an explicit empty-body message. - An HTML page over the size limit returns the same clear note that PDFs and JSON already get (
response too large …).
Impact
Many sites send block pages or large HTML, so research tasks hit this often. The agent can't distinguish "blocked", "empty" and "too large" from each other or from a bug.
A clear message would let the agent recover by itself. Retrying with saveToFile plus search works on the same Wikipedia page, but today the agent only knows to do that because we've written the error code into our system prompt.
Relevant code observations in 0.207.0
readResponseTextWithLimit(packages/core/src/extensions/proxy-security.ts) replaces a body overMAX_EXTENSION_PROXY_RESPONSE_SIZE(1 MiB) with the text(response too large - N bytes, max 1048576)(or(response truncated - …)withoutcontent-length). The original bytes are discarded in both cases.fetch-tool.tspasses that text, with the originaltext/htmlcontent type, toprocessWebContent(web-content.ts). HTML extraction then throws because the parsed document has nodocumentElement, and the catch rethrows it asweb-request post-processing error: ….- Non-HTML content types skip HTML extraction, which is why PDFs and JSON over 1 MB get the clear note.
Possible fix
- If the body has no parseable
documentElement, or is the size note, return it as raw text (with the status) instead of throwing.
I'll pick this up — handle the null documentElement case and return the status/text or a clear too-large note instead. PR in a day or two.