Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .azure-pipelines/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ extends:
echo '{ "data-root": "/mnt/docker" }' | sudo tee /etc/docker/daemon.json
sudo service docker start

# Used by scripts/download_driver.sh on the host. The Docker build context is
# utils/docker (see build.sh), so this file never reaches the images.
# scripts/build_driver.sh builds the driver from .upstream/ on the host. `npm ci` uses
# the registry and the credentials of this .npmrc file. The Docker build context is
# utils/docker (see build.sh), thus this file does not go into the images.
- task: Bash@3
displayName: "setup .npmrc"
inputs:
Expand Down
7 changes: 5 additions & 2 deletions .azure-pipelines/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ extends:
inputs:
workingFile: .npmrc

- bash: ./scripts/download_driver.sh
displayName: 'Download driver'
# The script clones microsoft/playwright into .upstream/ at the commit in
# scripts/DRIVER_VERSION and builds the driver from it. `npm ci` uses the registry
# and the credentials of the .npmrc file above.
- bash: ./scripts/build_driver.sh
displayName: 'Build the driver'

# Must run before MavenAuthenticate@0 so the credentials it injects into
# ~/.m2/settings.xml are not overwritten by the copy.
Expand Down
13 changes: 12 additions & 1 deletion .claude/skills/playwright-java-release/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ name: playwright-java-release
description: Prepare a Playwright Java release after the rolling PR has merged — cut the release branch, mark the Maven version, add Java-specific changes to the release notes, draft the GitHub release, and tick the Java boxes in the internal checklist.
---

Use this skill once the `chore: roll driver to 1.X.0` PR has merged into `main` and the upstream JS `v1.X.0` is published. The rolling work itself is covered by the [[playwright-roll]] skill.
Use this skill after the roll PR for `1.X` is in `main`. The [[playwright-roll]] skill does the roll.

First, check the driver. We build the driver from the `microsoft/playwright` commit in `scripts/DRIVER_VERSION`, not from a published npm package. For a release, that commit must be on the upstream `release-1.X` branch, and the driver must report `1.X.y`:

```bash
scripts/build_driver.sh
git -C .upstream fetch origin release-1.X
git -C .upstream merge-base --is-ancestor "$(cat scripts/DRIVER_VERSION)" FETCH_HEAD && echo "on release-1.X"
git -C .upstream show "$(cat scripts/DRIVER_VERSION)":packages/playwright-core/package.json | grep '"version"'
```

If a check fails, tell the user, and roll with `scripts/roll_driver.sh release-1.X` (the tip of the branch) or `scripts/roll_driver.sh <commit>` (the commit that the user gives).

Throughout this doc, replace `X` with the minor version (e.g. `60` for `1.60.0`) and `<user>` with the fork owner (`gh api user --jq .login`).

Expand Down
114 changes: 70 additions & 44 deletions .claude/skills/playwright-roll/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,90 @@
---
name: playwright-roll
description: Roll Playwright Java to a new version
description: Roll Playwright Java to a new microsoft/playwright commit. Moves the commit in scripts/DRIVER_VERSION, builds the driver from source, generates the API, and ports the upstream changes of the client.
---

Help the user roll to a new version of Playwright.
ROLLING.md contains general instructions and scripts.
# Rolling Playwright

Start with running ./scripts/roll_driver.sh to update the version and generate the API to see the state of things.
Afterwards, walk through the upstream changes that affect the Java client and port the relevant ones.
Read `AGENTS.md` and `ROLLING.md` first.

## Determining what to port
`scripts/DRIVER_VERSION` holds one commit of `microsoft/playwright`. We build the driver from source at that commit. `.upstream/` (gitignored) is a clone of `microsoft/playwright` at that commit. Read the upstream code there. Do not edit, commit or switch branches in `.upstream/`.

List the upstream commits that touched a client-relevant path since the last release. The paths cover everything that can change the public Java surface or the wire protocol:
A roll moves `scripts/DRIVER_VERSION` to a newer commit and ports the changes between the two commits. A roll does not use the published npm packages or their versions.

