Skip to content

Commit 64f7a05

Browse files
authored
fix: prevent video.saveAs() from hanging (#1020)
1 parent 436fc12 commit 64f7a05

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public Path path() {
7272
@Override
7373
public void saveAs(Path path) {
7474
page.withLogging("Video.saveAs", () -> {
75+
if (!page.isClosed()) {
76+
throw new PlaywrightException("Page is not yet closed. Close the page prior to calling saveAs");
77+
}
7578
try {
7679
waitForArtifact().saveAs(path);
7780
} catch (PlaywrightException e) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,17 @@ void shouldWaitForVideoFinishWhenPageIsClosed(@TempDir Path videosDir) throws IO
127127
assertTrue(Files.exists(files.get(0)));
128128
assertTrue(Files.size(files.get(0)) > 0);
129129
}
130+
131+
@Test
132+
void shouldErrorIfPageNotClosedBeforeSaveAs(@TempDir Path tmpDir) {
133+
try (Page page = browser.newPage(new Browser.NewPageOptions().setRecordVideoDir(tmpDir))) {
134+
page.navigate(server.PREFIX + "/grid.html");
135+
Path outPath = tmpDir.resolve("some-video.webm");
136+
Video video = page.video();
137+
PlaywrightException exception = assertThrows(PlaywrightException.class, () -> video.saveAs(outPath));
138+
assertTrue(
139+
exception.getMessage().contains("Page is not yet closed. Close the page prior to calling saveAs"),
140+
exception.getMessage());
141+
}
142+
}
130143
}

0 commit comments

Comments
 (0)