Headless browser automation using Playwright CLI. Use for browser testing, screenshots, scraping, and parallel browser sessions. Token-efficient CLI — no MCP overhead.
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.
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
Open Session
--persistent to preserve cookies/localStorage across commands-s=mystore-checkout-s=competitor-pricing--headed flagPLAYWRIGHT_MCP_CAPS=visionPLAYWRIGHT_MCP_VIEWPORT_SIZE=<VIEWPORT_SIZE> playwright-cli -s=<session-name> open <url> --persistent
PLAYWRIGHT_MCP_VIEWPORT_SIZE=1440x900 playwright-cli -s=mystore-checkout open https://mystore.com --persistent --headed
Snapshot Page
e12, e45) you can click, fill, etc.playwright-cli -s=mystore-checkout snapshot → returns element tree with refsplaywright-cli -s=<session-name> snapshotInteract with Elements
playwright-cli -s=mystore-checkout click e12 → clicks element ref e12playwright-cli -s=mystore-checkout fill e15 "[email protected]" → fills inputplaywright-cli -s=mystore-checkout type "search query" → types into focused elementplaywright-cli -s=mystore-checkout press Enter → presses keyboard keygoto <url>, go-back, go-forward, reloadplaywright-cli -s=<session-name> <command> <args>Take Screenshots
--filename=<path>playwright-cli -s=mystore-checkout screenshot → saves to default locationplaywright-cli -s=mystore-checkout screenshot --filename=./screenshots/checkout-step1.pngplaywright-cli -s=<session-name> screenshot [--filename=<path>]Close Session
playwright-cli -s=mystore-checkout closeplaywright-cli close-allplaywright-cli -s=<name> delete-dataplaywright-cli -s=<session-name> close| 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>