fix(browser): resolve SyntaxError in browser_get_images eval on CDP bridges#22230
Open
Kailigithub wants to merge 1 commit into
Open
fix(browser): resolve SyntaxError in browser_get_images eval on CDP bridges#22230Kailigithub wants to merge 1 commit into
Kailigithub wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a
SyntaxError: Unexpected end of inputraised bybrowser_get_imageson real content pages. The CDP eval bridge cannot parse a bare multi-lineJSON.stringify(...)expression as a complete JavaScript statement — wrapping it as an IIFE ((() => { return JSON.stringify(...) })()) makes it unambiguous regardless of how the bridge constructs itsnew Function()call.Root cause
The
browser_get_imagesfunction attools/browser_tool.py:2790passed a raw multi-lineJSON.stringify(...)string to_run_browser_command(task_id, "eval", [...]). When the bridge resolves this vianew Function(code)without an explicitreturn, the trailing)on its own line is interpreted as an incomplete expression, producingSyntaxError: Unexpected end of input.The same expression wrapped in an IIFE via
browser_consolesucceeds, 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:This is the minimal, non-invasive fix that works for all CDP eval bridge implementations.
Verification
python3 -m py_compile tools/browser_tool.py— passruff check tools/browser_tool.py— passCloses #22012