Skip to content

Commit 44cb76d

Browse files
authored
chore: only log har when pw:api is enabled (#977)
1 parent 9fac877 commit 44cb76d

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Base64;
2727
import java.util.Map;
2828

29+
import static com.microsoft.playwright.impl.LoggingSupport.isApiLoggingEnabled;
2930
import static com.microsoft.playwright.impl.LoggingSupport.logApi;
3031
import static com.microsoft.playwright.impl.Serialization.fromNameValues;
3132
import static com.microsoft.playwright.impl.Serialization.gson;
@@ -66,7 +67,9 @@ void handle(Route route) {
6667
String action = response.get("action").getAsString();
6768
if ("redirect".equals(action)) {
6869
String redirectURL = response.get("redirectURL").getAsString();
69-
logApi("HAR: " + route.request().url() + " redirected to " + redirectURL);
70+
if (isApiLoggingEnabled()) {
71+
logApi("HAR: " + route.request().url() + " redirected to " + redirectURL);
72+
}
7073
((RouteImpl) route).redirectNavigationRequest(redirectURL);
7174
return;
7275
}
@@ -83,7 +86,9 @@ void handle(Route route) {
8386
}
8487

8588
if ("error".equals(action)) {
86-
logApi("HAR: " + response.get("message").getAsString());
89+
if (isApiLoggingEnabled()) {
90+
logApi("HAR: " + response.get("message").getAsString());
91+
}
8792
// Report the error, but fall through to the default handler.
8893
}
8994

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ static void logWithTimestamp(String message) {
6060
System.err.println(timestamp + " " + message);
6161
}
6262

63+
static boolean isApiLoggingEnabled() {
64+
return isEnabled;
65+
}
66+
6367
static void logApi(String message) {
6468
// This matches log format produced by the server.
6569
logWithTimestamp("pw:api " + message);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ private static class RouteInfo {
3939
}
4040

4141
boolean handle(RouteImpl route) {
42-
if (times != null && times <= 0) {
43-
return false;
44-
}
4542
if (!matcher.test(route.request().url())) {
4643
return false;
4744
}

playwright/src/test/java/com/microsoft/playwright/TestBrowserContextHar.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ void shouldRoundTripHarWithPostData(@TempDir Path tmpDir) {
326326
assertEquals("3", page2.evaluate(fetchFunction, "3"));
327327
assertEquals("3", page2.evaluate(fetchFunction, "3"));
328328
try {
329-
Object result = page2.evaluate(fetchFunction, "4");
330-
System.out.println(result);
329+
page2.evaluate(fetchFunction, "4");
331330
fail("did not throw");
332331
} catch (PlaywrightException e) {
333332
}

playwright/src/test/java/com/microsoft/playwright/TestPageRequestFallback.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,14 @@ void shouldFallBackAfterException() {
133133
@Test
134134
void shouldChainOnce() {
135135
page.route("**/empty.html", route -> {
136+
System.out.println("before fulfill");
136137
route.fulfill(new Route.FulfillOptions().setStatus(200).setBody("fulfilled one"));
138+
System.out.println("after fulfill");
137139
}, new Page.RouteOptions().setTimes(1));
138140
page.route("**/empty.html", route -> {
141+
System.out.println("before fallback");
139142
route.fallback();
143+
System.out.println("after fallback");
140144
}, new Page.RouteOptions().setTimes(1));
141145
Response response = page.navigate(server.EMPTY_PAGE);
142146
assertEquals("fulfilled one", response.text());

0 commit comments

Comments
 (0)