Compress agent skills
This commit is contained in:
34
agent-browser/references/eval.md
Normal file
34
agent-browser/references/eval.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# JavaScript Evaluation
|
||||
|
||||
Use `eval` to run JavaScript in the browser context.
|
||||
|
||||
Simple expressions can use regular shell quoting:
|
||||
|
||||
```bash
|
||||
agent-browser eval 'document.title'
|
||||
agent-browser eval 'document.querySelectorAll("img").length'
|
||||
```
|
||||
|
||||
For complex JavaScript, use `--stdin` to avoid shell quoting corruption:
|
||||
|
||||
```bash
|
||||
agent-browser eval --stdin <<'EVALEOF'
|
||||
JSON.stringify(
|
||||
Array.from(document.querySelectorAll("img"))
|
||||
.filter(i => !i.alt)
|
||||
.map(i => ({ src: i.src.split("/").pop(), width: i.width }))
|
||||
)
|
||||
EVALEOF
|
||||
```
|
||||
|
||||
Use base64 for generated scripts:
|
||||
|
||||
```bash
|
||||
agent-browser eval -b "$(printf '%s' 'Array.from(document.querySelectorAll("a")).map(a => a.href)' | base64)"
|
||||
```
|
||||
|
||||
Rules of thumb:
|
||||
|
||||
- Single-line with no nested quotes: regular `eval 'expression'`.
|
||||
- Nested quotes, arrow functions, template literals, or multiline: `eval --stdin`.
|
||||
- Programmatic scripts: `eval -b`.
|
||||
Reference in New Issue
Block a user