Skip to content

[Bug]: browser_console crashes with CDP "Object reference chain is too long" when returning DOM Elements #35306

Closed as not planned

Description

@kmukul123

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

  1. added
    type/bugSomething isn't working
    tool/browserBrowser automation (CDP, Playwright)
    P2Medium — degraded but workaround exists
    on May 30, 2026
  2. konsisumer commented on May 30, 2026

    @konsisumer

    Thanks for the detailed report and the proposed IIFE guard, @kmukul123.

    This exact crash — browser_console(expression="document.body") returning the raw CDP error Object reference chain is too long instead of usable output — was just fixed in #35385 (state: MERGED to main on 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 -> 42 are untouched):

    • browser_supervisor.evaluate_runtime: on that specific protocol-level error, retries once with returnByValue=false, so Chrome returns the node's description string — the same path already used for document.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 use JSON.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 confirm browser_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.

  3. teknium1 commented on Jul 13, 2026

    @teknium1
    Collaborator

    This is implemented on current main; closing via automated hermes-sweeper review.

    • PR fix(browser): recover from CDP DOM-node serialization crash in browser_console #35385 merged as 92ad7cc62cf030820d1eee9ceabd40f9b4c2cd9e (fix(browser): recover from CDP DOM-node serialization crash in browser_console).
    • tools/browser_supervisor.py:560 retries the specific CDP reference-chain failure with returnByValue=False, returning the DOM object's description rather than crashing.
    • tools/browser_tool.py:3638 converts that error to actionable primitive-extraction guidance on the CLI subprocess fallback.
    • tests/tools/test_browser_eval_supervisor_path.py:210 and :427 cover 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existssweeper:implemented-on-mainSweeper: behavior already present on current maintool/browserBrowser automation (CDP, Playwright)type/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions