Repository navigation
Description
Bug Description
When the LLM uses the browser_console tool and its injected JavaScript returns a raw DOM Node or NodeList (e.g., return document.body), it causes a fatal CDP serialization crash instead of returning a graceful tool error. Proposed Fix: Update _browser_eval in tools/browser_tool.py to wrap the incoming expression in an IIFE that explicitly checks if the returned result is an instance of Node or Window. If it is, it should return a clean string like "TOOL_ERROR: Extract primitive values instead" to guide the LLM back on track.
Proposed Fix (Tested Locally): In tools/browser_tool.py, update the _browser_eval function to wrap the incoming expression in an IIFE that safely checks the result before returning it to the CDP protocol:
safe_expression = f"""
(() => {{
const result = (function() {{ {expression} }})();
if (result instanceof Node || result instanceof NodeList || (typeof Window !== 'undefined' && result instanceof Window)) {{
return "TOOL_ERROR: You cannot return raw DOM Elements. Please extract and return primitive values like .innerText or .href instead.";
}}
return result;
}})()
"""
Steps to Reproduce
. Start an active Hermes agent session with the browser tools enabled.
2. Tell the agent to run the following exact command: browser_console(expression="document.body")
3. Observe the output. Instead of getting a graceful TOOL_ERROR, the underlying CDP connection will crash completely, throwing a raw "Object reference chain is too long" exception back to the agent.
Expected Behavior
When the LLM uses the browser_console tool and its injected JavaScript returns a raw DOM Node or NodeList (e.g., return document.body), it causes a fatal CDP serialization crash instead of returning a graceful tool error
Actual Behavior
. Start an active Hermes agent session with the browser tools enabled.
2. Tell the agent to run the following exact command: browser_console(expression="document.body")
3. Observe the output. Instead of getting a graceful TOOL_ERROR, the underlying CDP connection will crash completely, throwing a raw "Object reference chain is too long" exception back to the agent.
Affected Component
Tools (terminal, file ops, web, code execution, etc.)
Messaging Platform (if gateway-related)
No response
Debug Report
⚠️ This will upload the following to a public paste service:
• System info (OS, Python version, Hermes version, provider, which API keys
are configured — NOT the actual keys)
• Recent log lines (agent.log, errors.log, gateway.log — may contain
conversation fragments and file paths)
• Full agent.log and gateway.log (up to 512 KB each — likely contains
conversation content, tool outputs, and file paths)
Pastes auto-delete after 6 hours.
Collecting debug report...
Uploading...
Debug report uploaded:
Report https://paste.rs/rcrsx
agent.log https://paste.rs/kSPOw
gateway.log https://paste.rs/fwtnL
⏱ Pastes will auto-delete in 6 hours.
To delete now: hermes debug delete <url>Operating System
Windows
Python Version
3.11
Hermes Version
0.15.0
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
No response
Proposed Fix (optional)
No response
Are you willing to submit a PR for this?
- I'd like to fix this myself and submit a PR
Activity
konsisumer commentedon May 30, 2026
Thanks for the detailed report and the proposed IIFE guard, @kmukul123.
This exact crash —
browser_console(expression="document.body")returning the raw CDP errorObject reference chain is too longinstead of usable output — was just fixed in #35385 (state: MERGED tomainon 2026-05-30).The merged fix reaches the same graceful outcome you were after, via a slightly different mechanism (no expression rewriting, so normal evals like
1+41 -> 42are untouched):browser_supervisor.evaluate_runtime: on that specific protocol-level error, retries once withreturnByValue=false, so Chrome returns the node's description string — the same path already used fordocument.querySelector()results._browser_eval(CLI subprocess fallback, which can't retry): converts the reference-chain error into actionable guidance ("extract a primitive value like.innerText/.href, or useJSON.stringify()") instead of surfacing it raw.You reported this on Hermes 0.15.0; the fix isn't in a tagged release yet. Could you pull the latest
main(or the next release once it ships) and confirmbrowser_console(expression="document.body")now returns clean guidance rather than crashing? If you still hit the raw error after that, please reopen with the fresh traceback and we'll dig further.teknium1 commentedon Jul 13, 2026
This is implemented on current
main; closing via automated hermes-sweeper review.92ad7cc62cf030820d1eee9ceabd40f9b4c2cd9e(fix(browser): recover from CDP DOM-node serialization crash in browser_console).tools/browser_supervisor.py:560retries the specific CDP reference-chain failure withreturnByValue=False, returning the DOM object's description rather than crashing.tools/browser_tool.py:3638converts that error to actionable primitive-extraction guidance on the CLI subprocess fallback.tests/tools/test_browser_eval_supervisor_path.py:210and:427cover both fallback guidance and the supervisor retry path.Thanks for the detailed reproduction and proposed guard; the merged fix reaches the requested graceful behavior without rewriting expressions.