Skip to content

Commit 9048a0f

Browse files
committed
read baseUrl and videoDir from initializer
1 parent 68e144d commit 9048a0f

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,20 @@ enum EventType {
102102
request = connection.getExistingObject(initializer.getAsJsonObject("requestContext").get("guid").getAsString());
103103
request.timeoutSettings = timeoutSettings;
104104
clock = new ClockImpl(this);
105-
closePromise = new WaitableEvent<>(listeners, EventType.CLOSE);
105+
closePromise = new WaitableEvent<>(listeners, EventType.CLOSE);
106+
107+
String url = initializer.getAsJsonObject("options").get("baseUrl").getAsString();
108+
if (url != null) {
109+
try {
110+
this.baseUrl = new URL(url);
111+
} catch (MalformedURLException e) {
112+
}
113+
}
114+
115+
JsonObject recordVideo = initializer.getAsJsonObject("options").getAsJsonObject("recordVideo");
116+
if (recordVideo != null) {
117+
this.videosDir = Path.of(recordVideo.get("dir").getAsString());
118+
}
106119
}
107120

108121
void setRecordHar(Path path, HarContentPolicy policy) {
@@ -111,14 +124,6 @@ void setRecordHar(Path path, HarContentPolicy policy) {
111124
}
112125
}
113126

114-
void setBaseUrl(String spec) {
115-
try {
116-
this.baseUrl = new URL(spec);
117-
} catch (MalformedURLException e) {
118-
this.baseUrl = null;
119-
}
120-
}
121-
122127
String effectiveCloseReason() {
123128
if (closeReason != null) {
124129
return closeReason;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ private BrowserContextImpl newContextImpl(NewContextOptions options) {
181181
params.addProperty("testIdAttributeName", browserType.playwright.sharedSelectors.testIdAttributeName);
182182
JsonElement result = sendMessage("newContext", params);
183183
BrowserContextImpl context = connection.getExistingObject(result.getAsJsonObject().getAsJsonObject("context").get("guid").getAsString());
184-
context.videosDir = options.recordVideoDir;
185-
if (options.baseURL != null) {
186-
context.setBaseUrl(options.baseURL);
187-
}
188184
context.initializeHarFromOptions(harOptions);
189185
return context;
190186
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ private BrowserContextImpl launchPersistentContextImpl(Path userDataDir, LaunchP
207207
BrowserImpl browser = connection.getExistingObject(json.getAsJsonObject("browser").get("guid").getAsString());
208208
browser.connectToBrowserType(this, options.tracesDir);
209209
BrowserContextImpl context = connection.getExistingObject(json.getAsJsonObject("context").get("guid").getAsString());
210-
context.videosDir = options.recordVideoDir;
211-
if (options.baseURL != null) {
212-
context.setBaseUrl(options.baseURL);
213-
}
214210
context.initializeHarFromOptions(harOptions);
215211
context.tracing().setTracesDir(options.tracesDir);
216212
return context;

0 commit comments

Comments
 (0)