How pexip/playwright works
Purpose and distribution
Playwright is a Node.js/TypeScript browser-automation platform: a common API and test runner drive Chromium, Firefox, and WebKit, with CLI, MCP/agent, component-testing, trace, and reporting surfaces. Published package facades expose CommonJS/ESM/types and install hooks from packages/playwright/package.json, packages/playwright-core/package.json, and browser-specific packages such as packages/playwright-chromium/package.json.
Primary entry points
Library consumers import playwright or playwright-core; package entry shims resolve into the core client/server implementation. User-facing commands enter through packages/playwright/cli.js and packages/playwright-core/cli.js. Test commands are assembled in packages/playwright/src/program.ts and packages/playwright/src/cli/testActions.ts; core CLI installation/browser actions live in packages/playwright-core/src/cli/program.ts. MCP starts from packages/playwright-core/src/entry/mcp.ts and packages/playwright-core/src/tools/mcp/program.ts.
Client, protocol, and server boundary
The public client API models browsers, contexts, pages, locators, network, artifacts, and tracing in packages/playwright-core/src/client/playwright.ts, packages/playwright-core/src/client/page.ts, and packages/playwright-core/src/client/locator.ts. Calls cross a channel-based object protocol: generated/spec-defined contracts are rooted in packages/protocol/spec/playwright.yml, validated/serialized in packages/playwright-core/src/protocol/validator.ts, and bridged by server dispatchers such as packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts. This boundary permits in-process operation plus remote pipe/WebSocket transports.
Browser lifecycle and engine adapters
The server owns browser launch, context isolation, page/frame state, instrumentation, downloads, screenshots, video, and network routing. Core orchestration is in packages/playwright-core/src/server/playwright.ts, packages/playwright-core/src/server/browserType.ts, and packages/playwright-core/src/server/browserContext.ts. Engine-specific adapters translate the shared model to Chromium CDP, Firefox’s Juggler protocol, and WebKit protocol: packages/playwright-core/src/server/chromium/crBrowser.ts, packages/playwright-core/src/server/firefox/ffBrowser.ts, and packages/playwright-core/src/server/webkit/wkBrowser.ts. Browser acquisition/version registry is separate in packages/playwright-core/src/server/registry/index.ts.
Page-resident automation
A bundled injected script runs inside controlled pages to implement selector evaluation, locator generation, actionability support, accessibility snapshots, recorder behavior, and WebAuthn/mock capabilities. Key sources are packages/injected/src/injectedScript.ts, packages/injected/src/selectorEvaluator.ts, and packages/injected/src/ariaSnapshot.ts. This is a strict execution boundary: Node-side server code requests behavior, while DOM traversal and element resolution execute in the browser realm.
Test runner pipeline
@playwright/test layers configuration, project expansion, discovery/transformation, worker scheduling, fixtures, retries, assertions, and reporters over the library. Configuration/loading begins at packages/playwright/src/common/configLoader.ts; scheduling and child-process control are in packages/playwright/src/runner/testRunner.ts and packages/playwright/src/runner/workerHost.ts; test execution/fixtures run in packages/playwright/src/worker/workerMain.ts and packages/playwright/src/worker/fixtureRunner.ts. Results flow through reporter implementations, including blob and HTML formats, in packages/playwright/src/reporters/blob.ts and packages/playwright/src/reporters/html.ts.
Artifacts and interactive tooling
Tracing records server-side actions and snapshots, then emits trace artifacts consumed by shared trace models and browser UIs: packages/playwright-core/src/server/trace/recorder/tracing.ts, packages/isomorphic/trace/traceModel.ts, and packages/trace-viewer/src/ui/workbench.tsx. Recorder/codegen uses packages/playwright-core/src/server/recorder/recorderApp.ts with the React frontend in packages/recorder/src/recorder.tsx. Agent-facing MCP tools translate structured requests into browser sessions via packages/playwright-core/src/tools/mcp/browserFactory.ts and packages/playwright-core/src/tools/backend/tools.ts; the dashboard provides live session control through packages/dashboard/src/dashboard.tsx.
Runtimes, native dependencies, and infrastructure
The dominant runtime is Node.js with TypeScript/JavaScript; interactive viewers/dashboard are Vite/React applications. Browser execution depends on downloaded Chromium, Firefox, and WebKit binaries and OS-native dependencies; Firefox/WebKit include maintained upstream patches under browser_patches/firefox/juggler and browser_patches/webkit. Android support includes an ADB-facing server and Gradle-built driver at packages/playwright-core/src/server/android/android.ts and packages/playwright-core/src/server/android/driver. CI publishes npm, Docker, and extension artifacts through workflows including .github/workflows/publish_release.yml, .github/workflows/publish_release_docker.yml, and .github/workflows/publish_extension.yml.
Main entry points: server/playwright.ts Browser orchestration · client/playwright.ts Public client API · testRunner.ts Runner scheduler · browserFactory.ts MCP browser tools
Components 22
Package & command entry points
- Published package facades · Expose CJS, ESM, types, and install hooks.
packages/playwright/package.json - CLI commands
packages/playwright/cli.js - Test command assembly
packages/playwright/src/program.ts - Browser install CLI
packages/playwright-core/src/cli/program.ts - MCP server
packages/playwright-core/src/entry/mcp.ts
Automation core
- Public client API · Browser, context, page, locator, network, artifacts, and tracing APIs.
packages/playwright-core/src/client/playwright.ts - Channel protocol · Spec-defined contracts are validated and serialized across the client/server boundary.
packages/protocol/spec/playwright.yml - Server dispatchers
packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts - Browser orchestration · Owns launch, contexts, pages, routing, downloads, video, and screenshots.
packages/playwright-core/src/server/playwright.ts - Engine adapters · Maps the shared browser model to CDP, Juggler, and WebKit protocols.
packages/playwright-core/src/server/chromium/crBrowser.ts - Browser binaries · Downloaded engines with OS-native dependencies.
- Browser registry
packages/playwright-core/src/server/registry/index.ts - Injected page script · Executes selector evaluation, actionability, accessibility, recorder, and mocks in pages.
packages/injected/src/injectedScript.ts
Test runner
- Config & discovery
packages/playwright/src/common/configLoader.ts - Runner scheduler · Schedules projects, retries, and worker processes.
packages/playwright/src/runner/testRunner.ts - Test workers & fixtures
packages/playwright/src/worker/workerMain.ts - Reporters · Produces blob and HTML result formats.
packages/playwright/src/reporters/html.ts
Artifacts & interactive tools
- Tracing recorder
packages/playwright-core/src/server/trace/recorder/tracing.ts - Trace Viewer
packages/trace-viewer/src/ui/workbench.tsx - Recorder & codegen
packages/playwright-core/src/server/recorder/recorderApp.ts - MCP browser tools · Turns structured agent requests into browser sessions.
packages/playwright-core/src/tools/mcp/browserFactory.ts - Session dashboard · Provides live session control.
packages/dashboard/src/dashboard.tsx
Connections 22
- Published package facades → Public client API: exports
- CLI commands → Test command assembly: test commands
- CLI commands → Browser install CLI: browser commands
- Test command assembly → Config & discovery: loads
- Browser install CLI → Browser registry: installs
- MCP server → MCP browser tools: serves
- Public client API → Channel protocol: channel calls
- Channel protocol → Server dispatchers: validated messages
- Server dispatchers → Browser orchestration: controls
- Browser orchestration → Engine adapters: drives
- Engine adapters → Browser binaries: protocol transport
- Browser registry → Browser binaries: downloads and resolves
- Browser orchestration → Injected page script: requests page-realm actions
- Config & discovery → Runner scheduler: projects and tests
- Runner scheduler → Test workers & fixtures: spawns
- Test workers & fixtures → Public client API: uses automation API
- Runner scheduler → Reporters: results
- Browser orchestration → Tracing recorder: records actions and snapshots
- Tracing recorder → Trace Viewer: trace artifacts
- Browser orchestration → Recorder & codegen: captures interactions
- MCP browser tools → Public client API: creates sessions
- Session dashboard → MCP browser tools: live session control