Skip to content

The agent fails to correctly interface with the chrome-devtools binary, inventing flags or failing to escape characters for the shell. #1896

@zyzyzyryxy

Description

@zyzyzyryxy

Description of the bug

Agent can misunderstand how to use CLI interface properly and struggle with finding a working solution.
In one session I encountered 6 consecutive failed attempts to properly call the tool:

  1. Attempt 1 (Bash Syntax Error):

    • Tool Call: chrome-devtools evaluate_script --expression '''const mainElement = document.querySelector('main'); ... return oldestDate.toLocaleDateString(...);'''
    • Error: /usr/bin/bash: line 2: span)).filter(span => { ... No such file or directory
    • Reason: The shell tried to execute the JavaScript code as a bash script because of unescaped parentheses and line breaks.
  2. Attempt 2 (Missing Positional Argument):

    • Tool Call: chrome-devtools evaluate_script --expression '''const mainElement = document.querySelector('main'); ... return oldestDate.toLocaleDateString(...);'''
    • Error: Not enough non-option arguments: got 0, need at least 1
    • Reason: The CLI parser expected the script as a positional argument; it treated the code following --expression as a value for an unrecognized flag.
  3. Attempt 3 (Missing Positional Argument):

    • Tool Call: chrome-devtools evaluate_script --expression "(() => { const dates = []; ... return oldestDate.toLocaleDateString(...); })();"
    • Error: Not enough non-option arguments: got 0, need at least 1
    • Reason: Similar to Attempt 2, but using double quotes. The parser still failed to identify the required positional argument.
  4. Attempt 4 (Unknown CLI Flag):

    • Tool Call: chrome-devtools evaluate_script --expression '''(() => { ... })();'''
    • Error: Unknown arguments: expression, found.;
    • Reason: The CLI explicitly rejected the invented --expression flag.
  5. Attempt 5 (JavaScript Syntax Error via Shell):

    • Tool Call: chrome-devtools evaluate_script "(() => { const dates = []; ... return oldestDate.getTime(); } else { return -1; } })();"
    • Error: Unexpected token ';'
    • Reason: The flag was removed, but the shell stripped or misinterpreted characters within the double-quoted string, resulting in invalid JavaScript being delivered to the browser.
  6. Attempt 6 (JavaScript Syntax Error via Shell):

    • Tool Call: chrome-devtools evaluate_script "(() => { const dateStrings = []; ... return dateStrings; })();"
    • Error: Unexpected token ';'
    • Reason: Final attempt to pass a complex anonymous function. The shell interpretation again corrupted the JavaScript syntax.

Reproduction

Give the agent access to chrome-devtools CLI. Prompt to run some complex script on the page.

Expectation

Improve CLI error messages or related skill to better instruct agent how to formulate CLI commands. Some ideas:

  • Adjust error messages from CLI tool to better inform the agent why it is facing the error, prioritizing "unrecognized flag" error over "missing positional arguments could help. Maybe both issues should be reported at once if possible.
  • Provide concrete example of evaluate_script use in the skill, as this is one of the most commonly used tools.

MCP configuration

No response

Chrome DevTools MCP version

v0.20.1

Chrome version

No response

Coding agent version

gemini-cli

Model version

gemini-2.5-flash

Chat log

No response

Node version

No response

Operating system

None

Extra checklist

  • I want to provide a PR to fix this bug

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions