# microsoft/playwright-cli architecture

> Architecture diagram of the GitHub repository microsoft/playwright-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/playwright-cli
- Repository: https://github.com/microsoft/playwright-cli

## Overview

#### 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`](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js) (Command surface), [`package.json`](https://github.com/microsoft/playwright-cli/blob/main/package.json) (Package metadata), [`skills/playwright-cli/SKILL.md`](https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/SKILL.md) (Agent SKILL), [`skills/playwright-cli/references/tracing.md`](https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/tracing.md) (Tracing guidance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI Runtime"]
  node_cli_entry["playwright-cli<br/>CLI entry<br/>[playwright-cli.js]"]
  node_command_surface["Command surface<br/>commands<br/>[playwright-cli.js]"]
  node_session_manager["Session manager<br/>session lifecycle<br/>[playwright-cli.js]"]
  node_page_interaction["Page interaction<br/>automation commands<br/>[playwright-cli.js]"]
  node_snapshot_search["Snapshots &amp; search<br/>token-efficient page state<br/>[playwright-cli.js]"]
end

subgraph group_browser["Browser Control"]
  node_playwright_runtime{{"Playwright runtime<br/>Node dependency<br/>[package.json]"}}
  node_browser_session["Browser / context / page<br/>browser state<br/>[playwright-cli.js]"]
  node_external_browser["CDP / extension browser<br/>external attachment<br/>[README.md]"]
end

subgraph group_outputs["State &amp; Outputs"]
  node_browser_state[("Saved browser state<br/>storage state<br/>[storage-state.md]")]
  node_network_diagnostics["Routing &amp; diagnostics<br/>network inspection<br/>[request-mocking.md]"]
  node_artifacts["Artifacts<br/>file outputs<br/>[playwright-cli.js]"]
end

subgraph group_skills["Agent Skill Package"]
  node_tracing_guidance["Tracing guidance<br/>skill reference<br/>[tracing.md]"]
  node_skill_docs["Agent SKILL<br/>agent documentation<br/>[SKILL.md]"]
  node_skill_installer["Skill update tooling<br/>repository scripts<br/>[update.js]"]
  node_skill_validation["Skill checker<br/>validation script<br/>[skillCheck.js]"]
end

subgraph group_delivery["Delivery"]
  node_package_metadata["Package metadata<br/>npm package<br/>[package.json]"]
  node_ci["CI workflow<br/>GitHub Actions<br/>[ci.yml]"]
  node_npm_publish["Publish workflow<br/>GitHub Actions<br/>[publish.yml]"]
  node_integration_tests["Integration coverage<br/>command tests"]
end

node_cli_entry -->|"dispatches"| node_command_surface
node_command_surface -->|"selects session"| node_session_manager
node_session_manager -->|"owns"| node_browser_session
node_session_manager -->|"attaches via CDP/extension"| node_external_browser
node_session_manager -->|"uses"| node_playwright_runtime
node_command_surface -->|"executes"| node_page_interaction
node_page_interaction -->|"mutates page"| node_browser_session
node_page_interaction -->|"captures/uses refs"| node_snapshot_search
node_snapshot_search -->|"writes snapshot files"| node_artifacts
node_command_surface -->|"saves and loads"| node_browser_state
node_command_surface -->|"configures and inspects"| node_network_diagnostics
node_command_surface -->|"writes"| node_artifacts
node_skill_docs -.->|"documents usage"| node_cli_entry
node_tracing_guidance -.->|"documents traces"| node_artifacts
node_skill_installer -->|"installs/updates"| node_skill_docs
node_skill_validation -->|"checks"| node_skill_docs
node_package_metadata -->|"packages executable"| node_cli_entry
node_package_metadata -->|"declares dependency"| node_playwright_runtime
node_ci -->|"runs"| node_integration_tests
node_npm_publish -->|"publishes"| node_package_metadata

click node_cli_entry "https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js"
click node_command_surface "https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js"
click node_session_manager "https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js"
click node_page_interaction "https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js"
click node_snapshot_search "https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js"
click node_playwright_runtime "https://github.com/microsoft/playwright-cli/blob/main/package.json"
click node_browser_session "https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js"
click node_external_browser "https://github.com/microsoft/playwright-cli/blob/main/README.md"
click node_browser_state "https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/storage-state.md"
click node_network_diagnostics "https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/request-mocking.md"
click node_artifacts "https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js"
click node_tracing_guidance "https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/tracing.md"
click node_skill_docs "https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/SKILL.md"
click node_skill_installer "https://github.com/microsoft/playwright-cli/blob/main/scripts/update.js"
click node_skill_validation "https://github.com/microsoft/playwright-cli/blob/main/skillCheck.js"
click node_package_metadata "https://github.com/microsoft/playwright-cli/blob/main/package.json"
click node_ci "https://github.com/microsoft/playwright-cli/blob/main/.github/workflows/ci.yml"
click node_npm_publish "https://github.com/microsoft/playwright-cli/blob/main/.github/workflows/publish.yml"
click node_integration_tests "https://github.com/microsoft/playwright-cli/blob/main/tests/integration.spec.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli_entry,node_command_surface,node_session_manager,node_page_interaction,node_snapshot_search toneBlue
class node_playwright_runtime,node_browser_session,node_external_browser toneAmber
class node_browser_state,node_network_diagnostics,node_artifacts toneMint
class node_tracing_guidance,node_skill_docs,node_skill_installer,node_skill_validation toneRose
class node_package_metadata,node_ci,node_npm_publish,node_integration_tests toneIndigo
```

## Components

### CLI Runtime

Node.js command boundary and session-oriented browser control.

- [playwright-cli](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js): CLI entry · Dispatches session-scoped automation commands. · `playwright-cli.js`
- [Command surface](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js): commands · Lifecycle, navigation, interaction, storage, routing, diagnostics, and recording commands. · `playwright-cli.js`
- [Session manager](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js): session lifecycle · Owns named browser, context, and page state across invocations. · `playwright-cli.js`
- [Page interaction](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js): automation commands · Navigates pages and performs locator, ref, and input actions. · `playwright-cli.js`
- [Snapshots & search](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js): token-efficient page state · Writes reference-oriented page structure for agent targeting. · `playwright-cli.js`

### Browser Control

Playwright-managed and externally attached browser sessions.

- [Playwright runtime](https://github.com/microsoft/playwright-cli/blob/main/package.json): Node dependency · Drives installed browser engines. · `package.json`
- [Browser / context / page](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js): browser state · Preserves live cookies and storage while a session remains alive. · `playwright-cli.js`
- [CDP / extension browser](https://github.com/microsoft/playwright-cli/blob/main/README.md): external attachment · 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](https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/storage-state.md): storage state · Save/load state plus cookie and web-storage operations. · `skills/playwright-cli/references/storage-state.md`
- [Routing & diagnostics](https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/request-mocking.md): network inspection · Mocks requests and exposes console and request inspection. · `skills/playwright-cli/references/request-mocking.md`
- [Artifacts](https://github.com/microsoft/playwright-cli/blob/main/playwright-cli.js): file outputs · Screenshots, PDFs, snapshots, traces, videos, and logs. · `playwright-cli.js`

### Agent Skill Package

Portable documentation and installation support for coding agents.

- [Tracing guidance](https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/references/tracing.md): skill reference · Documents trace capture workflows. · `skills/playwright-cli/references/tracing.md`
- [Agent SKILL](https://github.com/microsoft/playwright-cli/blob/main/skills/playwright-cli/SKILL.md): agent documentation · Teaches CLI invocation and specialized automation workflows. · `skills/playwright-cli/SKILL.md`
- [Skill update tooling](https://github.com/microsoft/playwright-cli/blob/main/scripts/update.js): repository scripts · Installs and updates the portable skill package. · `scripts/update.js`
- [Skill checker](https://github.com/microsoft/playwright-cli/blob/main/skillCheck.js): validation script · `skillCheck.js`

### Delivery

Package metadata, CI, and npm publishing automation.

- [Package metadata](https://github.com/microsoft/playwright-cli/blob/main/package.json): npm package · Declares Node.js 18+ runtime, dependencies, and publication metadata. · `package.json`
- [CI workflow](https://github.com/microsoft/playwright-cli/blob/main/.github/workflows/ci.yml): GitHub Actions · Runs automated repository validation. · `.github/workflows/ci.yml`
- [Publish workflow](https://github.com/microsoft/playwright-cli/blob/main/.github/workflows/publish.yml): GitHub Actions · Automates npm package publication. · `.github/workflows/publish.yml`
- [Integration coverage](https://github.com/microsoft/playwright-cli/blob/main/tests/integration.spec.ts): command tests · Exercises command-level CLI behavior. · `tests/integration.spec.ts`

## Connections

- 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