- `docs/src/api/` — the source of truth for `api.json`. Method/option additions, removals, and `langs:` filter changes flow from here.
- `packages/playwright-core/src/client/` — the JS client implementation that the Java client mirrors.
- `packages/isomorphic/` — selector engines, locator generation/parsing, and aria-snapshot logic shared between client and server. Changes here can affect client-side helpers like `getByRoleSelector`.
- `packages/playwright/src/matchers/matchers.ts` — assertion-method definitions. Changes here usually correspond to new options on `LocatorAssertions` / `PageAssertions`.
- `packages/protocol/spec/` — the wire protocol schema (one `*.yml` file per area). Method/event additions, parameter renames, and result-shape changes affect what the Java `*Impl` classes need to send/receive.
## 1. Roll

```bash
cd ~/playwright
PREV_TAG=$(git tag | grep -E '^v1\.[0-9]+\.[0-9]+$' | sort -V | tail -1) # e.g. v1.59.1
git log "$PREV_TAG"..HEAD --oneline -- \
./scripts/roll_driver.sh # the tip of upstream main
./scripts/roll_driver.sh release-1.X # the tip of an upstream release branch
./scripts/roll_driver.sh <commit> # an exact commit (40 hex digits)
```

Use the target that the user gives. If the user gives no target, roll `main` to upstream `main`, and roll a `release-1.X` branch of this repository to upstream `release-1.X`.

The script writes the commit to `scripts/DRIVER_VERSION`, rolls Node.js, builds the driver from `.upstream/`, generates the API and updates the README. Then get the two commits:

```bash
old=$(git show HEAD:scripts/DRIVER_VERSION)
new=$(cat scripts/DRIVER_VERSION)
```

## 2. Find the changes to port

List the upstream commits between the two commits that changed a path the Java client depends on:

- `docs/src/api/` — the source of `api.json`. A new or removed method or option, or a changed `langs:` filter, comes from here.
- `packages/playwright-core/src/client/` — the JS client. The Java client is a port of it.
- `packages/isomorphic/` — selector engines, locator generation and parsing, and the aria snapshot code. The client and the server share this code. A change here can change client helpers such as `getByRoleSelector`.
- `packages/playwright/src/matchers/matchers.ts` — the assertion methods. A change here is usually a new option of `LocatorAssertions` or `PageAssertions`.
- `packages/protocol/spec/` — the wire protocol, one `*.yml` file for each area. A new method or event, a renamed parameter or a changed result changes the messages that the Java `*Impl` classes send and receive.

```bash
git -C .upstream log "$old..$new" --oneline --reverse -- \
'docs/src/api/' \
'packages/playwright-core/src/client/' \
'packages/isomorphic/' \
'packages/playwright/src/matchers/matchers.ts' \
'packages/protocol/spec/'
```

Walk that list top-to-bottom (oldest-first is easier — newest is at top, so reverse). For each commit:
1. Read the commit (`git show <sha>`) to see what client/protocol/docs changed.
2. If it's JS-internal (bundling, dispatcher conventions, electron, mcp, dashboard, trace-viewer, test-runner) — skip.
3. If it touches `docs/src/api/` or types, check `langs:` annotations — features marked `langs: js`/`langs: js, python` don't apply to Java.
4. If it adds/changes a public API method or option that applies to Java, port it. The api.json regenerated by `roll_driver.sh` already contains the new types/options, so the generated Java interfaces usually pick them up automatically — what's typically missing is the `*Impl` wiring.
5. Watch for follow-up reverts — a "feat: X" commit might be undone by a later "Revert X". Check whether the change still exists in HEAD before porting.
6. Maintain a running notes file (e.g. `/tmp/roll-notes.md`) listing each upstream PR as ported / skipped / verified-already-supported, with a one-line reason. This file becomes the body of the eventual PR.
The list starts with the oldest commit. Do these steps for each commit:

1. Read the commit: `git -C .upstream show <sha>`.
2. If the change is internal to JS (bundling, dispatchers, electron, mcp, dashboard, trace viewer, test runner), skip it.
3. If the commit changes `docs/src/api/` or types, read the `langs:` annotations. A feature with `langs: js` or `langs: js, python` does not apply to Java.
4. If the commit adds or changes a public method or option that applies to Java, port it. `roll_driver.sh` already generated the new types and options in the Java interfaces. Usually only the `*Impl` code is missing.
5. Make sure that a later commit did not revert the change. Look at the code at `$new` before you port.
6. Keep notes in a file (for example `/tmp/roll-notes.md`). For each upstream PR, write one line: ported, skipped or already supported, with the reason. The PR description comes from this file.

