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 @@ -382,7 +382,11 @@ public void close(CloseOptions options) {
options = new CloseOptions();
}
closeReason = options.reason;
request.dispose(convertType(options, APIRequestContext.DisposeOptions.class));
try {
request.dispose(convertType(options, APIRequestContext.DisposeOptions.class));
} catch (TargetClosedError e) {
// The request context was disposed by the user already.
}
try {
tracing.exportAllHars();
} catch (RuntimeException e) {
Expand Down Expand Up @@ -934,7 +938,7 @@ protected void initializeHarFromOptions(Browser.NewContextOptions options) {
contentPolicy = HarContentPolicy.OMIT;
}
if (contentPolicy == null) {
contentPolicy = options.recordHarPath.endsWith(".zip") ? HarContentPolicy.ATTACH : HarContentPolicy.EMBED;
contentPolicy = options.recordHarPath.toString().endsWith(".zip") ? HarContentPolicy.ATTACH : HarContentPolicy.EMBED;
}
RouteFromHAROptions routeFromHAROptions = new RouteFromHAROptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,4 +986,11 @@ void shouldSupportMultipleHttpCredentials(Browser browser, Server server) {
assertEquals(401, response2.status());
}
}

@PlaywrightTest
void shouldCloseContextAfterRequestDispose(Browser browser) {
BrowserContext context = browser.newContext();
context.request().dispose();
context.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.microsoft.playwright;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.microsoft.playwright.fixtures.DisabledOnBrowser;
import com.microsoft.playwright.fixtures.PlaywrightTest;
import com.microsoft.playwright.options.HarMode;
Expand Down Expand Up @@ -535,4 +537,22 @@ void shouldNotInterceptAPIRequestContextRequestsByDefault(Browser browser, Serve
assertEquals("{\"hello\": \"fresh\"}", replayed.text());
}
}

@PlaywrightTest
void shouldAttachContentWhenRecordingHarZip(Browser browser, Server server, @TempDir Path tmpDir) throws IOException {
Path harPath = tmpDir.resolve("har.zip");
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions()
.setRecordHarPath(harPath)
.setRecordHarMode(HarMode.MINIMAL))) {
Page page = context.newPage();
page.navigate(server.PREFIX + "/one-style.html");
}
Path harDir = tmpDir.resolve("har");
extractZip(harPath, harDir);
String har = new String(Files.readAllBytes(harDir.resolve("har.har")), StandardCharsets.UTF_8);
JsonObject content = JsonParser.parseString(har).getAsJsonObject().getAsJsonObject("log")
.getAsJsonArray("entries").get(0).getAsJsonObject().getAsJsonObject("response").getAsJsonObject("content");
assertTrue(content.has("_file"), har);
assertTrue(Files.exists(harDir.resolve(content.get("_file").getAsString())));
}
}
Loading