Purpose
Automate browsers using playwright-cli, a token-efficient CLI for Playwright. Runs headless by default, supports parallel sessions via named sessions (-s=), and persistent profiles for cookies/state. Use when you need headless browsing, UI testing, screenshots, web scraping, or any browser automation that can run in the background.
Variables
HEADED: false # Show browser window. Options: true, false
VISION: false # Return screenshots as images in context (higher token cost)
VIEWPORT_SIZE: 1440x900 # Browser viewport dimensions (WxH)
SCREENSHOTS_DIR: ./screenshots # Where screenshots are saved
Workflow
Open Session
- Derive a short kebab-case session name from the user's prompt
- Open with
--persistent to preserve cookies/localStorage across commands
- Example: "test checkout on mystore.com" →
-s=mystore-checkout
- Example: "scrape pricing from competitor.com" →
-s=competitor-pricing
- IF: HEADED is true → add
--headed flag
- IF: VISION is true → prefix with
PLAYWRIGHT_MCP_CAPS=vision
- Tool: Bash
PLAYWRIGHT_MCP_VIEWPORT_SIZE=<VIEWPORT_SIZE> playwright-cli -s=<session-name> open <url> --persistent
- Headed example:
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=mystore-checkout open https://mystore.com --persistent --headed
Snapshot Page
- Capture element references to identify interactive elements
- Returns a list of refs (e.g.,
e12, e45) you can click, fill, etc.
- Example:
playwright-cli -s=mystore-checkout snapshot → returns element tree with refs
- Tool: Bash
playwright-cli -s=<session-name> snapshot
Interact with Elements
- Use refs from snapshot to click, fill, type, select, hover
- Example:
playwright-cli -s=mystore-checkout click e12 → clicks element ref e12
- Example:
playwright-cli -s=mystore-checkout fill e15 "test@example.com" → fills input
- Example:
playwright-cli -s=mystore-checkout type "search query" → types into focused element
- Example:
playwright-cli -s=mystore-checkout press Enter → presses keyboard key
- Navigate:
goto <url>, go-back, go-forward, reload
- Tool: Bash
playwright-cli -s=<session-name> <command> <args>
Take Screenshots
- Capture current page state as PNG
- IF: specific filename needed → use
--filename=<path>
- Example:
playwright-cli -s=mystore-checkout screenshot → saves to default location
- Example:
playwright-cli -s=mystore-checkout screenshot --filename=./screenshots/checkout-step1.png
- Tool: Bash
playwright-cli -s=<session-name> screenshot [--filename=<path>]
Close Session
- ALWAYS close the session when done — this is not optional
- Example:
playwright-cli -s=mystore-checkout close
- To close ALL sessions:
playwright-cli close-all
- To wipe session data:
playwright-cli -s=<name> delete-data
- Tool: Bash
playwright-cli -s=<session-name> close
Additional Commands Reference
| Command |
Description |
Example |
open [url] |
Launch browser |
-s=test open https://example.com --persistent |
close |
Close session |
-s=test close |
goto <url> |
Navigate to URL |
-s=test goto https://example.com/page2 |
snapshot |
Get element refs |
-s=test snapshot |
screenshot |
Capture page image |
-s=test screenshot --filename=out.png |
click <ref> |
Click element |
-s=test click e12 |
fill <ref> <text> |
Fill input field |
-s=test fill e15 "hello" |
type <text> |
Type into focused |
-s=test type "search" |
press <key> |
Press keyboard key |
-s=test press Enter |
hover <ref> |
Hover over element |
-s=test hover e20 |
select <ref> <val> |
Select dropdown |
-s=test select e30 "option1" |
go-back |
Back |
-s=test go-back |
go-forward |
Forward |
-s=test go-forward |
reload |
Reload page |
-s=test reload |
tab-list |
List tabs |
-s=test tab-list |
tab-new [url] |
New tab |
-s=test tab-new https://example.com |
tab-select <i> |
Switch tab |
-s=test tab-select 1 |
list |
List sessions |
list |
close-all |
Close all sessions |
close-all |
Common flags: --persistent (cookies/state), --headed (visible browser), --browser=chrome, --filename=<path>
1---2name: playwright-browser3description: Headless browser automation using Playwright CLI. Use for browser testing, screenshots, scraping, and parallel browser sessions. Token-efficient CLI — no MCP overhead.4---56# Purpose78Automate browsers using `playwright-cli`, a token-efficient CLI for Playwright. Runs headless by default, supports parallel sessions via named sessions (`-s=`), and persistent profiles for cookies/state. Use when you need headless browsing, UI testing, screenshots, web scraping, or any browser automation that can run in the background.910## Variables1112HEADED: false # Show browser window. Options: true, false13VISION: false # Return screenshots as images in context (higher token cost)14VIEWPORT_SIZE: 1440x900 # Browser viewport dimensions (WxH)15SCREENSHOTS_DIR: ./screenshots # Where screenshots are saved1617## Workflow18191. **Open Session**20 - Derive a short kebab-case session name from the user's prompt21 - Open with `--persistent` to preserve cookies/localStorage across commands22 - Example: "test checkout on mystore.com" → `-s=mystore-checkout`23 - Example: "scrape pricing from competitor.com" → `-s=competitor-pricing`24 - IF: HEADED is true → add `--headed` flag25 - IF: VISION is true → prefix with `PLAYWRIGHT_MCP_CAPS=vision`26 - Tool: Bash27 ```28 PLAYWRIGHT_MCP_VIEWPORT_SIZE=<VIEWPORT_SIZE> playwright-cli -s=<session-name> open <url> --persistent29 ```30 - Headed example:31 ```32 PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=mystore-checkout open https://mystore.com --persistent --headed33 ```34352. **Snapshot Page**36 - Capture element references to identify interactive elements37 - Returns a list of refs (e.g., `e12`, `e45`) you can click, fill, etc.38 - Example: `playwright-cli -s=mystore-checkout snapshot` → returns element tree with refs39 - Tool: Bash `playwright-cli -s=<session-name> snapshot`40413. **Interact with Elements**42 - Use refs from snapshot to click, fill, type, select, hover43 - Example: `playwright-cli -s=mystore-checkout click e12` → clicks element ref e1244 - Example: `playwright-cli -s=mystore-checkout fill e15 "test@example.com"` → fills input45 - Example: `playwright-cli -s=mystore-checkout type "search query"` → types into focused element46 - Example: `playwright-cli -s=mystore-checkout press Enter` → presses keyboard key47 - Navigate: `goto <url>`, `go-back`, `go-forward`, `reload`48 - Tool: Bash `playwright-cli -s=<session-name> <command> <args>`49504. **Take Screenshots**51 - Capture current page state as PNG52 - IF: specific filename needed → use `--filename=<path>`53 - Example: `playwright-cli -s=mystore-checkout screenshot` → saves to default location54 - Example: `playwright-cli -s=mystore-checkout screenshot --filename=./screenshots/checkout-step1.png`55 - Tool: Bash `playwright-cli -s=<session-name> screenshot [--filename=<path>]`56575. **Close Session**58 - ALWAYS close the session when done — this is not optional59 - Example: `playwright-cli -s=mystore-checkout close`60 - To close ALL sessions: `playwright-cli close-all`61 - To wipe session data: `playwright-cli -s=<name> delete-data`62 - Tool: Bash `playwright-cli -s=<session-name> close`6364## Additional Commands Reference6566| Command | Description | Example |67|---------|-------------|---------|68| `open [url]` | Launch browser | `-s=test open https://example.com --persistent` |69| `close` | Close session | `-s=test close` |70| `goto <url>` | Navigate to URL | `-s=test goto https://example.com/page2` |71| `snapshot` | Get element refs | `-s=test snapshot` |72| `screenshot` | Capture page image | `-s=test screenshot --filename=out.png` |73| `click <ref>` | Click element | `-s=test click e12` |74| `fill <ref> <text>` | Fill input field | `-s=test fill e15 "hello"` |75| `type <text>` | Type into focused | `-s=test type "search"` |76| `press <key>` | Press keyboard key | `-s=test press Enter` |77| `hover <ref>` | Hover over element | `-s=test hover e20` |78| `select <ref> <val>` | Select dropdown | `-s=test select e30 "option1"` |79| `go-back` | Back | `-s=test go-back` |80| `go-forward` | Forward | `-s=test go-forward` |81| `reload` | Reload page | `-s=test reload` |82| `tab-list` | List tabs | `-s=test tab-list` |83| `tab-new [url]` | New tab | `-s=test tab-new https://example.com` |84| `tab-select <i>` | Switch tab | `-s=test tab-select 1` |85| `list` | List sessions | `list` |86| `close-all` | Close all sessions | `close-all` |8788**Common flags**: `--persistent` (cookies/state), `--headed` (visible browser), `--browser=chrome`, `--filename=<path>`