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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void dispose(DisposeOptions options) {
}
disposeReason = options.reason;
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
sendMessage("dispose", params);
sendMessage("dispose", params, NO_TIMEOUT);
}

@Override
Expand Down Expand Up @@ -131,7 +131,6 @@ private APIResponse fetchImpl(String url, RequestOptionsImpl options) {
if (options.multipart != null) {
params.add("multipartData", serializeMultipartData(options.multipart.fields));
}
params.addProperty("timeout", timeoutSettings.timeout(options.timeout));
if (options.failOnStatusCode != null) {
params.addProperty("failOnStatusCode", options.failOnStatusCode);
}
Expand All @@ -150,7 +149,7 @@ private APIResponse fetchImpl(String url, RequestOptionsImpl options) {
}
params.addProperty("maxRetries", options.maxRetries);
}
JsonObject json = sendMessage("fetch", params).getAsJsonObject();
JsonObject json = sendMessage("fetch", params, timeoutSettings.timeout(options.timeout)).getAsJsonObject();
return new APIResponseImpl(this, json.getAsJsonObject("response"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.util.List;

import static com.microsoft.playwright.impl.ChannelOwner.NO_TIMEOUT;
import static com.microsoft.playwright.impl.Serialization.gson;
import static com.microsoft.playwright.impl.Utils.addToProtocol;

Expand Down Expand Up @@ -60,14 +61,17 @@ public APIRequestContextImpl newContext(NewContextOptions options) {
}
List<ClientCertificate> clientCertificateList = options.clientCertificates;
options.clientCertificates = null;
Double timeout = options.timeout;
// Timeout is handled on the client.
options.timeout = null;
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
if (storageState != null) {
params.add("storageState", storageState);
}
addToProtocol(params, clientCertificateList);
JsonObject result = playwright.sendMessage("newRequest", params).getAsJsonObject();
JsonObject result = playwright.sendMessage("newRequest", params, NO_TIMEOUT).getAsJsonObject();
APIRequestContextImpl context = playwright.connection.getExistingObject(result.getAsJsonObject("request").get("guid").getAsString());
context.timeoutSettings.setDefaultTimeout(options.timeout);
context.timeoutSettings.setDefaultTimeout(timeout);
return context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;

import static com.microsoft.playwright.impl.ChannelOwner.NO_TIMEOUT;
import static com.microsoft.playwright.impl.Serialization.gson;
import static com.microsoft.playwright.impl.Utils.isSafeCloseError;
import static java.util.Arrays.asList;
Expand All @@ -48,7 +49,7 @@ public byte[] body() {
try {
JsonObject params = new JsonObject();
params.addProperty("fetchUid", fetchUid());
JsonObject json = context.sendMessage("fetchResponseBody", params).getAsJsonObject();
JsonObject json = context.sendMessage("fetchResponseBody", params, NO_TIMEOUT).getAsJsonObject();
if (!json.has("binary")) {
throw new PlaywrightException("Response has been disposed");
}
Expand All @@ -65,7 +66,7 @@ public byte[] body() {
public void dispose() {
JsonObject params = new JsonObject();
params.addProperty("fetchUid", fetchUid());
context.sendMessage("disposeAPIResponse", params);
context.sendMessage("disposeAPIResponse", params, NO_TIMEOUT);
}

@Override
Expand Down Expand Up @@ -111,7 +112,7 @@ String fetchUid() {
List<String> fetchLog() {
JsonObject params = new JsonObject();
params.addProperty("fetchUid", fetchUid());
JsonObject json = context.sendMessage("fetchLog", params).getAsJsonObject();
JsonObject json = context.sendMessage("fetchLog", params, NO_TIMEOUT).getAsJsonObject();
JsonArray log = json.get("log").getAsJsonArray();
return gson().fromJson(log, new TypeToken<List<String>>() {}.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ public void saveAs(Path path) {

JsonObject params = new JsonObject();
params.addProperty("path", path.toString());
sendMessage("saveAs", params);
sendMessage("saveAs", params, NO_TIMEOUT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ void call(BindingCallback binding) {

JsonObject params = new JsonObject();
params.add("result", gson().toJsonTree(serializeArgument(result)));
sendMessage("resolve", params);
sendMessage("resolve", params, NO_TIMEOUT);
} catch (RuntimeException exception) {
JsonObject params = new JsonObject();
params.add("error", gson().toJsonTree(serializeError(exception)));
sendMessage("reject", params);
sendMessage("reject", params, NO_TIMEOUT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ enum EventType {
request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
request.timeoutSettings = timeoutSettings;
clock = new ClockImpl(this);
closePromise = new WaitableEvent<>(listeners, EventType.CLOSE);
closePromise = new WaitableEvent<>(listeners, EventType.CLOSE);
}

Path videosDir() {
Expand All @@ -121,7 +121,7 @@ URL baseUrl() {
}
return null;
}

String effectiveCloseReason() {
if (closeReason != null) {
return closeReason;
Expand Down Expand Up @@ -261,15 +261,15 @@ private Page waitForPageImpl(WaitForPageOptions options, Runnable code) {
public CDPSession newCDPSession(Page page) {
JsonObject params = new JsonObject();
params.add("page", ((PageImpl) page).toProtocolRef());
JsonObject result = sendMessage("newCDPSession", params).getAsJsonObject();
JsonObject result = sendMessage("newCDPSession", params, NO_TIMEOUT).getAsJsonObject();
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
}

@Override
public CDPSession newCDPSession(Frame frame) {
JsonObject params = new JsonObject();
params.add("frame", ((FrameImpl) frame).toProtocolRef());
JsonObject result = sendMessage("newCDPSession", params).getAsJsonObject();
JsonObject result = sendMessage("newCDPSession", params, NO_TIMEOUT).getAsJsonObject();
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
}

Expand All @@ -285,7 +285,7 @@ public void close(CloseOptions options) {
for (Map.Entry<String, HarRecorder> entry : harRecorders.entrySet()) {
JsonObject params = new JsonObject();
params.addProperty("harId", entry.getKey());
JsonObject json = sendMessage("harExport", params).getAsJsonObject();
JsonObject json = sendMessage("harExport", params, NO_TIMEOUT).getAsJsonObject();
ArtifactImpl artifact = connection.getExistingObject(json.getAsJsonObject("artifact").get("guid").getAsString());
// Server side will compress artifact if content is attach or if file is .zip.
HarRecorder harParams = entry.getValue();
Expand All @@ -297,14 +297,14 @@ public void close(CloseOptions options) {
JsonObject unzipParams = new JsonObject();
unzipParams.addProperty("zipFile", tmpPath);
unzipParams.addProperty("harFile", harParams.path.toString());
connection.localUtils.sendMessage("harUnzip", unzipParams);
connection.localUtils.sendMessage("harUnzip", unzipParams, NO_TIMEOUT);
} else {
artifact.saveAs(harParams.path);
}
artifact.delete();
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
sendMessage("close", params);
sendMessage("close", params, NO_TIMEOUT);
}
runUntil(() -> {}, closePromise);
}
Expand All @@ -319,14 +319,14 @@ public List<Cookie> cookies(String url) {
public void addCookies(List<Cookie> cookies) {
JsonObject params = new JsonObject();
params.add("cookies", gson().toJsonTree(cookies));
sendMessage("addCookies", params);
sendMessage("addCookies", params, NO_TIMEOUT);
}

@Override
public void addInitScript(String script) {
JsonObject params = new JsonObject();
params.addProperty("source", script);
sendMessage("addInitScript", params);
sendMessage("addInitScript", params, NO_TIMEOUT);
}

@Override
Expand Down Expand Up @@ -358,7 +358,7 @@ public void clearCookies(ClearCookiesOptions options) {
setStringOrRegex(params, "name", options.name);
setStringOrRegex(params, "domain", options.domain);
setStringOrRegex(params, "path", options.path);
sendMessage("clearCookies", params);
sendMessage("clearCookies", params, NO_TIMEOUT);
}

private static void setStringOrRegex(JsonObject params, String name, Object value) {
Expand All @@ -383,7 +383,7 @@ public List<Cookie> cookies(List<String> urls) {
urls = new ArrayList<>();
}
params.add("urls", gson().toJsonTree(urls));
JsonObject json = sendMessage("cookies", params).getAsJsonObject();
JsonObject json = sendMessage("cookies", params, NO_TIMEOUT).getAsJsonObject();
Cookie[] cookies = gson().fromJson(json.getAsJsonArray("cookies"), Cookie[].class);
return asList(cookies);
}
Expand All @@ -409,7 +409,7 @@ private void exposeBindingImpl(String name, BindingCallback playwrightBinding, E
if (options != null && options.handle != null && options.handle) {
params.addProperty("needsHandle", true);
}
sendMessage("exposeBinding", params);
sendMessage("exposeBinding", params, NO_TIMEOUT);
}

@Override
Expand All @@ -427,7 +427,7 @@ public void grantPermissions(List<String> permissions, GrantPermissionsOptions o
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.add("permissions", gson().toJsonTree(permissions));
sendMessage("grantPermissions", params);
sendMessage("grantPermissions", params, NO_TIMEOUT);
}

@Override
Expand Down Expand Up @@ -517,13 +517,13 @@ void recordIntoHar(PageImpl page, Path har, RouteFromHAROptions options, HarCont
params.add("page", page.toProtocolRef());
}
JsonObject recordHarArgs = new JsonObject();
recordHarArgs.addProperty("zip", har.toString().endsWith(".zip"));
recordHarArgs.addProperty("zip", har.toString().endsWith(".zip"));
recordHarArgs.addProperty("content", contentPolicy.name().toLowerCase());
recordHarArgs.addProperty("mode", (options.updateMode == null ? HarMode.MINIMAL : options.updateMode).name().toLowerCase());
addHarUrlFilter(recordHarArgs, options.url);

params.add("options", recordHarArgs);
JsonObject json = sendMessage("harStart", params).getAsJsonObject();
JsonObject json = sendMessage("harStart", params, NO_TIMEOUT).getAsJsonObject();
String harId = json.get("harId").getAsString();
harRecorders.put(harId, new HarRecorder(har, contentPolicy));
}
Expand All @@ -549,7 +549,7 @@ public void setExtraHTTPHeaders(Map<String, String> headers) {
jsonHeaders.add(header);
}
params.add("headers", jsonHeaders);
sendMessage("setExtraHTTPHeaders", params);
sendMessage("setExtraHTTPHeaders", params, NO_TIMEOUT);
}

@Override
Expand All @@ -558,14 +558,14 @@ public void setGeolocation(Geolocation geolocation) {
if (geolocation != null) {
params.add("geolocation", gson().toJsonTree(geolocation));
}
sendMessage("setGeolocation", params);
sendMessage("setGeolocation", params, NO_TIMEOUT);
}

@Override
public void setOffline(boolean offline) {
JsonObject params = new JsonObject();
params.addProperty("offline", offline);
sendMessage("setOffline", params);
sendMessage("setOffline", params, NO_TIMEOUT);
}

@Override
Expand All @@ -575,7 +575,7 @@ public String storageState(StorageStateOptions options) {
}
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.remove("path");
JsonElement json = sendMessage("storageState", params);
JsonElement json = sendMessage("storageState", params, NO_TIMEOUT);

String storageState = json.toString();
if (options.path != null) {
Expand Down Expand Up @@ -648,11 +648,11 @@ private void unroute(UrlMatcher matcher, Consumer<Route> handler) {
}

private void updateInterceptionPatterns() {
sendMessage("setNetworkInterceptionPatterns", routes.interceptionPatterns());
sendMessage("setNetworkInterceptionPatterns", routes.interceptionPatterns(), NO_TIMEOUT);
}

private void updateWebSocketInterceptionPatterns() {
sendMessage("setWebSocketInterceptionPatterns", webSocketRoutes.interceptionPatterns());
sendMessage("setWebSocketInterceptionPatterns", webSocketRoutes.interceptionPatterns(), NO_TIMEOUT);
}

void handleRoute(RouteImpl route) {
Expand Down Expand Up @@ -817,7 +817,7 @@ WritableStream createTempFile(String name, long lastModifiedMs) {
JsonObject params = new JsonObject();
params.addProperty("name", name);
params.addProperty("lastModifiedMs", lastModifiedMs);
JsonObject json = sendMessage("createTempFile", params).getAsJsonObject();
JsonObject json = sendMessage("createTempFile", params, NO_TIMEOUT).getAsJsonObject();
return connection.getExistingObject(json.getAsJsonObject("writableStream").get("guid").getAsString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public BrowserContextImpl newContext(NewContextOptions options) {
options.recordHarPath = null;
options.recordHarOmitContent = null;
options.recordHarUrlFilter = null;

if (options.storageStatePath != null) {
try {
byte[] bytes = Files.readAllBytes(options.storageStatePath);
Expand Down Expand Up @@ -171,7 +171,7 @@ public BrowserContextImpl newContext(NewContextOptions options) {
}
params.add("selectorEngines", gson().toJsonTree(browserType.playwright.selectors.selectorEngines));
params.addProperty("testIdAttributeName", browserType.playwright.selectors.testIdAttributeName);
JsonElement result = sendMessage("newContext", params);
JsonElement result = sendMessage("newContext", params, NO_TIMEOUT);
BrowserContextImpl context = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("context").get("guid").getAsString());
context.initializeHarFromOptions(harOptions);
return context;
Expand All @@ -192,7 +192,7 @@ public void startTracing(Page page, StartTracingOptions options) {
if (page != null) {
params.add("page", ((PageImpl) page).toProtocolRef());
}
sendMessage("startTracing", params);
sendMessage("startTracing", params, NO_TIMEOUT);
}

@Override
Expand Down Expand Up @@ -250,7 +250,7 @@ void handleEvent(String event, JsonObject parameters) {
@Override
public CDPSession newBrowserCDPSession() {
JsonObject params = new JsonObject();
JsonObject result = sendMessage("newBrowserCDPSession", params).getAsJsonObject();
JsonObject result = sendMessage("newBrowserCDPSession", params, NO_TIMEOUT).getAsJsonObject();
return connection.getExistingObject(result.getAsJsonObject("session").get("guid").getAsString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public BrowserImpl launch(LaunchOptions options) {
if (options == null) {
options = new LaunchOptions();
}
options.timeout = TimeoutSettings.launchTimeout(options.timeout);
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
JsonElement result = sendMessage("launch", params);
JsonElement result = sendMessage("launch", params, TimeoutSettings.launchTimeout(options.timeout));
BrowserImpl browser = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("browser").get("guid").getAsString());
browser.browserType = this;
browser.launchOptions = options;
Expand Down Expand Up @@ -77,11 +76,12 @@ public Browser connect(String wsEndpoint, ConnectOptions options) {
headers.addProperty("x-playwright-browser", name());
}

if (!params.has("timeout")) {
params.addProperty("timeout", 0);
Double timeout = options.timeout;
if (timeout == null) {
timeout = 0.0;
}

JsonObject json = connection.localUtils().sendMessage("connect", params).getAsJsonObject();
JsonObject json = connection.localUtils().sendMessage("connect", params, timeout).getAsJsonObject();
JsonPipe pipe = connection.getExistingObject(json.getAsJsonObject("pipe").get("guid").getAsString());
Connection connection = new Connection(pipe, this.connection.env, this.connection.localUtils);
PlaywrightImpl playwright = connection.initializePlaywright();
Expand Down Expand Up @@ -118,11 +118,10 @@ public Browser connectOverCDP(String endpointURL, ConnectOverCDPOptions options)
if (options == null) {
options = new ConnectOverCDPOptions();
}
options.timeout = TimeoutSettings.launchTimeout(options.timeout);

JsonObject params = gson().toJsonTree(options).getAsJsonObject();
params.addProperty("endpointURL", endpointURL);
JsonObject json = sendMessage("connectOverCDP", params).getAsJsonObject();
JsonObject json = sendMessage("connectOverCDP", params, TimeoutSettings.launchTimeout(options.timeout)).getAsJsonObject();

BrowserImpl browser = connection.getExistingObject(json.getAsJsonObject("browser").get("guid").getAsString());
browser.connectToBrowserType(this, null);
Expand All @@ -149,8 +148,6 @@ public BrowserContextImpl launchPersistentContext(Path userDataDir, LaunchPersis
options.recordHarOmitContent = null;
options.recordHarUrlFilter = null;

options.timeout = TimeoutSettings.launchTimeout(options.timeout);

JsonObject params = gson().toJsonTree(options).getAsJsonObject();
if (!userDataDir.isAbsolute() && !userDataDir.toString().isEmpty()) {
Path cwd = Paths.get("").toAbsolutePath();
Expand Down Expand Up @@ -186,7 +183,7 @@ public BrowserContextImpl launchPersistentContext(Path userDataDir, LaunchPersis
}
params.add("selectorEngines", gson().toJsonTree(playwright.selectors.selectorEngines));
params.addProperty("testIdAttributeName", playwright.selectors.testIdAttributeName);
JsonObject json = sendMessage("launchPersistentContext", params).getAsJsonObject();
JsonObject json = sendMessage("launchPersistentContext", params, TimeoutSettings.launchTimeout(options.timeout)).getAsJsonObject();
BrowserImpl browser = connection.getExistingObject(json.getAsJsonObject("browser").get("guid").getAsString());
browser.connectToBrowserType(this, options.tracesDir);
BrowserContextImpl context = connection.getExistingObject(json.getAsJsonObject("context").get("guid").getAsString());
Expand Down
Loading
Loading