Skip to content

Commit 3604aab

Browse files
authored
chore: store LocalUtils on Connection (#963)
1 parent 2fdb89c commit 3604aab

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public void routeFromHAR(Path har, RouteFromHAROptions options) {
352352
options = new RouteFromHAROptions();
353353
}
354354
UrlMatcher matcher = UrlMatcher.forOneOf(baseUrl, options.url);
355-
HARRouter harRouter = new HARRouter(browser.localUtils, har, options.notFound);
355+
HARRouter harRouter = new HARRouter(connection.localUtils, har, options.notFound);
356356
onClose(context -> harRouter.dispose());
357357
route(matcher, route -> harRouter.handle(route), null);
358358
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class BrowserImpl extends ChannelOwner implements Browser {
4040
boolean isRemote;
4141
boolean isConnectedOverWebSocket;
4242
private boolean isConnected = true;
43-
LocalUtils localUtils;
4443
BrowserTypeImpl browserType;
4544

4645
enum EventType {
@@ -212,7 +211,6 @@ private BrowserContextImpl newContextImpl(NewContextOptions options) {
212211
context.setBaseUrl(options.baseURL);
213212
}
214213
context.recordHarPath = recordHarPath;
215-
context.tracing().localUtils = localUtils;
216214
contexts.add(context);
217215
return context;
218216
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ private BrowserImpl launchImpl(LaunchOptions options) {
4848
JsonObject params = gson().toJsonTree(options).getAsJsonObject();
4949
JsonElement result = sendMessage("launch", params);
5050
BrowserImpl browser = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("browser").get("guid").getAsString());
51-
browser.localUtils = localUtils;
5251
browser.browserType = this;
5352
return browser;
5453
}
@@ -97,7 +96,6 @@ private Browser connectImpl(String wsEndpoint, ConnectOptions options) {
9796
BrowserImpl browser = connection.getExistingObject(playwright.initializer.getAsJsonObject("preLaunchedBrowser").get("guid").getAsString());
9897
browser.isRemote = true;
9998
browser.isConnectedOverWebSocket = true;
100-
browser.localUtils = localUtils;
10199
browser.browserType = this;
102100
Consumer<JsonPipe> connectionCloseListener = t -> browser.notifyRemoteClosed();
103101
pipe.onClose(connectionCloseListener);
@@ -132,7 +130,6 @@ private Browser connectOverCDPImpl(String endpointURL, ConnectOverCDPOptions opt
132130

133131
BrowserImpl browser = connection.getExistingObject(json.getAsJsonObject("browser").get("guid").getAsString());
134132
browser.isRemote = true;
135-
browser.localUtils = localUtils;
136133
browser.browserType = this;
137134
if (json.has("defaultContext")) {
138135
String contextId = json.getAsJsonObject("defaultContext").get("guid").getAsString();
@@ -199,7 +196,6 @@ private BrowserContextImpl launchPersistentContextImpl(Path userDataDir, LaunchP
199196
context.setBaseUrl(options.baseURL);
200197
}
201198
context.recordHarPath = options.recordHarPath;
202-
context.tracing().localUtils = localUtils;
203199
return context;
204200
}
205201

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class Connection {
6464
String debug = System.getenv("DEBUG");
6565
isLogging = (debug != null) && debug.contains("pw:channel");
6666
}
67+
LocalUtils localUtils;
6768

6869
class Root extends ChannelOwner {
6970
Root(Connection connection) {
@@ -138,6 +139,10 @@ public PlaywrightImpl initializePlaywright() {
138139
return (PlaywrightImpl) this.root.initialize();
139140
}
140141

142+
LocalUtils localUtils() {
143+
return localUtils;
144+
}
145+
141146
public <T> T getExistingObject(String guid) {
142147
@SuppressWarnings("unchecked") T result = (T) objects.get(guid);
143148
if (result == null)
@@ -270,7 +275,8 @@ private ChannelOwner createRemoteObject(String parentGuid, JsonObject params) {
270275
result = new JsonPipe(parent, type, guid, initializer);
271276
break;
272277
case "LocalUtils":
273-
result = new LocalUtils(parent, type, guid, initializer);
278+
localUtils = new LocalUtils(parent, type, guid, initializer);
279+
result = localUtils;
274280
break;
275281
case "Page":
276282
result = new PageImpl(parent, type, guid, initializer);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ public void routeFromHAR(Path har, RouteFromHAROptions options) {
975975
options = new RouteFromHAROptions();
976976
}
977977
UrlMatcher matcher = UrlMatcher.forOneOf(browserContext.baseUrl, options.url);
978-
HARRouter harRouter = new HARRouter(browserContext.browser().localUtils, har, options.notFound);
978+
HARRouter harRouter = new HARRouter(connection.localUtils, har, options.notFound);
979979
onClose(context -> harRouter.dispose());
980980
route(matcher, route -> harRouter.handle(route), null);
981981
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import static com.microsoft.playwright.impl.Serialization.gson;
2727

2828
class TracingImpl extends ChannelOwner implements Tracing {
29-
LocalUtils localUtils;
3029
boolean isRemote;
3130

3231
TracingImpl(ChannelOwner parent, String type, String guid, JsonObject initializer) {
@@ -60,7 +59,7 @@ private void stopChunkImpl(Path path) {
6059
// Add local sources to the remote trace if necessary.
6160
if (isRemote && json.has("sourceEntries")) {
6261
JsonArray entries = json.getAsJsonArray("sourceEntries");
63-
localUtils.zip(path, entries);
62+
connection.localUtils.zip(path, entries);
6463
}
6564
}
6665

0 commit comments

Comments
 (0)