Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Automate browser interactions for web testing, form filling, screenshots, and data extraction using the playwright-cli tool.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: playwright-cli3description: Automate browser interactions, test web pages and work with Playwright tests.4allowed-tools: Bash(playwright-cli:*) Bash(npx:*) Bash(npm:*)5---67# Browser Automation with playwright-cli89## Quick start1011```bash12# open new browser13playwright-cli open14# navigate to a page15playwright-cli goto https://playwright.dev16# interact with the page using refs from the snapshot17playwright-cli click e1518playwright-cli type "page.click"19playwright-cli press Enter20# take a screenshot (rarely used, as snapshot is more common)21playwright-cli screenshot22# close the browser23playwright-cli close24```2526## Commands2728### Core2930```bash31playwright-cli open32# open and navigate right away33playwright-cli open https://example.com/34playwright-cli goto https://playwright.dev35playwright-cli type "search query"36playwright-cli click e337playwright-cli dblclick e738# --submit presses Enter after filling the element39playwright-cli fill e5 "[email protected]" --submit40playwright-cli drag e2 e841# drop files or data onto an element (from outside the page)42playwright-cli drop e4 --path=./image.png43playwright-cli drop e4 --data="text/plain=hello world"44playwright-cli hover e445playwright-cli select e9 "option-value"46playwright-cli upload ./document.pdf47playwright-cli check e1248playwright-cli uncheck e1249playwright-cli snapshot50playwright-cli eval "document.title"51playwright-cli eval "el => el.textContent" e552# get element id, class, or any attribute not visible in the snapshot53playwright-cli eval "el => el.id" e554playwright-cli eval "el => el.getAttribute('data-testid')" e555playwright-cli dialog-accept56playwright-cli dialog-accept "confirmation text"57playwright-cli dialog-dismiss58playwright-cli resize 1920 108059playwright-cli close60```6162### Navigation6364```bash65playwright-cli go-back66playwright-cli go-forward67playwright-cli reload68```6970### Keyboard7172```bash73playwright-cli press Enter74playwright-cli press ArrowDown75playwright-cli keydown Shift76playwright-cli keyup Shift77```7879### Mouse8081```bash82playwright-cli mousemove 150 30083playwright-cli mousedown84playwright-cli mousedown right85playwright-cli mouseup86playwright-cli mouseup right87playwright-cli mousewheel 0 10088```8990### Save as9192```bash93playwright-cli screenshot94playwright-cli screenshot e595playwright-cli screenshot --filename=page.png96playwright-cli pdf --filename=page.pdf97```9899### Tabs100101```bash102playwright-cli tab-list103playwright-cli tab-new104playwright-cli tab-new https://example.com/page105playwright-cli tab-close106playwright-cli tab-close 2107playwright-cli tab-select 0108```109110### Storage111112```bash113playwright-cli state-save114playwright-cli state-save auth.json115playwright-cli state-load auth.json116117# Cookies118playwright-cli cookie-list119playwright-cli cookie-list --domain=example.com120playwright-cli cookie-get session_id121playwright-cli cookie-set session_id abc123122playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure123playwright-cli cookie-delete session_id124playwright-cli cookie-clear125126# LocalStorage127playwright-cli localstorage-list128playwright-cli localstorage-get theme129playwright-cli localstorage-set theme dark130playwright-cli localstorage-delete theme131playwright-cli localstorage-clear132133# SessionStorage134playwright-cli sessionstorage-list135playwright-cli sessionstorage-get step136playwright-cli sessionstorage-set step 3137playwright-cli sessionstorage-delete step138playwright-cli sessionstorage-clear139```140141### Network142143```bash144playwright-cli route "**/*.jpg" --status=404145playwright-cli route "https://api.example.com/**" --body='{"mock": true}'146playwright-cli route-list147playwright-cli unroute "**/*.jpg"148playwright-cli unroute149```150151### DevTools152153```bash154playwright-cli console155playwright-cli console warning156playwright-cli requests157playwright-cli request 5158playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])"159playwright-cli run-code --filename=script.js160playwright-cli tracing-start161playwright-cli tracing-stop162playwright-cli video-start video.webm163playwright-cli video-chapter "Chapter Title" --description="Details" --duration=2000164playwright-cli video-stop165166# launch the dashboard for UI review / design feedback — user annotates the page, you receive the annotated screenshot, snapshot, and notes167playwright-cli show --annotate168169# generate a Playwright locator for an element from its ref or selector170playwright-cli generate-locator e5 --raw171172# show a persistent highlight overlay for an element, optionally with a custom style173playwright-cli highlight e5174playwright-cli highlight e5 --style="outline: 3px dashed red"175# hide a single element highlight, or all page highlights when no target is given176playwright-cli highlight e5 --hide177playwright-cli highlight --hide178```179180## Raw output181182The global `--raw` option strips page status, generated code, and snapshot sections from the output, returning only the result value. Use it to pipe command output into other tools. Commands that don't produce output return nothing.183184```bash185playwright-cli --raw eval "JSON.stringify(performance.timing)" | jq '.loadEventEnd - .navigationStart'186playwright-cli --raw eval "JSON.stringify([...document.querySelectorAll('a')].map(a => a.href))" > links.json187playwright-cli --raw snapshot > before.yml188playwright-cli click e5189playwright-cli --raw snapshot > after.yml190diff before.yml after.yml191TOKEN=$(playwright-cli --raw cookie-get session_id)192playwright-cli --raw localstorage-get theme193```194195For structured output wrapping every reply as JSON, pass --json196```bash197playwright-cli list --json198```199200## Open parameters201```bash202# Use specific browser when creating session203playwright-cli open --browser=chrome204playwright-cli open --browser=firefox205playwright-cli open --browser=webkit206playwright-cli open --browser=msedge207208# Use persistent profile (by default profile is in-memory)209playwright-cli open --persistent210# Use persistent profile with custom directory211playwright-cli open --profile=/path/to/profile212213# Connect to browser via Playwright Extension214playwright-cli attach --extension=chrome215216# Connect to a running Chrome or Edge by channel name217playwright-cli attach --cdp=chrome218playwright-cli attach --cdp=msedge219220# Connect to a running browser via CDP endpoint221playwright-cli attach --cdp=http://localhost:9222222223# Start with config file224playwright-cli open --config=my-config.json225226# Close the browser227playwright-cli close228# Detach from an attached browser (leaves the external browser running)229playwright-cli -s=msedge detach230# Delete user data for the default session231playwright-cli delete-data232```233234## Snapshots235236After each command, playwright-cli provides a snapshot of the current browser state.237238```bash239> playwright-cli goto https://example.com240### Page241- Page URL: https://example.com/242- Page Title: Example Domain243### Snapshot244[Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)245```246247You can also take a snapshot on demand using `playwright-cli snapshot` command. All the options below can be combined as needed.248249```bash250# default - save to a file with timestamp-based name251playwright-cli snapshot252253# save to file, use when snapshot is a part of the workflow result254playwright-cli snapshot --filename=after-click.yaml255256# snapshot an element instead of the whole page257playwright-cli snapshot "#main"258259# limit snapshot depth for efficiency, take a partial snapshot afterwards260playwright-cli snapshot --depth=4261playwright-cli snapshot e34262263# include each element's bounding box as [box=x,y,width,height]264playwright-cli snapshot --boxes265```266267## Targeting elements268269By default, use refs from the snapshot to interact with page elements.270271```bash272# get snapshot with refs273playwright-cli snapshot274275# interact using a ref276playwright-cli click e15277```278279You can also use css selectors or Playwright locators.280281```bash282# css selector283playwright-cli click "#main > button.submit"284285# role locator286playwright-cli click "getByRole('button', { name: 'Submit' })"287288# test id289playwright-cli click "getByTestId('submit-button')"290```291292## Browser Sessions293294```bash295# create new browser session named "mysession" with persistent profile296playwright-cli -s=mysession open example.com --persistent297# same with manually specified profile directory (use when requested explicitly)298playwright-cli -s=mysession open example.com --profile=/path/to/profile299playwright-cli -s=mysession click e6300playwright-cli -s=mysession close # stop a named browser301playwright-cli -s=mysession delete-data # delete user data for persistent session302303playwright-cli list304# Close all browsers305playwright-cli close-all306# Forcefully kill all browser processes307playwright-cli kill-all308```309310## Installation311312If global `playwright-cli` command is not available, try a local version via `npx playwright-cli`:313314```bash315npx --no-install playwright-cli --version316```317318When local version is available, use `npx playwright-cli` in all commands. Otherwise, install `playwright-cli` as a global command:319320```bash321npm install -g @playwright/cli@latest322```323324## Example: Form submission325326```bash327playwright-cli open https://example.com/form328playwright-cli snapshot329330playwright-cli fill e1 "[email protected]"331playwright-cli fill e2 "password123"332playwright-cli click e3333playwright-cli snapshot334playwright-cli close335```336337## Example: Multi-tab workflow338339```bash340playwright-cli open https://example.com341playwright-cli tab-new https://example.com/other342playwright-cli tab-list343playwright-cli tab-select 0344playwright-cli snapshot345playwright-cli close346```347348## Example: Debugging with DevTools349350```bash351playwright-cli open https://example.com352playwright-cli click e4353playwright-cli fill e7 "test"354playwright-cli console355playwright-cli requests356playwright-cli close357```358359```bash360playwright-cli open https://example.com361playwright-cli tracing-start362playwright-cli click e4363playwright-cli fill e7 "test"364playwright-cli tracing-stop365playwright-cli close366```367368## Example: Interactive session369370Ask the user for UI review or design feedback. The user draws boxes on the live page and types comments; you receive the annotated screenshot, the snapshot of the marked region, and the user's notes. Use this whenever the user asks for "UI review", "design feedback", or to "ask the user what they think / want / mean":371372```bash373playwright-cli open https://example.com374playwright-cli show --annotate375```376377## Specific tasks378379* **Running and Debugging Playwright tests** [references/playwright-tests.md](references/playwright-tests.md)380* **Request mocking** [references/request-mocking.md](references/request-mocking.md)381* **Running Playwright code** [references/running-code.md](references/running-code.md)382* **Browser session management** [references/session-management.md](references/session-management.md)383* **Spec-driven testing (plan / generate / heal)** [references/spec-driven-testing.md](references/spec-driven-testing.md)384* **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md)385* **Test generation** [references/test-generation.md](references/test-generation.md)386* **Tracing** [references/tracing.md](references/tracing.md)387* **Video recording** [references/video-recording.md](references/video-recording.md)388* **Inspecting element attributes** [references/element-attributes.md](references/element-attributes.md)389