Skip to content

Commit 49a66c8

Browse files
committed
docs: clarify CLI evaluate_script usage
1 parent 0a6aaa5 commit 49a66c8

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

docs/cli.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ chrome-devtools fill "input-uid-456" "search query"
7070
chrome-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

7593
By default, the CLI outputs a human-readable summary of the tool's result. For programmatic use, you can request raw JSON:

skills/chrome-devtools-cli/SKILL.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ chrome-devtools take_snapshot # Take a text snapshot of the page from the a11y t
123123
chrome-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

0 commit comments

Comments
 (0)