Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ public void dispose(DisposeOptions options) {
options = new DisposeOptions();
}
disposeReason = options.reason;
channel.dispose(toProtocol(options, APIRequestContextDisposeParams.class), NO_TIMEOUT);
try {
channel.dispose(toProtocol(options, APIRequestContextDisposeParams.class), NO_TIMEOUT);
} catch (TargetClosedError e) {
return;
}
tracing.resetStackCounter();
}

Expand Down Expand Up @@ -279,7 +283,7 @@ public String storageState(StorageStateOptions options) {
// that is compared with BrowserContext.storageState().
String storageState = sendMessage("storageState", connection.protocolGson().toJsonTree(params).getAsJsonObject(), NO_TIMEOUT).toString();
if (options.path != null) {
Utils.writeToFile(storageState.getBytes(StandardCharsets.UTF_8), options.path);
Utils.writeToFile(Serialization.toPrettyJson(storageState).getBytes(StandardCharsets.UTF_8), options.path);
}
return storageState;
}
Expand All @@ -296,6 +300,9 @@ private static RequestOptionsImpl ensureOptions(RequestOptions options, String m
}

private static boolean isJsonParsable(String value) {
if (value.trim().isEmpty()) {
return false;
}
try {
JsonElement result = JsonParser.parseString(value);
if (result != null && result.isJsonPrimitive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
Expand Down Expand Up @@ -84,14 +83,6 @@ public class BrowserContextImpl extends ChannelOwner implements BrowserContext {
closePromise = new WaitableEvent<>(this, Events.BrowserContext.CLOSE);
}

Path videosDir() {
JsonObject recordVideo = initializer.getAsJsonObject("options").getAsJsonObject("recordVideo");
if (recordVideo == null) {
return null;
}
return Paths.get(recordVideo.get("dir").getAsString());
}

URL baseUrl() {
JsonElement url = initializer.getAsJsonObject("options").get("baseURL");
if (url != null) {
Expand Down Expand Up @@ -632,7 +623,7 @@ public String storageState(StorageStateOptions options) {

String storageState = json.toString();
if (options.path != null) {
Utils.writeToFile(storageState.getBytes(StandardCharsets.UTF_8), options.path);
Utils.writeToFile(Serialization.toPrettyJson(storageState).getBytes(StandardCharsets.UTF_8), options.path);
}
return storageState;
}
Expand Down Expand Up @@ -729,7 +720,7 @@ void handleRoute(RouteImpl route) {
}
}
if (handled == Router.HandleResult.NoMatchingHandler || handled == Router.HandleResult.Fallback) {
route.resume(null, true);
route.continueAsFallback();
}
}

Expand Down Expand Up @@ -829,7 +820,7 @@ protected void handleEvent(String event, JsonObject params) {
request.failure = params.get("failureText").getAsString();
}
if (request.timing != null) {
request.timing.responseEnd = params.get("responseEndTiming").getAsDouble();
request.setResponseEndTiming(params.get("responseEndTiming").getAsDouble());
}
emit(Events.BrowserContext.REQUEST_FAILED, request);
if (params.has("page")) {
Expand All @@ -841,7 +832,7 @@ protected void handleEvent(String event, JsonObject params) {
RequestImpl request = connection.getExistingObject(guid);
request.didFailOrFinish = true;
if (request.timing != null) {
request.timing.responseEnd = params.get("responseEndTiming").getAsDouble();
request.setResponseEndTiming(params.get("responseEndTiming").getAsDouble());
}
emit(Events.BrowserContext.REQUEST_FINISHED, request);
if (params.has("page")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public List<String> selectOption(String[] values, SelectOptionOptions options) {
}
ElementHandleSelectOptionParams params = Utils.toProtocol(options, ElementHandleSelectOptionParams.class);
if (values != null) {
Utils.assertNoNullItems(values);
params.options = new ArrayList<>();
for (String value : values) {
ElementHandleSelectOptionParams.ElementHandleSelectOptionParamsOptions option = new ElementHandleSelectOptionParams.ElementHandleSelectOptionParamsOptions();
Expand All @@ -318,6 +319,7 @@ public List<String> selectOption(SelectOption[] values, SelectOptionOptions opti
}
ElementHandleSelectOptionParams params = Utils.toProtocol(options, ElementHandleSelectOptionParams.class);
if (values != null) {
Utils.assertNoNullItems(values);
params.options = new ArrayList<>();
for (SelectOption value : values) {
ElementHandleSelectOptionParams.ElementHandleSelectOptionParamsOptions option = new ElementHandleSelectOptionParams.ElementHandleSelectOptionParamsOptions();
Expand All @@ -337,6 +339,7 @@ public List<String> selectOption(ElementHandle[] values, SelectOptionOptions opt
}
ElementHandleSelectOptionParams params = Utils.toProtocol(options, ElementHandleSelectOptionParams.class);
if (values != null) {
Utils.assertNoNullItems(values);
params.elements = new ArrayList<>();
for (ElementHandle value : values) {
params.elements.add((ElementHandleImpl) value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@
FrameSelectOptionParams params = toProtocol(options, FrameSelectOptionParams.class);
params.selector = selector;
if (values != null) {
Utils.assertNoNullItems(values);
params.options = new ArrayList<>();
for (SelectOption value : values) {
FrameSelectOptionParams.FrameSelectOptionParamsOptions option = new FrameSelectOptionParams.FrameSelectOptionParamsOptions();
Expand All @@ -646,6 +647,7 @@
FrameSelectOptionParams params = toProtocol(options, FrameSelectOptionParams.class);
params.selector = selector;
if (values != null) {
Utils.assertNoNullItems(values);
params.options = new ArrayList<>();
for (String value : values) {
FrameSelectOptionParams.FrameSelectOptionParamsOptions option = new FrameSelectOptionParams.FrameSelectOptionParamsOptions();
Expand All @@ -668,6 +670,7 @@
FrameSelectOptionParams params = toProtocol(options, FrameSelectOptionParams.class);
params.selector = selector;
if (values != null) {
Utils.assertNoNullItems(values);
params.elements = new ArrayList<>();
for (ElementHandle handle : values) {
params.elements.add((ElementHandleImpl) handle);
Expand Down Expand Up @@ -1102,11 +1105,11 @@
return new TimeoutSettings().navigationTimeout(timeout);
}

FrameExpectResult expect(String expression, FrameExpectOptions options, String title) {

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / stable (playwright-x64-ubuntu24-64-core, chrome)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / stable (playwright-x64-ubuntu24-64-core, chrome)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, chromium)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, chromium)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, webkit)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, webkit)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, firefox)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, firefox)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, chromium)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, chromium)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, webkit)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, webkit)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, firefox)

cannot find symbol

Check failure on line 1108 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, firefox)

cannot find symbol
return withTitle(title, () -> expect(expression, options));
}

FrameExpectResult expect(String expression, FrameExpectOptions options) {

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / stable (playwright-x64-ubuntu24-64-core, chrome)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / stable (playwright-x64-ubuntu24-64-core, chrome)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, chromium)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, chromium)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, webkit)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, webkit)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, firefox)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (playwright-x64-ubuntu24-64-core, firefox)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, chromium)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, chromium)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, webkit)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, webkit)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, firefox)

cannot find symbol

Check failure on line 1112 in playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java

View workflow job for this annotation

GitHub Actions / dev (macos-26-xlarge, firefox)

cannot find symbol
FrameExpectParams params = toProtocol(this, options, FrameExpectParams.class);
params.expression = expression;
FrameExpectResult result = new FrameExpectResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,9 @@ public String url() {

@Override
public VideoImpl video() {
if (!browserContext.initializer.getAsJsonObject("options").has("recordVideo")) {
return null;
}
return video;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.microsoft.playwright.impl;

import com.microsoft.playwright.impl.protocol.*;
import com.microsoft.playwright.options.PseudoElement;
import java.util.List;

class FrameExpectOptions {
Expand All @@ -26,6 +27,7 @@ class FrameExpectOptions {
Double expectedNumber;
SerializedArgument expectedValue;
Boolean useInnerText;
PseudoElement pseudo;
boolean isNot;
Double timeout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class RequestImpl extends ChannelOwner implements Request {
boolean didFailOrFinish;
ResponseImpl existingResponse;
private FallbackOverrides fallbackOverrides;
private final FrameImpl frame;

static class FallbackOverrides {
String url;
Expand All @@ -60,6 +61,11 @@ static class FallbackOverrides {
RequestImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
super(parent, type, guid, initializer);

if (initializer.has("frame")) {
frame = connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
} else {
frame = null;
}
if (initializer.has("redirectedFrom")) {
redirectedFrom = connection.getExistingObject(initializer.getAsJsonObject("redirectedFrom").get("guid").getAsString());
redirectedFrom.redirectedTo = this;
Expand Down Expand Up @@ -87,9 +93,15 @@ public String failure() {
return failure;
}

PageImpl safePage() {
return frame == null ? null : frame.page;
}

@Override
public FrameImpl frame() {
FrameImpl frame = connection.getExistingObject(initializer.getAsJsonObject("frame").get("guid").getAsString());
if (frame == null) {
throw new PlaywrightException("Service Worker requests do not have an associated frame.");
}
if (frame.page == null) {
throw new PlaywrightException("Frame for this navigation request is not available, because the request\n" +
"was issued before the frame is created. You can check whether the request\n" +
Expand Down Expand Up @@ -218,6 +230,13 @@ private RawHeaders getRawHeaders() {
return rawHeaders;
}

void setResponseEndTiming(double responseEndTiming) {
timing.responseEnd = responseEndTiming;
if (timing.responseStart == -1) {
timing.responseStart = responseEndTiming;
}
}

void applyFallbackOverrides(FallbackOverrides overrides) {
if (fallbackOverrides == null) {
fallbackOverrides = new FallbackOverrides();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public String get() {
return request.failure();
}
});
PageImpl page = request.frame().page;
waitables.add(page.createWaitForCloseHelper());
waitables.add(page.createWaitableTimeout(null));
PageImpl page = request.safePage();
if (page != null) {
waitables.add(page.createWaitForCloseHelper());
waitables.add(page.createWaitableTimeout(null));
}
runUntil(() -> {}, new WaitableRace<>(waitables));
return request.failure();
}
Expand Down
Loading
Loading