Skip to content

Commit afd80ad

Browse files
authored
chore: roll to 1.59.0-alpha (#1900)
1 parent 605e428 commit afd80ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1816
-251
lines changed

.claude/skills/playwright-roll/SKILL.md

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Roll Playwright Java to a new version
66
Help the user roll to a new version of Playwright.
77
ROLLING.md contains general instructions and scripts.
88

9-
Start with updating the version and generating the API to see the state of things.
9+
Start with running ./scripts/roll_driver.sh to update the version and generate the API to see the state of things.
1010
Afterwards, work through the list of changes that need to be backported.
1111
You can find a list of pull requests that might need to be taking into account in the issue titled "Backport changes".
1212
Work through them one-by-one and check off the items that you have handled.
@@ -16,6 +16,126 @@ Rolling includes:
1616
- updating client implementation to match changes in the upstream JS implementation (see ../playwright/packages/playwright-core/src/client)
1717
- adding a couple of new tests to verify new/changed functionality
1818

19+
## Mimicking the JavaScript implementation
20+
21+
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:
22+
23+
```
24+
../playwright/packages/playwright-core/src/client/browserContext.ts
25+
../playwright/packages/playwright-core/src/client/page.ts
26+
../playwright/packages/playwright-core/src/client/tracing.ts
27+
../playwright/packages/playwright-core/src/client/video.ts
28+
../playwright/packages/playwright-core/src/client/locator.ts
29+
../playwright/packages/playwright-core/src/client/network.ts
30+
...
31+
```
32+
33+
Key translation rules:
34+
35+
**Protocol calls**`await this._channel.methodName(params)``sendMessage("methodName", params, NO_TIMEOUT)`
36+
37+
**Extracting a returned channel object from a result** — JS uses `SomeClass.from(result.foo)` which resolves the JS-side object for a channel reference. In Java, the object was already created when the server sent `__create__`, so extract it from the connection: `connection.getExistingObject(result.getAsJsonObject("foo").get("guid").getAsString())`
38+
39+
**Async/await** — all `await` calls become synchronous `sendMessage(...)` calls since the Java client is synchronous.
40+
41+
**`undefined` / optional params** — JS `options?.foo` checks translate to `if (options != null && options.foo != null)` null checks before adding to the params `JsonObject`.
42+
43+
**`_channel` fields** — the JS `this._channel.foo` maps to calling `sendMessage("foo", ...)` on `this` in the Impl class.
44+
45+
**Channel object references in params** — when a JS call passes a channel object as a param (e.g. `{ frame: frame._channel }`), in Java pass the guid: `params.addProperty("frame", ((FrameImpl) frame).guid)`.
46+
47+
## Fixing generator and compilation errors
48+
49+
After running `./scripts/roll_driver.sh`, the build often fails because the generated Java interfaces reference new types or methods that the generator doesn't know how to handle yet, and the `*Impl` classes don't implement new interface methods.
50+
51+
### ApiGenerator.java fixes (tools/api-generator/src/main/java/com/microsoft/playwright/tools/ApiGenerator.java)
52+
53+
The generator has hardcoded lists that control which imports are added to each generated file. When new classes appear in the API, add them to the relevant lists in `Interface.writeTo`:
54+
- `options.*` import list — add new classes that use types from the options package
55+
- `java.util.*` import list — add new classes that use `List`, `Map`, etc.
56+
- `java.util.function.Consumer` list — add new classes with `Consumer`-typed event handlers
57+
58+
Type mapping: when JS-only types (like `Disposable`) are used as return types in Java-compatible methods, add a mapping in `convertBuiltinType`. For example, `Disposable``AutoCloseable`.
59+
60+
Event handler generation: events with `void` type generate invalid `Consumer<void>`. Handle this case in `Event.writeListenerMethods` by emitting `Runnable` instead.
61+
62+
After editing the generator, recompile and re-run it:
63+
```
64+
mvn -f tools/api-generator/pom.xml compile -q
65+
mvn -f tools/api-generator/pom.xml exec:java -Dexec.mainClass=com.microsoft.playwright.tools.ApiGenerator
66+
```
67+
68+
### Impl class fixes (playwright/src/main/java/com/microsoft/playwright/impl/)
69+
70+
After regenerating, compile `playwright/` to find what's missing:
71+
```
72+
mvn -f playwright/pom.xml compile 2>&1 | grep "ERROR"
73+
```
74+
75+
Common patterns:
76+
77+
**Return type changed (e.g. `void``AutoCloseable`):** Update the method signature in the Impl class and return an appropriate `AutoCloseable`. Check the JS client to see what kind of disposable is used:
78+
- If JS returns `DisposableObject.from(result.disposable)` — the server created a disposable channel object. Extract its guid from the protocol result and return `connection.getExistingObject(guid)` (a `DisposableObject`).
79+
- If JS returns `new DisposableStub(() => this.someCleanup())` — it's a local callback. Return `new DisposableStub(this::someCleanup)` in Java.
80+
- Examples: `addInitScript`/`exposeBinding`/`exposeFunction``DisposableObject`; `route(...)``DisposableStub(() -> unroute(...))`; `Tracing.group``DisposableStub(this::groupEnd)`; `Video.start``DisposableStub(this::stop)`.
81+
82+
**New method missing:** Add a stub implementation. Common patterns:
83+
- Simple protocol message: `sendMessage("methodName", params, NO_TIMEOUT)`
84+
- New property accessor (e.g. from initializer): `return initializer.get("fieldName").getAsString()`
85+
- Delegation to mainFrame (for Page methods): `return mainFrame.locator(":root").method(...)`
86+
87+
**New interface entirely (e.g. `Debugger`):** Create a new `*Impl` class extending `ChannelOwner`, implement the interface, and register the type in `Connection.java`'s switch statement. Initialize the field from the parent's initializer in the parent's constructor (e.g. `connection.getExistingObject(initializer.getAsJsonObject("debugger").get("guid").getAsString())`).
88+
89+
**Field visibility:** If a field needs to be accessed from a sibling Impl class (e.g. setting `existingResponse` on `RequestImpl` from `BrowserContextImpl`), change it from `private` to package-private.
90+
91+
**`ListenerCollection` only supports `Consumer<T>`, not `Runnable`.** For void events that use `Runnable` handlers, maintain a plain `List<Runnable>` instead.
92+
93+
**Protocol changes that remove events** — when a method's response now returns an object directly instead of via a subsequent event, update the Impl to capture it from the `sendMessage` result and remove the old event handler. Example: `videoStart` used to fire a `"video"` page event to deliver the artifact; it now returns the artifact directly in the response. Check git history of the upstream JS client when tests hang unexpectedly.
94+
95+
**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/src/protocol.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.
96+
97+
## Porting and verifying tests
98+
99+
**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.
100+
101+
**Java test file names don't always match upstream spec names.** `TestScreencast.java` tests `recordVideo` video-file recording (which corresponds to `video.spec.ts`), not the newer `page.screencast` streaming API (`screencast.spec.ts`). When comparing coverage, check test *content*, not just file names.
102+
103+
**Remove tests for behavior that was removed upstream.** When the JS client drops a client-side error check (e.g., "Page is not yet closed before saveAs", "Page did not produce any video frames"), delete the corresponding Java tests rather than trying to keep them passing. Check the upstream `tests/library/` spec to confirm the behavior is gone.
104+
105+
**Run the full suite to catch regressions, re-run flaky failures in isolation.** Some tests (e.g., `TestClientCertificates#shouldKeepSupportingHttp`) time out only under heavy parallel load. Run the failing test alone to confirm it's flaky before investigating further.
106+
107+
## Commit Convention
108+
109+
Semantic commit messages: `label(scope): description`
110+
111+
Labels: `fix`, `feat`, `chore`, `docs`, `test`, `devops`
112+
113+
```bash
114+
git checkout -b fix-39562
115+
# ... make changes ...
116+
git add <changed-files>
117+
git commit -m "$(cat <<'EOF'
118+
fix(proxy): handle SOCKS proxy authentication
119+
120+
Fixes: https://github.com/microsoft/playwright-java/issues/39562
121+
EOF
122+
)"
123+
git push origin fix-39562
124+
gh pr create --repo microsoft/playwright-java --head username:fix-39562 \
125+
--title "fix(proxy): handle SOCKS proxy authentication" \
126+
--body "$(cat <<'EOF'
127+
## Summary
128+
- <describe the change very! briefly>
129+
130+
Fixes https://github.com/microsoft/playwright-java/issues/39562
131+
EOF
132+
)"
133+
```
134+
135+
Never add Co-Authored-By agents in commit message.
136+
Never add "Generated with" in commit message.
137+
Branch naming for issue fixes: `fix-<issue-number>`
138+
19139
## Tips & Tricks
20140
- Project checkouts are in the parent directory (`../`).
21141
- When updating checkboxes, store the issue content into /tmp and edit it there, then update the issue based on the file

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
1010

1111
| | Linux | macOS | Windows |
1212
| :--- | :---: | :---: | :---: |
13-
| Chromium <!-- GEN:chromium-version -->145.0.7632.6<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
13+
| Chromium <!-- GEN:chromium-version -->146.0.7680.31<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1414
| WebKit <!-- GEN:webkit-version -->26.0<!-- GEN:stop --> ||||
15-
| Firefox <!-- GEN:firefox-version -->146.0.1<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
15+
| Firefox <!-- GEN:firefox-version -->148.0.2<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1616

1717
## Documentation
1818

ROLLING.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
* make sure to have at least Java 8 and Maven 3.6.3
44
* clone playwright for java: http://github.com/microsoft/playwright-java
5-
* `./scripts/roll_driver.sh 1.47.0-beta-1726138322000`
5+
* roll the driver and update generated sources: `./scripts/roll_driver.sh next`
6+
* fix any errors
67
* commit & send PR with the roll
7-
8-
## Finding driver version
9-
10-
For development versions of Playwright, you can find the latest version by looking at [publish_canary](https://github.com/microsoft/playwright/actions/workflows/publish_canary.yml) workflow -> `publish canary NPM & Publish canary Docker` -> `build & publish driver` step -> `PACKAGE_VERSION`
11-
<img width="960" alt="image" src="https://github.com/microsoft/playwright-java/assets/9798949/4f33a7f1-b39a-4179-8ae7-fb1d84094c75">
12-
13-
14-
# Updating Version
15-
16-
```bash
17-
./scripts/set_maven_version.sh 1.15.0
18-
```
19-

0 commit comments

Comments
 (0)