Skip to content

Commit 880f7bb

Browse files
committed
chore: roll to 1.59.0-alpha-1774622285000
- Add Overlay API (page.overlay()) with show/chapter/setVisible - Add Debugger.requestPause(), change pausedDetails() to return single PausedDetails - Fix Video.start() to handle path option locally and pass annotate/size to protocol - Fix Response.httpVersion() to call protocol method - Fix ResponseImpl to set request.existingResponse in constructor - Fix TracingImpl to track additionalSources from group() locations - Fix DialogImpl.dismiss() to swallow TargetClosedErrors for beforeunload dialogs - Fix HarRouter to merge set-cookie headers - Fix ConsoleMessagesFilter.SINCE_NAVIGATION serialization to kebab-case - Fix Locator.normalize() to use resolveSelector protocol message
1 parent afd80ad commit 880f7bb

File tree

19 files changed

+361
-59
lines changed

19 files changed

+361
-59
lines changed

playwright/src/main/java/com/microsoft/playwright/Debugger.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ public interface Debugger {
3535
void offPausedStateChanged(Runnable handler);
3636

3737
/**
38-
* Returns details about the currently paused calls. Returns an empty array if the debugger is not paused.
38+
* Returns details about the currently paused call. Returns {@code null} if the debugger is not paused.
3939
*
4040
* @since v1.59
4141
*/
42-
List<PausedDetails> pausedDetails();
42+
PausedDetails pausedDetails();
4343
/**
4444
* Configures the debugger to pause before the next action is executed.
4545
*
4646
* <p> Throws if the debugger is already paused. Use {@link com.microsoft.playwright.Debugger#next Debugger.next()} or {@link
4747
* com.microsoft.playwright.Debugger#runTo Debugger.runTo()} to step while paused.
4848
*
4949
* <p> Note that {@link com.microsoft.playwright.Page#pause Page.pause()} is equivalent to a "debugger" statement — it pauses
50-
* execution at the call site immediately. On the contrary, {@link com.microsoft.playwright.Debugger#pause
51-
* Debugger.pause()} is equivalent to "pause on next statement" — it configures the debugger to pause before the next
52-
* action is executed.
50+
* execution at the call site immediately. On the contrary, {@link com.microsoft.playwright.Debugger#requestPause
51+
* Debugger.requestPause()} is equivalent to "pause on next statement" — it configures the debugger to pause before the
52+
* next action is executed.
5353
*
5454
* @since v1.59
5555
*/
56-
void pause();
56+
void requestPause();
5757
/**
5858
* Resumes script execution. Throws if the debugger is not paused.
5959
*

playwright/src/main/java/com/microsoft/playwright/Locator.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class AriaSnapshotOptions {
3535
*/
3636
public Integer depth;
3737
/**
38-
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption with element references. Defaults to {@code
39-
* "default"}.
38+
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption. Defaults to {@code "default"}. See details
39+
* for more information.
4040
*/
4141
public AriaSnapshotMode mode;
4242
/**
@@ -55,8 +55,8 @@ public AriaSnapshotOptions setDepth(int depth) {
5555
return this;
5656
}
5757
/**
58-
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption with element references. Defaults to {@code
59-
* "default"}.
58+
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption. Defaults to {@code "default"}. See details
59+
* for more information.
6060
*/
6161
public AriaSnapshotOptions setMode(AriaSnapshotMode mode) {
6262
this.mode = mode;
@@ -2322,6 +2322,12 @@ public WaitForOptions setTimeout(double timeout) {
23222322
*
23232323
* <p> Below is the HTML markup and the respective ARIA snapshot:
23242324
*
2325+
* <p> An AI-optimized snapshot, controlled by {@code mode}, is different from a default snapshot:
2326+
* <ol>
2327+
* <li> Includes element references {@code [ref=e2]}. 2. Does not wait for an element matching the locator, and throws when no
2328+
* elements match. 3. Includes snapshots of {@code <iframe>}s inside the target.</li>
2329+
* </ol>
2330+
*
23252331
* @since v1.49
23262332
*/
23272333
default String ariaSnapshot() {
@@ -2353,6 +2359,12 @@ default String ariaSnapshot() {
23532359
*
23542360
* <p> Below is the HTML markup and the respective ARIA snapshot:
23552361
*
2362+
* <p> An AI-optimized snapshot, controlled by {@code mode}, is different from a default snapshot:
2363+
* <ol>
2364+
* <li> Includes element references {@code [ref=e2]}. 2. Does not wait for an element matching the locator, and throws when no
2365+
* elements match. 3. Includes snapshots of {@code <iframe>}s inside the target.</li>
2366+
* </ol>
2367+
*
23562368
* @since v1.49
23572369
*/
23582370
String ariaSnapshot(AriaSnapshotOptions options);
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.microsoft.playwright;
18+
19+
20+
/**
21+
* Interface for managing page overlays that display persistent visual indicators on top of the page.
22+
*/
23+
public interface Overlay {
24+
class ShowOptions {
25+
/**
26+
* Duration in milliseconds after which the overlay is automatically removed. Overlay stays until dismissed if not
27+
* provided.
28+
*/
29+
public Double duration;
30+
31+
/**
32+
* Duration in milliseconds after which the overlay is automatically removed. Overlay stays until dismissed if not
33+
* provided.
34+
*/
35+
public ShowOptions setDuration(double duration) {
36+
this.duration = duration;
37+
return this;
38+
}
39+
}
40+
class ChapterOptions {
41+
/**
42+
* Optional description text displayed below the title.
43+
*/
44+
public String description;
45+
/**
46+
* Duration in milliseconds after which the overlay is automatically removed. Defaults to {@code 2000}.
47+
*/
48+
public Double duration;
49+
50+
/**
51+
* Optional description text displayed below the title.
52+
*/
53+
public ChapterOptions setDescription(String description) {
54+
this.description = description;
55+
return this;
56+
}
57+
/**
58+
* Duration in milliseconds after which the overlay is automatically removed. Defaults to {@code 2000}.
59+
*/
60+
public ChapterOptions setDuration(double duration) {
61+
this.duration = duration;
62+
return this;
63+
}
64+
}
65+
/**
66+
* Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a
67+
* disposable that removes the overlay when disposed.
68+
*
69+
* @param html HTML content for the overlay.
70+
* @since v1.59
71+
*/
72+
default AutoCloseable show(String html) {
73+
return show(html, null);
74+
}
75+
/**
76+
* Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a
77+
* disposable that removes the overlay when disposed.
78+
*
79+
* @param html HTML content for the overlay.
80+
* @since v1.59
81+
*/
82+
AutoCloseable show(String html, ShowOptions options);
83+
/**
84+
* Shows a chapter overlay with a title and optional description, centered on the page with a blurred backdrop. Useful for
85+
* narrating video recordings. The overlay is removed after the specified duration, or 2000ms.
86+
*
87+
* @param title Title text displayed prominently in the overlay.
88+
* @since v1.59
89+
*/
90+
default void chapter(String title) {
91+
chapter(title, null);
92+
}
93+
/**
94+
* Shows a chapter overlay with a title and optional description, centered on the page with a blurred backdrop. Useful for
95+
* narrating video recordings. The overlay is removed after the specified duration, or 2000ms.
96+
*
97+
* @param title Title text displayed prominently in the overlay.
98+
* @since v1.59
99+
*/
100+
void chapter(String title, ChapterOptions options);
101+
/**
102+
* Sets visibility of all overlays without removing them.
103+
*
104+
* @param visible Whether overlays should be visible.
105+
* @since v1.59
106+
*/
107+
void setVisible(boolean visible);
108+
}
109+

playwright/src/main/java/com/microsoft/playwright/Page.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,8 +2986,8 @@ class AriaSnapshotOptions {
29862986
*/
29872987
public Integer depth;
29882988
/**
2989-
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption with element references. Defaults to {@code
2990-
* "default"}.
2989+
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption: including element references like {@code
2990+
* [ref=e2]} and snapshots of {@code <iframe>}s. Defaults to {@code "default"}.
29912991
*/
29922992
public AriaSnapshotMode mode;
29932993
/**
@@ -3006,8 +3006,8 @@ public AriaSnapshotOptions setDepth(int depth) {
30063006
return this;
30073007
}
30083008
/**
3009-
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption with element references. Defaults to {@code
3010-
* "default"}.
3009+
* When set to {@code "ai"}, returns a snapshot optimized for AI consumption: including element references like {@code
3010+
* [ref=e2]} and snapshots of {@code <iframe>}s. Defaults to {@code "default"}.
30113011
*/
30123012
public AriaSnapshotOptions setMode(AriaSnapshotMode mode) {
30133013
this.mode = mode;
@@ -5880,6 +5880,12 @@ default Locator locator(String selector) {
58805880
* @since v1.8
58815881
*/
58825882
Mouse mouse();
5883+
/**
5884+
*
5885+
*
5886+
* @since v1.59
5887+
*/
5888+
Overlay overlay();
58835889
/**
58845890
* Adds one-off {@code Dialog} handler. The handler will be removed immediately after next {@code Dialog} is created.
58855891
* <pre>{@code

playwright/src/main/java/com/microsoft/playwright/impl/DebuggerImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616

1717
package com.microsoft.playwright.impl;
1818

19-
import com.google.gson.JsonArray;
2019
import com.google.gson.JsonObject;
2120
import com.microsoft.playwright.Debugger;
2221
import com.microsoft.playwright.options.Location;
2322
import com.microsoft.playwright.options.PausedDetails;
2423

2524
import java.util.ArrayList;
26-
import java.util.Arrays;
2725
import java.util.List;
2826

2927
import static com.microsoft.playwright.impl.Serialization.gson;
3028

3129
class DebuggerImpl extends ChannelOwner implements Debugger {
3230
private final List<Runnable> pausedStateChangedHandlers = new ArrayList<>();
33-
private List<PausedDetails> pausedDetails = new ArrayList<>();
31+
private PausedDetails pausedDetails;
3432

3533
DebuggerImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
3634
super(parent, type, guid, initializer);
@@ -39,8 +37,11 @@ class DebuggerImpl extends ChannelOwner implements Debugger {
3937
@Override
4038
protected void handleEvent(String event, JsonObject params) {
4139
if ("pausedStateChanged".equals(event)) {
42-
JsonArray details = params.getAsJsonArray("pausedDetails");
43-
pausedDetails = Arrays.asList(gson().fromJson(details, PausedDetails[].class));
40+
if (params.has("pausedDetails") && !params.get("pausedDetails").isJsonNull()) {
41+
pausedDetails = gson().fromJson(params.get("pausedDetails"), PausedDetails.class);
42+
} else {
43+
pausedDetails = null;
44+
}
4445
for (Runnable handler : new ArrayList<>(pausedStateChangedHandlers)) {
4546
handler.run();
4647
}
@@ -58,13 +59,13 @@ public void offPausedStateChanged(Runnable handler) {
5859
}
5960

6061
@Override
61-
public List<PausedDetails> pausedDetails() {
62+
public PausedDetails pausedDetails() {
6263
return pausedDetails;
6364
}
6465

6566
@Override
66-
public void pause() {
67-
sendMessage("pause", new JsonObject(), NO_TIMEOUT);
67+
public void requestPause() {
68+
sendMessage("requestPause", new JsonObject(), NO_TIMEOUT);
6869
}
6970

7071
@Override

playwright/src/main/java/com/microsoft/playwright/impl/DialogImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public void accept(String promptText) {
4343

4444
@Override
4545
public void dismiss() {
46-
sendMessage("dismiss");
46+
try {
47+
sendMessage("dismiss");
48+
} catch (TargetClosedError e) {
49+
// Swallow TargetClosedErrors for beforeunload dialogs.
50+
}
4751
}
4852

4953
@Override

playwright/src/main/java/com/microsoft/playwright/impl/HARRouter.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.microsoft.playwright.impl;
1818

19+
import com.google.gson.JsonArray;
20+
import com.google.gson.JsonElement;
1921
import com.google.gson.JsonObject;
2022
import com.microsoft.playwright.PlaywrightException;
2123
import com.microsoft.playwright.Request;
@@ -82,7 +84,7 @@ void handle(Route route) {
8284
if (status == -1) {
8385
return;
8486
}
85-
Map<String, String> headers = fromNameValues(response.getAsJsonArray("headers"));
87+
Map<String, String> headers = mergeSetCookieHeaders(response.getAsJsonArray("headers"));
8688
byte[] buffer = Base64.getDecoder().decode(response.get("body").getAsString());
8789
route.fulfill(new Route.FulfillOptions()
8890
.setStatus(status)
@@ -105,6 +107,25 @@ void handle(Route route) {
105107
route.abort();
106108
}
107109

110+
private static Map<String, String> mergeSetCookieHeaders(JsonArray headersArray) {
111+
Map<String, String> result = new java.util.LinkedHashMap<>();
112+
for (JsonElement element : headersArray) {
113+
JsonObject pair = element.getAsJsonObject();
114+
String name = pair.get("name").getAsString();
115+
String value = pair.get("value").getAsString();
116+
if ("set-cookie".equalsIgnoreCase(name)) {
117+
if (!result.containsKey("set-cookie")) {
118+
result.put("set-cookie", value);
119+
} else {
120+
result.put("set-cookie", result.get("set-cookie") + "\n" + value);
121+
}
122+
} else {
123+
result.put(name, value);
124+
}
125+
}
126+
return result;
127+
}
128+
108129
void dispose() {
109130
JsonObject params = new JsonObject();
110131
params.addProperty("harId", harId);

playwright/src/main/java/com/microsoft/playwright/impl/LocalUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ JsonArray deviceDescriptors() {
3434
return initializer.getAsJsonArray("deviceDescriptors");
3535
}
3636

37-
void zip(Path zipFile, JsonArray entries, String stacksId, boolean appendMode, boolean includeSources) {
37+
void zip(Path zipFile, JsonArray entries, String stacksId, boolean appendMode, boolean includeSources, List<String> additionalSources) {
3838
JsonObject params = new JsonObject();
3939
params.addProperty("zipFile", zipFile.toString());
4040
params.add("entries", entries);
4141
params.addProperty("mode", appendMode ? "append" : "write");
4242
params.addProperty("stacksId", stacksId);
4343
params.addProperty("includeSources", includeSources);
44+
if (!additionalSources.isEmpty()) {
45+
JsonArray sourcesArray = new JsonArray();
46+
for (String source : additionalSources) {
47+
sourcesArray.add(source);
48+
}
49+
params.add("additionalSources", sourcesArray);
50+
}
4451
sendMessage("zip", params, NO_TIMEOUT);
4552
}
4653

playwright/src/main/java/com/microsoft/playwright/impl/LocatorImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public List<String> allTextContents() {
112112
public Locator normalize() {
113113
JsonObject params = new JsonObject();
114114
params.addProperty("selector", selector);
115-
JsonObject result = frame.sendMessage("normalizeLocator", params, ChannelOwner.NO_TIMEOUT).getAsJsonObject();
116-
return new LocatorImpl(frame, result.get("selector").getAsString(), null);
115+
JsonObject result = frame.sendMessage("resolveSelector", params, ChannelOwner.NO_TIMEOUT).getAsJsonObject();
116+
return new LocatorImpl(frame, result.get("resolvedSelector").getAsString(), null);
117117
}
118118

119119
@Override

0 commit comments

Comments
 (0)