hermes - 💡(How to fix) Fix browser_get_images: 'Evaluation error: SyntaxError: Unexpected end of input' on real pages

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

browser_get_images returns {"success": false, "error": "Evaluation error: SyntaxError: Unexpected end of input"} on real content pages. The same page is fine — a hand-written document.images query via browser_console works, and every other browser_* tool (navigate, snapshot, click, type, press, back, scroll, vision, console) works in the same session.

Error Message

{"success": false, "error": "Evaluation error: SyntaxError: Unexpected end of input"}

Root Cause

browser_get_images returns {"success": false, "error": "Evaluation error: SyntaxError: Unexpected end of input"} on real content pages. The same page is fine — a hand-written document.images query via browser_console works, and every other browser_* tool (navigate, snapshot, click, type, press, back, scroll, vision, console) works in the same session.

Fix Action

Fix / Workaround

Workaround that succeeds on the same session/page — identical logic, wrapped in an IIFE and sent through browser_console:

Code Example

{"success": false, "error": "Evaluation error: SyntaxError: Unexpected end of input"}

---

(() => {
  const imgs = Array.from(document.querySelectorAll('img')).slice(0, 5);
  return imgs.map(i => ({src: i.src, alt: i.alt || '', w: i.naturalWidth, h: i.naturalHeight}));
})()

---

js_code = """JSON.stringify(
    [...document.images].map(img => ({
        src: img.src,
        alt: img.alt || '',
        width: img.naturalWidth,
        height: img.naturalHeight
    })).filter(img => img.src && !img.src.startsWith('data:'))
)"""

---

js_code = """(() => JSON.stringify(
       [...document.images].map(img => ({ ... })).filter(...)
   ))()"""
RAW_BUFFERClick to expand / collapse

Summary

browser_get_images returns {"success": false, "error": "Evaluation error: SyntaxError: Unexpected end of input"} on real content pages. The same page is fine — a hand-written document.images query via browser_console works, and every other browser_* tool (navigate, snapshot, click, type, press, back, scroll, vision, console) works in the same session.

Repro

Fresh CLI session (Browserbase backend, no residential proxies, but that's incidental — bug reproduces on pages that don't touch bot-detection at all):

  1. browser_navigatehttps://en.wikipedia.org/wiki/Hermes (loads, title "Hermes - Wikipedia", 2023 elements in snapshot)
  2. browser_get_images → fails

Output:

{"success": false, "error": "Evaluation error: SyntaxError: Unexpected end of input"}

Reproduced twice back-to-back on the same page. Also hit during an earlier ad-hoc browser-tool sweep (no other failing tool in the same run).

Workaround that succeeds on the same session/page — identical logic, wrapped in an IIFE and sent through browser_console:

(() => {
  const imgs = Array.from(document.querySelectorAll('img')).slice(0, 5);
  return imgs.map(i => ({src: i.src, alt: i.alt || '', w: i.naturalWidth, h: i.naturalHeight}));
})()

Returns the list cleanly.

Where the bug likely lives

tools/browser_tool.py line ~2722 (browser_get_images) builds this raw multi-line expression and ships it to _run_browser_command(task_id, "eval", [js_code]):

js_code = """JSON.stringify(
    [...document.images].map(img => ({
        src: img.src,
        alt: img.alt || '',
        width: img.naturalWidth,
        height: img.naturalHeight
    })).filter(img => img.src && !img.src.startsWith('data:'))
)"""

The same code wrapped in an IIFE via browser_console (which presumably routes through the same CDP eval underneath) succeeds, so the failure is in how the eval bridge wraps / parses this particular expression shape (leading JSON.stringify( + trailing ) over multi-line, no leading (...) grouping or return). SyntaxError: Unexpected end of input is the canonical error when an evaluator feeds the string into something that expects a complete statement/function body rather than a bare expression (e.g. new Function(body) without a return, or a wrapper that strips the closing paren).

Suggested fix

One of:

  1. Wrap the expression at the call site as an IIFE so it's unambiguous regardless of how the bridge parses it:
    js_code = """(() => JSON.stringify(
        [...document.images].map(img => ({ ... })).filter(...)
    ))()"""
  2. Or make _run_browser_command(..., "eval", ...) always wrap single-expression inputs as (() => (<expr>))() before shipping to CDP.

(1) is the one-line fix. (2) prevents the same footgun from biting other eval callers.

Environment

  • OS: Windows 10 (also presumably affects other OSes — the evaluator path is shared)
  • Browser backend: Browserbase (hosted; warning emitted about no residential proxies, but that's unrelated — the failure is at the JS-parse stage before any page behavior matters)
  • hermes-agent: latest main as of 2026-05-08 (clone for inspection just now)
  • Tool version path: tools/browser_tool.py browser_get_images at ~L2705, schema at ~L1397, registry at ~L3488

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING