File tree Expand file tree Collapse file tree
skills/chrome-devtools-cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,6 +70,24 @@ chrome-devtools fill "input-uid-456" "search query"
7070chrome-devtools lighthouse_audit --mode snapshot
7171```
7272
73+ ** Script evaluation:**
74+
75+ ``` sh
76+ # The JavaScript function is the first positional argument.
77+ chrome-devtools evaluate_script ' () => document.title'
78+
79+ # Pass snapshot UIDs through --args instead of putting them in selectors.
80+ chrome-devtools evaluate_script ' (el) => el.innerText' --args 1_4
81+
82+ # For longer scripts, assign the function to a shell variable first.
83+ script=' () => {
84+ return [...document.querySelectorAll("time")].map(el => el.textContent?.trim()).filter(Boolean);
85+ }'
86+ chrome-devtools evaluate_script " $script "
87+ ```
88+
89+ Do not invent flags like ` --expression ` for ` evaluate_script ` . The CLI expects the function as a positional argument, and single quotes are usually the safest way to preserve JavaScript syntax in the shell.
90+
7391## Output format
7492
7593By default, the CLI outputs a human-readable summary of the tool's result. For programmatic use, you can request raw JSON:
Original file line number Diff line number Diff line change @@ -123,6 +123,25 @@ chrome-devtools take_snapshot # Take a text snapshot of the page from the a11y t
123123chrome-devtools take_snapshot --verbose true --filePath " s.txt" # Take a verbose snapshot and save to file
124124```
125125
126+ ### ` evaluate_script ` quoting rules
127+
128+ - Pass the JavaScript function as the first positional argument. Do not invent flags like ` --expression ` .
129+ - Prefer wrapping the whole function in single quotes in the shell so JavaScript parentheses and double quotes are preserved.
130+ - Keep the argument as a function expression such as ` '() => document.title' ` or ` '(el) => el.innerText' ` .
131+ - For complex scripts, write the function to a shell variable first and then pass the variable to ` chrome-devtools evaluate_script ` .
132+
133+ Examples:
134+
135+ ``` bash
136+ chrome-devtools evaluate_script ' () => document.title'
137+ chrome-devtools evaluate_script ' (el) => el.innerText' --args 1_4
138+ script=' () => {
139+ const dates = [...document.querySelectorAll("time")].map(el => el.textContent?.trim()).filter(Boolean);
140+ return dates;
141+ }'
142+ chrome-devtools evaluate_script " $script "
143+ ```
144+
126145## Service Management
127146
128147``` bash
You can’t perform that action at this time.
0 commit comments