Skip to content

fix(browser): resolve SyntaxError in browser_get_images eval on CDP bridges#22230

Open
Kailigithub wants to merge 1 commit into
NousResearch:mainfrom
Kailigithub:fix/22012-browser-get-images-syntaxerror
Open

fix(browser): resolve SyntaxError in browser_get_images eval on CDP bridges#22230
Kailigithub wants to merge 1 commit into
NousResearch:mainfrom
Kailigithub:fix/22012-browser-get-images-syntaxerror

Conversation

@Kailigithub

Copy link
Copy Markdown
Contributor

Summary

Fixes a SyntaxError: Unexpected end of input raised by browser_get_images on real content pages. The CDP eval bridge cannot parse a bare multi-line JSON.stringify(...) expression as a complete JavaScript statement — wrapping it as an IIFE ((() => { return JSON.stringify(...) })()) makes it unambiguous regardless of how the bridge constructs its new Function() call.

Root cause

The browser_get_images function at tools/browser_tool.py:2790 passed a raw multi-line JSON.stringify(...) string to _run_browser_command(task_id, "eval", [...]). When the bridge resolves this via new Function(code) without an explicit return, the trailing ) on its own line is interpreted as an incomplete expression, producing SyntaxError: Unexpected end of input.

The same expression wrapped in an IIFE via browser_console succeeds, confirming the fix is at the call site's expression shape.

Fix

Wrap the JSON.stringify(...) call in an IIFE so it is a complete, self-contained statement body:

(() => {
    return JSON.stringify(
        [...document.images].map(img => ({ ... })).filter(...)
    );
})()

This is the minimal, non-invasive fix that works for all CDP eval bridge implementations.

Verification

  • python3 -m py_compile tools/browser_tool.py — pass
  • ruff check tools/browser_tool.py — pass
  • The fix does not change any logic, return type, or call signature; it only adjusts how the JS expression is wrapped for the eval bridge.

Closes #22012

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists tool/browser Browser automation (CDP, Playwright) labels May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/browser Browser automation (CDP, Playwright) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

browser_get_images: 'Evaluation error: SyntaxError: Unexpected end of input' on real pages

2 participants