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# annotate each subsequent action (click, type, ...) with a callout naming the action and highlighting the target167playwright-cli video-show-actions --duration=600 --position=top-right168playwright-cli video-hide-actions169170# launch the dashboard for UI review / design feedback — user annotates the page, you receive the annotated screenshot, snapshot, and notes171playwright-cli show --annotate172173# generate a Playwright locator for an element from its ref or selector174playwright-cli generate-locator e5 --raw175176# show a persistent highlight overlay for an element, optionally with a custom style177playwright-cli highlight e5178playwright-cli highlight e5 --style="outline: 3px dashed red"179# hide a single element highlight, or all page highlights when no target is given180playwright-cli highlight e5 --hide181playwright-cli highlight --hide182```183184## Raw output185186The 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.187188```bash189playwright-cli --raw eval "JSON.stringify(performance.timing)" | jq '.loadEventEnd - .navigationStart'190playwright-cli --raw eval "JSON.stringify([...document.querySelectorAll('a')].map(a => a.href))" > links.json191playwright-cli --raw snapshot > before.yml192playwright-cli click e5193playwright-cli --raw snapshot > after.yml194diff before.yml after.yml195TOKEN=$(playwright-cli --raw cookie-get session_id)196playwright-cli --raw localstorage-get theme197```198199For structured output wrapping every reply as JSON, pass --json200```bash201playwright-cli list --json202```203204## Open parameters205```bash206# Use specific browser when creating session207playwright-cli open --browser=chrome208playwright-cli open --browser=firefox209playwright-cli open --browser=webkit210playwright-cli open --browser=msedge211212# Use persistent profile (by default profile is in-memory)213playwright-cli open --persistent214# Use persistent profile with custom directory215playwright-cli open --profile=/path/to/profile216217# Connect to browser via Playwright Extension218playwright-cli attach --extension=chrome219220# Connect to a running Chrome or Edge by channel name221playwright-cli attach --cdp=chrome222playwright-cli attach --cdp=msedge223224# Connect to a running browser via CDP endpoint225playwright-cli attach --cdp=http://localhost:9222226227# Start with config file228playwright-cli open --config=my-config.json229230# Close the browser231playwright-cli close232# Detach from an attached browser (leaves the external browser running)233playwright-cli -s=msedge detach234# Delete user data for the default session235playwright-cli delete-data236```237238## URLs with `&` on Windows239240On Windows, `cmd.exe` and PowerShell treat `&` as a command separator, so URLs with multiple query parameters get truncated before `playwright-cli` runs. Escape `&` with `^&` in `cmd.exe`, or use `--%` in PowerShell:241242```batch243playwright-cli goto "https://example.com/?a=1^&b=2"244```245246```powershell247playwright-cli --% goto "https://example.com/?a=1&b=2"248```249250## Snapshots251252After each command, playwright-cli provides a snapshot of the current browser state.253254```bash255> playwright-cli goto https://example.com256### Page257- Page URL: https://example.com/258- Page Title: Example Domain259### Snapshot260[Snapshot](.playwright-cli/page-2026-02-14T19-22-42-679Z.yml)261```262263You can also take a snapshot on demand using `playwright-cli snapshot` command. All the options below can be combined as needed.264265```bash266# default - save to a file with timestamp-based name267playwright-cli snapshot268269# save to file, use when snapshot is a part of the workflow result270playwright-cli snapshot --filename=after-click.yaml271272# snapshot an element instead of the whole page273playwright-cli snapshot "#main"274275# limit snapshot depth for efficiency, take a partial snapshot afterwards276playwright-cli snapshot --depth=4277playwright-cli snapshot e34278279# include each element's bounding box as [box=x,y,width,height]280playwright-cli snapshot --boxes281```282283## Targeting elements284285By default, use refs from the snapshot to interact with page elements.286287```bash288# get snapshot with refs289playwright-cli snapshot290291# interact using a ref292playwright-cli click e15293```294295You can also use css selectors or Playwright locators.296297```bash298# css selector299playwright-cli click "#main > button.submit"300301# role locator302playwright-cli click "getByRole('button', { name: 'Submit' })"303304# test id305playwright-cli click "getByTestId('submit-button')"306```307308## Browser Sessions309310```bash311# create new browser session named "mysession" with persistent profile312playwright-cli -s=mysession open example.com --persistent313# same with manually specified profile directory (use when requested explicitly)314playwright-cli -s=mysession open example.com --profile=/path/to/profile315playwright-cli -s=mysession click e6316playwright-cli -s=mysession close # stop a named browser317playwright-cli -s=mysession delete-data # delete user data for persistent session318319playwright-cli list320# Close all browsers321playwright-cli close-all322# Forcefully kill all browser processes323playwright-cli kill-all324```325326## Installation327328If global `playwright-cli` command is not available, try a local version via `npx playwright-cli`:329330```bash331npx --no-install playwright-cli --version332```333334When local version is available, use `npx playwright-cli` in all commands. Otherwise, install `playwright-cli` as a global command:335336```bash337npm install -g @playwright/cli@latest338```339340## Example: Form submission341342```bash343playwright-cli open https://example.com/form344playwright-cli snapshot345346playwright-cli fill e1 "[email protected]"347playwright-cli fill e2 "password123"348playwright-cli click e3349playwright-cli snapshot350playwright-cli close351```352353## Example: Multi-tab workflow354355```bash356playwright-cli open https://example.com357playwright-cli tab-new https://example.com/other358playwright-cli tab-list359playwright-cli tab-select 0360playwright-cli snapshot361playwright-cli close362```363364## Example: Debugging with DevTools365366```bash367playwright-cli open https://example.com368playwright-cli click e4369playwright-cli fill e7 "test"370playwright-cli console371playwright-cli requests372playwright-cli close373```374375```bash376playwright-cli open https://example.com377playwright-cli tracing-start378playwright-cli click e4379playwright-cli fill e7 "test"380playwright-cli tracing-stop381playwright-cli close382```383384## Example: Interactive session385386Ask 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":387388```bash389playwright-cli open https://example.com390playwright-cli show --annotate391```392393## Specific tasks394395* **Running and Debugging Playwright tests** [references/playwright-tests.md](references/playwright-tests.md)396* **Request mocking** [references/request-mocking.md](references/request-mocking.md)397* **Running Playwright code** [references/running-code.md](references/running-code.md)398* **Browser session management** [references/session-management.md](references/session-management.md)399* **Spec-driven testing (plan / generate / heal)** [references/spec-driven-testing.md](references/spec-driven-testing.md)400* **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md)401* **Test generation** [references/test-generation.md](references/test-generation.md)402* **Tracing** [references/tracing.md](references/tracing.md)403* **Video recording** [references/video-recording.md](references/video-recording.md)404* **Inspecting element attributes** [references/element-attributes.md](references/element-attributes.md)405