How microsoft/playwright-cli works
Purpose and Entry Points
playwright-cli is a Node.js command-line interface for browser automation by coding agents. It wraps Playwright operations in concise commands and supplies agent-readable SKILL documentation. Primary executable entry point: playwright-cli.js; package publication/runtime metadata: package.json.
CLI Command Boundary
The CLI accepts session-scoped commands for browser lifecycle, navigation, interaction, snapshots, storage, network routing, diagnostics, recording, and dashboard access. Commands act on a selected/default browser session and return page state or write artifacts rather than embedding full page data into agent context. Core command implementation boundary: playwright-cli.js; command-level integration coverage: tests/integration.spec.ts.
Browser Session Lifecycle
A session owns a Playwright browser/context/page state, preserving cookies and storage across CLI invocations while it remains alive. Sessions may be isolated in memory, persistent on disk, or attached to an existing Chromium-family browser through CDP/extension mechanisms. Session management includes named sessions, listing, graceful close, forced process termination, detach, and data deletion. Relevant entry points: playwright-cli.js, README.md.
Page Interaction and Snapshot Flow
An agent opens or navigates a page, receives or explicitly captures a snapshot, then targets elements using snapshot refs, CSS selectors, or Playwright locators. Interaction commands—typing, clicking, forms, keyboard/mouse actions, uploads, tabs, and dialogs—mutate the selected page. Snapshots and searches are the principal token-efficiency boundary: page structure is emitted as a file/reference-oriented representation rather than a full accessibility tree in command output. Relevant paths: playwright-cli.js, skills/playwright-cli/SKILL.md.
State, Network, and Artifact Boundaries
The CLI exposes browser-state save/load plus cookie, localStorage, and sessionStorage operations. It also manages request routing/mocking and exposes console/request inspection. Screenshots, PDFs, snapshots, traces, and videos are material outputs; configuration controls output location and whether logs/artifacts go to files or stdout. Supporting agent guidance is separated into focused references: skills/playwright-cli/references/storage-state.md, skills/playwright-cli/references/request-mocking.md, skills/playwright-cli/references/tracing.md.
Agent Skill Distribution
The repository ships a portable skill package that teaches agents how to invoke the CLI and complete specialized workflows such as test execution, code execution, test generation, video capture, and element inspection. Installation/update behavior is supported by repository scripts rather than a web service. Primary paths: skills/playwright-cli/SKILL.md, scripts/update.js, skillCheck.js.
Runtime, Infrastructure, and Delivery
Runtime requirements are Node.js 18+ plus Playwright and installed/available browser engines. External browser connections can use Chrome DevTools Protocol or a browser extension; remote browser/service endpoints are configurable. CI and npm publication are automated through GitHub Actions. Relevant paths: package.json, .github/workflows/ci.yml, .github/workflows/publish.yml.
Main entry points: playwright-cli.js Command surface · package.json Package metadata · SKILL.md Agent SKILL · tracing.md Tracing guidance
Components 19
CLI Runtime
Node.js command boundary and session-oriented browser control.
- playwright-cli · Dispatches session-scoped automation commands.
playwright-cli.js - Command surface · Lifecycle, navigation, interaction, storage, routing, diagnostics, and recording commands.
playwright-cli.js - Session manager · Owns named browser, context, and page state across invocations.
playwright-cli.js - Page interaction · Navigates pages and performs locator, ref, and input actions.
playwright-cli.js - Snapshots & search · Writes reference-oriented page structure for agent targeting.
playwright-cli.js
Browser Control
Playwright-managed and externally attached browser sessions.
- Playwright runtime · Drives installed browser engines.
package.json - Browser / context / page · Preserves live cookies and storage while a session remains alive.
playwright-cli.js - CDP / extension browser · Connects to an existing Chromium-family browser or configured endpoint.
README.md
State & Outputs
Persistent browser state and file-oriented agent outputs.
- Saved browser state · Save/load state plus cookie and web-storage operations.
skills/playwright-cli/references/storage-state.md - Routing & diagnostics · Mocks requests and exposes console and request inspection.
skills/playwright-cli/references/request-mocking.md - Artifacts · Screenshots, PDFs, snapshots, traces, videos, and logs.
playwright-cli.js
Agent Skill Package
Portable documentation and installation support for coding agents.
- Tracing guidance · Documents trace capture workflows.
skills/playwright-cli/references/tracing.md - Agent SKILL · Teaches CLI invocation and specialized automation workflows.
skills/playwright-cli/SKILL.md - Skill update tooling · Installs and updates the portable skill package.
scripts/update.js - Skill checker
skillCheck.js
Delivery
Package metadata, CI, and npm publishing automation.
- Package metadata · Declares Node.js 18+ runtime, dependencies, and publication metadata.
package.json - CI workflow · Runs automated repository validation.
.github/workflows/ci.yml - Publish workflow · Automates npm package publication.
.github/workflows/publish.yml - Integration coverage · Exercises command-level CLI behavior.
tests/integration.spec.ts
Connections 20
- playwright-cli → Command surface: dispatches
- Command surface → Session manager: selects session
- Session manager → Browser / context / page: owns
- Session manager → CDP / extension browser: attaches via CDP/extension
- Session manager → Playwright runtime: uses
- Command surface → Page interaction: executes
- Page interaction → Browser / context / page: mutates page
- Page interaction → Snapshots & search: captures/uses refs
- Snapshots & search → Artifacts: writes snapshot files
- Command surface → Saved browser state: saves and loads
- Command surface → Routing & diagnostics: configures and inspects
- Command surface → Artifacts: writes
- Agent SKILL → playwright-cli: documents usage
- Tracing guidance → Artifacts: documents traces
- Skill update tooling → Agent SKILL: installs/updates
- Skill checker → Agent SKILL: checks
- Package metadata → playwright-cli: packages executable
- Package metadata → Playwright runtime: declares dependency
- CI workflow → Integration coverage: runs
- Publish workflow → Package metadata: publishes