How microsoft/webwright works
1. What this repository is
Webwright is a minimal browser-agent runtime built around a terminal, a local workspace, and a Playwright-driven Chromium browser. The core idea is that the agent’s durable state lives in files on disk, not in a long-lived browser session.
2. Primary execution entrypoint
The main runtime path starts in src/webwright/run/cli.py, which exposes the webwright command. It loads layered YAML config, validates runtime prerequisites, creates the run workspace, and hands control to the agent loop.
3. Core agent loop
src/webwright/agents/default.py is the central orchestration layer. It repeatedly:
- sends task/context to the selected model backend,
- receives code or actions,
- executes them in the environment,
- captures results, screenshots, and traces,
- and iterates until the task is done.
This is intentionally flat and script-oriented rather than a multi-agent or graph-based system.
4. Environment boundary: local workspace + browser
The environment layer in src/webwright/environments/ splits into two concerns:
- local_workspace.py for filesystem-backed run state and artifacts,
- local_browser.py for launching and managing Playwright/Chromium sessions.
The browser is treated as disposable; the workspace is the persistent record of the run.
5. Model backend abstraction
src/webwright/models/ provides a backend interface plus provider-specific adapters for OpenAI, Anthropic, and OpenRouter. This is the main external API boundary in the system. The agent loop talks to a common model interface, while provider modules handle auth, request shaping, and response parsing.
6. Tooling and model-dependent helpers
src/webwright/tools/ contains auxiliary capabilities used during runs, especially:
- image_qa.py for analyzing screenshots,
- self_reflection.py for debugging/repair loops,
- persistent_local_browser.py for browser persistence behavior,
- _model_config.py for routing tool usage to the configured model.
These tools are there to compensate when the primary model cannot directly inspect images or needs additional introspection.
7. Configuration model
Config is layered from src/webwright/config/, with base.yaml as the common core and separate overlays for model choice and environment mode, such as model_openai.yaml, model_claude.yaml, local_browser.yaml, persistent_browser.yaml, and task_showcase.yaml. This lets the same agent logic run in different deployment modes without changing code.
8. Artifacts and run outputs
Each run writes structured artifacts to the output workspace, including trajectories, screenshots, and other debugging files. The README also describes task_showcase/tasks/<id>/task.json and report.json when the showcase overlay is enabled. These artifacts are central to debugging, replaying, and comparing runs.
9. Task Showcase subsystem
assets/task_showcase/ is a separate Flask-based presentation layer for repeatable tasks. It renders generated task.json and report.json files into a dashboard using templates/dashboard.html and templates/task.html. This is not part of the agent loop itself; it is a reporting/viewing boundary for completed runs.
10. Trajectory comparison and trace viewing
assets/compare_trajectory/ is a static client-side viewer for comparing traces from Webwright and other agent harnesses. It consumes saved run data such as trajectory.json and raw_responses.jsonl, making trajectory inspection a first-class post-run workflow.
11. Plugin/skill integration boundary
The repo also ships integration surfaces for external agent hosts:
- .claude-plugin/ and .codex-plugin/ provide marketplace/plugin manifests,
- skills/webwright/ contains the shared skill, commands, and reference docs.
In these modes, Webwright can be invoked from Claude Code, Codex, OpenClaw, or Hermes, but the same underlying browser-task workflow and workspace artifact model still applies.
12. Supporting infrastructure
src/webwright/utils/ holds cross-cutting support such as logging, runtime helpers, and serialization. src/webwright/run/doctor.py is the health-check path for verifying local prerequisites. Tests currently focus on doctor behavior and tool-routing correctness, indicating the repo’s main failure points are environment readiness and model/tool dispatch.
Main entry points: default.py Agent loop · base.yaml Config core · cli.py CLI · base.py Model API
Components 20
Runtime
CLI entrypoint, orchestration, and health checks
Environment
Persistent workspace and disposable browser boundary
- Workspace · Durable run state and artifacts stored on disk
src/webwright/environments/local_workspace.py - Browser · Local Playwright/Chromium session management
src/webwright/environments/local_browser.py - Run artifacts · Trajectory, screenshots, reports, and other persisted run outputs
assets/task_showcase/tasks/austin_apartments/report.json
Models
Shared model interface and provider adapters
- Model API · Common backend contract used by the agent loop
src/webwright/models/base.py - OpenAI · OpenAI-specific request and response handling
src/webwright/models/openai_model.py - Anthropic · Anthropic-specific request and response handling
src/webwright/models/anthropic_model.py - OpenRouter · OpenRouter-specific request and response handling
src/webwright/models/openrouter_model.py
Tools
Run-time helpers and model-dependent utilities
- Image QA · Screenshot analysis helper for models that need image interpretation
src/webwright/tools/image_qa.py - Reflection · Self-debugging and repair loop helper
src/webwright/tools/self_reflection.py - Persist browser · Behavior for keeping browser sessions alive across runs
src/webwright/tools/persistent_local_browser.py - Model config · Routes tool usage to the configured model backend
src/webwright/tools/_model_config.py
Showcase
Reporting and task presentation surfaces
- Task showcase · Presentation layer for completed tasks and reports
assets/task_showcase/app.py - Templates · Dashboard and task HTML templates for showcase rendering
assets/task_showcase/templates/dashboard.html - Trajectory viewer · Client-side comparison viewer for saved trajectories and responses
assets/compare_trajectory/app.js
Integrations
External host/plugin entry points
- Plugin manifests · Claude and Codex plugin entry manifests
.claude-plugin/plugin.json - Skill pack · Shared skill, commands, and reference docs for external hosts
skills/webwright/SKILL.md
Other components
- Agent loop · Main task loop that coordinates model calls, actions, results, and iteration
src/webwright/agents/default.py - Config core · Base and overlay YAML configuration for runtime, model, and environment modes
src/webwright/config/base.yaml
Connections 24
- CLI → Config core: loads · CLI assembles layered runtime configuration
- CLI → Doctor: checks · Runs prerequisite verification before execution
- CLI → Workspace: creates · Initializes the run workspace and output location
- CLI → Agent loop: starts · Hands control to the main agent orchestration loop
- Agent loop → Model API: queries · Sends task context and receives model outputs
- Agent loop → Workspace: writes · Persists state, artifacts, and run traces
- Agent loop → Browser: drives · Executes browser actions through Playwright
- Agent loop → Image QA: uses · Analyzes screenshots when visual inspection is needed
- Agent loop → Reflection: uses · Invokes repair and self-debugging support
- Agent loop → Model config: routes · Selects the configured helper or provider path
- Model API → OpenAI: implements · OpenAI provider adapter
- Model API → Anthropic: implements · Anthropic provider adapter
- Model API → OpenRouter: implements · OpenRouter provider adapter
- Persist browser → Browser: configures · Adjusts browser lifecycle behavior for persistent mode
- Task showcase → Templates: renders · Flask app serves dashboard and task views
- Task showcase → Run artifacts: reads · Consumes generated task and report artifacts
- Trajectory viewer → Run artifacts: reads · Loads saved trajectory and raw response files
- Plugin manifests → Skill pack: exposes · Plugin entry points surface the shared skill package
- Skill pack → CLI: invokes · External hosts can call the webwright runtime command
- Config core → Persist browser: enables · Overlay selects persistent browser mode
- Config core → Task showcase: enables · Overlay selects task showcase mode
- Config core → OpenAI: selects · Overlay selects the OpenAI backend
- Config core → Anthropic: selects · Overlay selects the Anthropic backend
- Config core → OpenRouter: selects · Overlay selects the OpenRouter backend