## What to include in the rolling PR
## 3. The roll PR

- Driver version bump
- Generated interface diffs from `roll_driver.sh`
- `*Impl` wiring for each ported feature
- Generator updates (import lists, special-cases) if new types appeared
- A small test per new public API surface — listener for new events, basic call for new methods, regression for changed return types
- PR description: list each upstream PR ported, each skipped (with reason), and each verified-already-supported
The PR contains:

Rolling includes:
- updating client implementation to match changes in the upstream JS implementation (see ../playwright/packages/playwright-core/src/client)
- adding a couple of new tests to verify new/changed functionality
- the new commit in `scripts/DRIVER_VERSION`, and the new `scripts/NODE_VERSION` if Node.js changed;
- the generated interfaces from `roll_driver.sh`;
- the `*Impl` code for each ported feature, the same as the upstream JS client (`.upstream/packages/playwright-core/src/client`);
- changes to the generator (import lists, special cases) if there are new types;
- one small test for each new public API: a listener for a new event, a call for a new method, a regression test for a changed return type.

Title: `chore(driver): roll to <version> (<first 10 characters of $new>)`. `<version>` is the version that the driver reports. Read it from the source, not from npm:

```bash
node -p "require('./.upstream/packages/playwright-core/package.json').version" # for example 1.67.0-next
```

Description: list each upstream PR that you ported, each PR that you skipped (with the reason), and each PR that Java already supported.

## Mimicking the JavaScript implementation

The Java client is a port of the JS client in `../playwright/packages/playwright-core/src/client/`. When implementing a new or changed method, always read the corresponding JS file first and mirror its logic:
The Java client is a port of the JS client in `.upstream/packages/playwright-core/src/client/`. When implementing a new or changed method, always read the corresponding JS file first and mirror its logic:

```
../playwright/packages/playwright-core/src/client/browserContext.ts
../playwright/packages/playwright-core/src/client/page.ts
../playwright/packages/playwright-core/src/client/tracing.ts
../playwright/packages/playwright-core/src/client/video.ts
../playwright/packages/playwright-core/src/client/locator.ts
../playwright/packages/playwright-core/src/client/network.ts
.upstream/packages/playwright-core/src/client/browserContext.ts
.upstream/packages/playwright-core/src/client/page.ts
.upstream/packages/playwright-core/src/client/tracing.ts
.upstream/packages/playwright-core/src/client/video.ts
.upstream/packages/playwright-core/src/client/locator.ts
.upstream/packages/playwright-core/src/client/network.ts
...
```

Expand Down Expand Up @@ -136,17 +159,20 @@ Common patterns:

**Protocol parameter renames** — protocol parameter names can change between versions (e.g. `wsEndpoint` → `endpoint` in `BrowserType.connect`). When a test fails with `expected string, got undefined` or similar validation errors from the driver, check `packages/protocol/spec/*.yml` for the current parameter names and update the corresponding `params.addProperty(...)` call in the Impl class. Also check the JS client (`src/client/`) to see how it builds the params object.

## Rebuilding the driver-bundle after a roll
## Rebuilding the driver modules after a roll

`./scripts/roll_driver.sh` does the whole roll pipeline end-to-end: bumps `DRIVER_VERSION`, downloads new driver files into `driver-bundle/src/main/resources/driver/<platform>/`, regenerates `api.json` and the Java interfaces, and updates the README. When all of that succeeds, the next `mvn` invocation that touches `driver-bundle` will pick up the new files and you don't need to think about it.
`./scripts/roll_driver.sh` does the full roll. It moves `scripts/DRIVER_VERSION` to the new commit. It builds the driver from `.upstream/` into `driver/src/main/resources/driver/package/` and `driver-bundle/src/main/resources/driver/<platform>/`. It generates `api.json` and the Java interfaces, and it updates the README. If all steps pass, the next `mvn` command uses the new driver.

But if any step in the pipeline fails (the very common case is the API generator throwing on a new type — see *Fixing generator and compilation errors*), the run aborts before `driver-bundle/target/classes/` has been refreshed. From that point on, until you manually rebuild `driver-bundle`, the test JVM will load the **old** driver from the cached `target/classes`/installed jar even though the source resources have already been swapped to the new version.
If a step fails, the script stops before Maven installs the new driver. The most frequent cause is the API generator, which fails on a new type (see *Fixing generator and compilation errors*). After that, the test JVM loads the **old** driver from `target/classes` or from the installed jar, although the source resources already hold the new driver.

