Contributing to Playwright
Relevant source files
The following files were used as context for generating this wiki page:
Contributing to Playwright involves a structured process designed to maintain code quality, consistency, and documentation. All contributions, from bug fixes to new features, require an associated GitHub issue to facilitate discussion and tracking. The project is a multi-package monorepo managed with npm workspaces, containing the core browser automation APIs, the test runner, and browser-specific packages.
This guide outlines the necessary steps for setting up the development environment, making changes, writing tests, and submitting a pull request. Adherence to the project's coding style, commit message format, and testing requirements is essential for a successful contribution.
Sources: CONTRIBUTING.md, README.md
Getting Started: Environment Setup
Before making any changes, you must set up the development environment. This involves cloning the repository, installing dependencies, and running the initial build.
Sources: CONTRIBUTING.md:13-23
Prerequisites
You must be running Node.js version 20 or later. The project's package.json files also specify a Node.js engine requirement of >=18.
node --version
Sources: CONTRIBUTING.md:14-16, packages/playwright/package.json:9-11, packages/playwright-core/package.json:9-11
Repository Setup and Installation
The initial setup process involves cloning the repository, installing all dependencies using npm ci, and installing the necessary browsers for testing.
The following diagram illustrates the setup workflow.
This diagram shows the sequence of commands to prepare the local development environment.
Sources: CONTRIBUTING.md:18-26
The commands to execute are:
# Clone your fork or the main repository
git clone https://github.com/microsoft/playwright
cd playwright
# Install dependencies
npm ci
# Run the build in watch mode
npm run watch
# Install browser binaries
npx playwright install
The npm run watch command starts a continuous build process that automatically recompiles files as you make changes. Note that some files, like TypeScript type definitions, are generated from the documentation in docs/src, and the watch process will overwrite manual changes to them.
Sources: CONTRIBUTING.md:21-30, package.json:28
Project Structure
Playwright is a monorepo that uses npm workspaces to manage its multiple packages. The key packages are located in the packages/ directory.
This diagram shows the dependency relationships between the main Playwright packages.
Sources: package.json:34-36, packages/playwright/package.json:52-54, packages/playwright-core/package.json, packages/playwright-test/package.json:28-30, packages/playwright-webkit/package.json:28-30, packages/playwright-chromium/package.json:28-30, packages/playwright-firefox/package.json:28-30
packages/playwright-core: Contains the core browser automation APIs. This is where most of the browser interaction logic resides.packages/playwright: The main package, which includes the test runner functionality. It depends onplaywright-core.packages/playwright-test: The package for the Playwright Test runner, which consumers install via@playwright/test. It depends on theplaywrightpackage.packages/playwright-chromium,packages/playwright-firefox,packages/playwright-webkit: These packages are responsible for managing their respective browser binaries and depend onplaywright-core.
Sources: CONTRIBUTING.md:32-33, packages/playwright/package.json, packages/playwright-core/package.json, packages/playwright-test/package.json
The Contribution Workflow
Contributing to Playwright follows a standard workflow: choose or create an issue, make your changes in a fork, add tests, and submit a pull request for review.
1. Choose or File an Issue
Every contribution, except for minor documentation updates, must be associated with a GitHub issue. This allows for discussion and feedback before development work begins.
- First-time contributors are encouraged to pick an issue labeled
open-to-a-pull-request. - If you have a new bug or feature, file a new issue first. Follow the "Bug Report" template and provide a minimal, reproducible example.
This diagram shows the contribution flow from issue creation to the pull request merge.
Sources: CONTRIBUTING.md:3-11, FILING_ISSUES.md
2. Make Changes and Write Documentation
When making code changes, ensure they adhere to the project's coding style, which is enforced by ESLint. You can check your code at any time by running:
npm run lint
Any new or changed public API must be documented in the docs/src directory within the same pull request. The documentation source is written in Markdown with a custom structure. The npm run watch process will automatically regenerate other documentation files from this source.
Sources: CONTRIBUTING.md:35-51, package.json:23
3. Add Tests
A test is required for almost any new or modified functionality. The project has multiple test suites located in the tests/ directory. The two most important suites to run locally are:
| Command | Description |
|---|---|
npm run ctest | Runs library API tests against Chromium (fast path). |
npm run test | Runs all library API tests against Chromium, Firefox, and WebKit. |
npm run ttest | Runs tests for the test runner itself. |
Tests must be hermetic, meaning they should not depend on external services and must work on macOS, Linux, and Windows.
Sources: CONTRIBUTING.md:53-70, package.json:17,20,22
Running against Changed Files
For a faster feedback loop, you can run tests only against files that have changed in your local git repository using the --only-changed flag. This feature analyzes the git diff and the project's dependency graph to determine which tests to run.
# Run tests for untracked or modified files
npx playwright test --only-changed
This is not compatible with watch mode or UI mode.
Sources: tests/playwright-test/only-changed.spec.ts:47-56, 114-116
4. Write a Commit Message
Commit messages must follow the Semantic Commit Messages format.
| Part | Description |
|---|---|
| label | fix, feat, docs, test, devops, or chore. |
| namespace | (Optional) A lowercase identifier in parentheses, e.g., (trace viewer). |
| title | A brief summary of the changes. |
| description | (Optional) A more detailed explanation in the present tense. |
| footer | (Optional) References to GitHub issues, e.g., Fixes #123. |
Example:
feat(trace viewer): network panel filtering
This patch adds a filtering toolbar to the network panel.
<link to a screenshot>
Fixes #123, references #234.
Sources: CONTRIBUTING.md:72-101
5. Send a Pull Request
Once your changes are complete, tested, and properly committed, submit a pull request. All submissions require a code review. Keep your pull requests small and focused. A CLA (Contributor License Agreement) bot will automatically check if you need to sign the agreement.
Sources: CONTRIBUTING.md:103-112
Development Scripts and Tooling
The package.json file contains numerous scripts to aid in development.
| Script | Description |
|---|---|
npm run build | Performs a one-time build of the project. |
npm run watch | Builds the project and watches for file changes to rebuild automatically. |
npm run lint | Runs ESLint, TypeScript compiler checks, and documentation linter. |
npm run doc | Runs the documentation linter (doclint). |
npm run test | Runs the full library test suite across all browsers. |
npm run ctest | Runs the library test suite on Chromium only. |
npm run ttest | Runs the test-runner's own test suite. |
npm run roll | A script to roll a new browser version into Playwright. |
Sources: package.json:17-29, CONTRIBUTING.md
Experimental HMR Dev Mode
For a faster development experience on UI-related features like the Recorder, Trace Viewer, and UI Mode, you can enable Hot Module Replacement (HMR) by setting the PW_HMR environment variable.
# Example for running UI Mode with HMR
PW_HMR=1 npm run ctest -- --ui
Sources: CONTRIBUTING.md:28-30
Using Custom Browser Builds
To test with a custom-built browser, you can specify the path to the executable using environment variables:
CRPATH: Path to Chromium executable.WKPATH: Path to WebKit executable.FFPATH: Path to Firefox executable.
Example:
CRPATH=<path-to-executable> npm run ctest
Sources: CONTRIBUTING.md:119-125