Skip to content

chore: remove withLogging #1804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025
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 @@ -53,10 +53,6 @@ public APIResponse delete(String url, RequestOptions options) {

@Override
public void dispose(DisposeOptions options) {
withLogging("APIRequestContext.dispose", () -> disposeImpl(options));
}

private void disposeImpl(DisposeOptions options) {
if (options == null) {
options = new DisposeOptions();
}
Expand All @@ -67,7 +63,7 @@ private void disposeImpl(DisposeOptions options) {

@Override
public APIResponse fetch(String urlOrRequest, RequestOptions options) {
return withLogging("APIRequestContext.fetch", () -> fetchImpl(urlOrRequest, (RequestOptionsImpl) options));
return fetchImpl(urlOrRequest, (RequestOptionsImpl) options);
}

@Override
Expand Down Expand Up @@ -220,14 +216,12 @@ public APIResponse put(String url, RequestOptions options) {

@Override
public String storageState(StorageStateOptions options) {
return withLogging("APIRequestContext.storageState", () -> {
JsonElement json = sendMessage("storageState");
String storageState = json.toString();
if (options != null && options.path != null) {
Utils.writeToFile(storageState.getBytes(StandardCharsets.UTF_8), options.path);
}
return storageState;
});
JsonElement json = sendMessage("storageState");
String storageState = json.toString();
if (options != null && options.path != null) {
Utils.writeToFile(storageState.getBytes(StandardCharsets.UTF_8), options.path);
}
return storageState;
}

private static RequestOptionsImpl ensureOptions(RequestOptions options, String method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.microsoft.playwright.impl;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.microsoft.playwright.APIRequest;
import com.microsoft.playwright.PlaywrightException;
Expand All @@ -26,12 +25,10 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Base64;
import java.util.List;

import static com.microsoft.playwright.impl.Serialization.gson;
import static com.microsoft.playwright.impl.Utils.addToProtocol;
import static java.nio.file.Files.readAllBytes;

class APIRequestImpl implements APIRequest {
private final PlaywrightImpl playwright;
Expand All @@ -42,10 +39,6 @@ class APIRequestImpl implements APIRequest {

@Override
public APIRequestContextImpl newContext(NewContextOptions options) {
return playwright.withLogging("APIRequest.newContext", () -> newContextImpl(options));
}

private APIRequestContextImpl newContextImpl(NewContextOptions options) {
if (options == null) {
options = new NewContextOptions();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.microsoft.playwright.impl;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.microsoft.playwright.APIResponse;
Expand Down Expand Up @@ -64,11 +63,9 @@ public byte[] body() {

@Override
public void dispose() {
context.withLogging("APIResponse.dispose", () -> {
JsonObject params = new JsonObject();
params.addProperty("fetchUid", fetchUid());
context.sendMessage("disposeAPIResponse", params);
});
JsonObject params = new JsonObject();
params.addProperty("fetchUid", fetchUid());
context.sendMessage("disposeAPIResponse", params);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,6 @@ public CDPSession newCDPSession(Frame frame) {

@Override
public void close(CloseOptions options) {
withLogging("BrowserContext.close", () -> closeImpl(options));
}

@Override
public List<Cookie> cookies(String url) {
return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url));
}

private void closeImpl(CloseOptions options) {
if (!closingOrClosed) {
closingOrClosed = true;
if (options == null) {
Expand Down Expand Up @@ -318,54 +309,48 @@ private void closeImpl(CloseOptions options) {
runUntil(() -> {}, closePromise);
}

@Override
public List<Cookie> cookies(String url) {
return cookies(url == null ? new ArrayList<>() : Collections.singletonList(url));
}


@Override
public void addCookies(List<Cookie> cookies) {
withLogging("BrowserContext.addCookies", () -> {
JsonObject params = new JsonObject();
params.add("cookies", gson().toJsonTree(cookies));
sendMessage("addCookies", params);
});
JsonObject params = new JsonObject();
params.add("cookies", gson().toJsonTree(cookies));
sendMessage("addCookies", params);
}

@Override
public void addInitScript(String script) {
withLogging("BrowserContext.addInitScript", () -> addInitScriptImpl(script));
JsonObject params = new JsonObject();
params.addProperty("source", script);
sendMessage("addInitScript", params);
}

@Override
public void addInitScript(Path path) {
withLogging("BrowserContext.addInitScript", () -> {
try {
byte[] bytes = readAllBytes(path);
addInitScriptImpl(new String(bytes, UTF_8));
} catch (IOException e) {
throw new PlaywrightException("Failed to read script from file", e);
}
});
try {
byte[] bytes = readAllBytes(path);
addInitScript(new String(bytes, UTF_8));
} catch (IOException e) {
throw new PlaywrightException("Failed to read script from file", e);
}
}

@Override
public List<Page> backgroundPages() {
return new ArrayList<>(backgroundPages);
}

private void addInitScriptImpl(String script) {
JsonObject params = new JsonObject();
params.addProperty("source", script);
sendMessage("addInitScript", params);
}

@Override
public BrowserImpl browser() {
return browser;
}

@Override
public void clearCookies(ClearCookiesOptions options) {
withLogging("BrowserContext.clearCookies", () -> clearCookiesImpl(options));
}

private void clearCookiesImpl(ClearCookiesOptions options) {
if (options == null) {
options = new ClearCookiesOptions();
}
Expand All @@ -388,15 +373,11 @@ private static void setStringOrRegex(JsonObject params, String name, Object valu

@Override
public void clearPermissions() {
withLogging("BrowserContext.clearPermissions", () -> sendMessage("clearPermissions"));
sendMessage("clearPermissions");
}

@Override
public List<Cookie> cookies(List<String> urls) {
return withLogging("BrowserContext.cookies", () -> cookiesImpl(urls));
}

private List<Cookie> cookiesImpl(List<String> urls) {
JsonObject params = new JsonObject();
if (urls == null) {
urls = new ArrayList<>();
Expand All @@ -409,7 +390,7 @@ private List<Cookie> cookiesImpl(List<String> urls) {

@Override
public void exposeBinding(String name, BindingCallback playwrightBinding, ExposeBindingOptions options) {
withLogging("BrowserContext.exposeBinding", () -> exposeBindingImpl(name, playwrightBinding, options));
exposeBindingImpl(name, playwrightBinding, options);
}

private void exposeBindingImpl(String name, BindingCallback playwrightBinding, ExposeBindingOptions options) {
Expand All @@ -433,16 +414,11 @@ private void exposeBindingImpl(String name, BindingCallback playwrightBinding, E

@Override
public void exposeFunction(String name, FunctionCallback playwrightFunction) {
withLogging("BrowserContext.exposeFunction",
() -> exposeBindingImpl(name, (BindingCallback.Source source, Object... args) -> playwrightFunction.call(args), null));
exposeBindingImpl(name, (BindingCallback.Source source, Object... args) -> playwrightFunction.call(args), null);
}

@Override
public void grantPermissions(List<String> permissions, GrantPermissionsOptions options) {
withLogging("BrowserContext.grantPermissions", () -> grantPermissionsImpl(permissions, options));
}

private void grantPermissionsImpl(List<String> permissions, GrantPermissionsOptions options) {
if (options == null) {
options = new GrantPermissionsOptions();
}
Expand All @@ -456,10 +432,6 @@ private void grantPermissionsImpl(List<String> permissions, GrantPermissionsOpti

@Override
public PageImpl newPage() {
return withLogging("BrowserContext.newPage", () -> newPageImpl());
}

private PageImpl newPageImpl() {
if (ownerPage != null) {
throw new PlaywrightException("Please use browser.newContext()");
}
Expand Down Expand Up @@ -508,10 +480,8 @@ public void routeFromHAR(Path har, RouteFromHAROptions options) {
}

private void route(UrlMatcher matcher, Consumer<Route> handler, RouteOptions options) {
withLogging("BrowserContext.route", () -> {
routes.add(matcher, handler, options == null ? null : options.times);
updateInterceptionPatterns();
});
routes.add(matcher, handler, options == null ? null : options.times);
updateInterceptionPatterns();
}

@Override
Expand All @@ -530,10 +500,8 @@ public void routeWebSocket(Predicate<String> predicate, Consumer<WebSocketRoute>
}

private void routeWebSocketImpl(UrlMatcher matcher, Consumer<WebSocketRoute> handler) {
withLogging("BrowserContext.routeWebSocket", () -> {
webSocketRoutes.add(matcher, handler);
updateWebSocketInterceptionPatterns();
});
webSocketRoutes.add(matcher, handler);
updateWebSocketInterceptionPatterns();
}

void recordIntoHar(PageImpl page, Path har, RouteFromHAROptions options, HarContentPolicy contentPolicy) {
Expand Down Expand Up @@ -572,46 +540,36 @@ public void setDefaultTimeout(double timeout) {

@Override
public void setExtraHTTPHeaders(Map<String, String> headers) {
withLogging("BrowserContext.setExtraHTTPHeaders", () -> {
JsonObject params = new JsonObject();
JsonArray jsonHeaders = new JsonArray();
for (Map.Entry<String, String> e : headers.entrySet()) {
JsonObject header = new JsonObject();
header.addProperty("name", e.getKey());
header.addProperty("value", e.getValue());
jsonHeaders.add(header);
}
params.add("headers", jsonHeaders);
sendMessage("setExtraHTTPHeaders", params);
});
JsonObject params = new JsonObject();
JsonArray jsonHeaders = new JsonArray();
for (Map.Entry<String, String> e : headers.entrySet()) {
JsonObject header = new JsonObject();
header.addProperty("name", e.getKey());
header.addProperty("value", e.getValue());
jsonHeaders.add(header);
}
params.add("headers", jsonHeaders);
sendMessage("setExtraHTTPHeaders", params);
}

@Override
public void setGeolocation(Geolocation geolocation) {
withLogging("BrowserContext.setGeolocation", () -> {
JsonObject params = new JsonObject();
if (geolocation != null) {
params.add("geolocation", gson().toJsonTree(geolocation));
}
sendMessage("setGeolocation", params);
});
JsonObject params = new JsonObject();
if (geolocation != null) {
params.add("geolocation", gson().toJsonTree(geolocation));
}
sendMessage("setGeolocation", params);
}

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

@Override
public String storageState(StorageStateOptions options) {
return withLogging("BrowserContext.storageState", () -> storageStateImpl(options));
}

private String storageStateImpl(StorageStateOptions options) {
if (options == null) {
options = new StorageStateOptions();
}
Expand All @@ -633,10 +591,8 @@ public TracingImpl tracing() {

@Override
public void unrouteAll() {
withLogging("BrowserContext.unrouteAll", () -> {
routes.removeAll();
updateInterceptionPatterns();
});
routes.removeAll();
updateInterceptionPatterns();
}

@Override
Expand Down Expand Up @@ -687,10 +643,8 @@ public R get() {
}

private void unroute(UrlMatcher matcher, Consumer<Route> handler) {
withLogging("BrowserContext.unroute", () -> {
routes.remove(matcher, handler);
updateInterceptionPatterns();
});
routes.remove(matcher, handler);
updateInterceptionPatterns();
}

private void updateInterceptionPatterns() {
Expand Down
Loading
Loading