Fix — rebuild `driver-bundle` once before re-running tests:
To correct this, install the two driver modules one time before you run the tests again:
```
mvn -f driver/pom.xml install -DskipTests
mvn -f driver-bundle/pom.xml install -DskipTests
```

If `scripts/generate_api.sh` prints `.upstream/ is not at ...`, run `scripts/build_driver.sh`.

## Porting and verifying tests

**Before porting an upstream test file, check the API exists in Java.** The upstream repo may have test files for brand-new APIs that haven't been added to the Java interface yet (e.g., `screencast.spec.ts` tests `page.screencast` which may not be in the generated `Page.java`). Check `git diff main --name-only` to see what interfaces were added this roll, and verify the method exists in the generated Java interface before porting.
Expand Down Expand Up @@ -178,5 +204,5 @@ Each line is a stack frame inside a test method — typically you'll see one or

When you've identified a hanging test:
1. Run it in isolation: `mvn -f playwright/pom.xml test -Dtest='TestClass#testMethod'`. If it passes alone, it's a parallel-load flake — note it but move on.
2. If it still hangs in isolation, look for a recent fix in the upstream repo for the *same* test name. Use `git log --oneline tests/library/<spec>.spec.ts` in `~/playwright`. Upstream fixes for client-side hangs are often small and portable (e.g. `about:blank` → `server.EMPTY_PAGE` from microsoft/playwright#39840 fixed `route-web-socket.spec.ts` arraybuffer hangs — apparently some browser changed the WebSocket origin policy on `about:blank`).
2. If it still hangs in isolation, look for a recent fix in the upstream repo for the *same* test name. Use `git -C .upstream log --oneline -- tests/library/<spec>.spec.ts`. Upstream fixes for client-side hangs are often small and portable (e.g. `about:blank` → `server.EMPTY_PAGE` from microsoft/playwright#39840 fixed `route-web-socket.spec.ts` arraybuffer hangs — apparently some browser changed the WebSocket origin policy on `about:blank`).
3. When porting an upstream fix, mirror the helper signature change rather than hard-coding workarounds. E.g. if upstream added a `server` parameter to `setupWS`, do the same in Java by injecting `Server server` via the JUnit fixture (`@FixtureTest` already wires up `ServerLifecycle`, so adding `Server server` to the test method signature is enough — no class-level boilerplate). Watch for local-variable shadowing when you add a `Server server` parameter to a method that already has a `WebSocketRoute server` local; rename the local.
24 changes: 18 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ jobs:
with:
distribution: zulu
java-version: 8
- name: Download drivers
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- name: Build the driver
shell: bash
run: scripts/download_driver.sh
run: scripts/build_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Install browsers
Expand Down Expand Up @@ -81,9 +85,13 @@ jobs:
with:
distribution: zulu
java-version: 8
- name: Download drivers
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- name: Build the driver
shell: bash
run: scripts/download_driver.sh
run: scripts/build_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
- name: Install browsers
Expand All @@ -109,9 +117,13 @@ jobs:
with:
distribution: temurin
java-version: 25
- name: Download drivers
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- name: Build the driver
shell: bash
run: scripts/download_driver.sh
run: scripts/build_driver.sh
- name: Build & Install
run: mvn -B install -D skipTests --no-transfer-progress
# Runs on JDK 25: with JDK 8 the javadoc plugin never uses the module path.
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/test_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ jobs:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Download drivers
run: scripts/download_driver.sh
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- name: Build the driver
run: scripts/build_driver.sh
- name: Intall Playwright
run: mvn install -D skipTests --no-transfer-progress
- name: Test CLI
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
arch: arm64
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
- name: Build Docker image
run: |
bash utils/docker/build.sh --${{ matrix.arch }} ${{ matrix.flavor }} playwright-java:localbuild-${{ matrix.flavor }}
Expand Down Expand Up @@ -65,6 +69,8 @@ jobs:

- name: Copy repository inside docker container
run: |
# The container does not need .upstream/, and it is large.
rm -rf .upstream
docker cp . "$CONTAINER_ID":/home/pwuser/playwright
# build.sh installed the SNAPSHOT artifacts into the local Maven repository
# of the runner; give them to pwuser so the test projects resolve them.
Expand Down
Loading
Loading