Skip to content

Commit b8a9d88

Browse files
authored
fix: NPE in Page.pdf for persistent context (#1292)
Fixes #1291
1 parent 5a4640f commit b8a9d88

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,9 +946,6 @@ public byte[] pdf(PdfOptions options) {
946946
}
947947

948948
private byte[] pdfImpl(PdfOptions options) {
949-
if (!browserContext.browser().isChromium()) {
950-
throw new PlaywrightException("Page.pdf only supported in headless Chromium");
951-
}
952949
if (options == null) {
953950
options = new PdfOptions();
954951
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ void shouldSupportFractionalScaleValue(@TempDir Path tempDir) throws IOException
5252
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
5353
void shouldThrowInNonChromium() {
5454
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
55-
assertTrue(e.getMessage().contains("Page.pdf only supported in headless Chromium"));
55+
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
56+
}
57+
58+
59+
@Test
60+
@DisabledIf(value="com.microsoft.playwright.TestBase#isChromium", disabledReason="skip")
61+
void correctExceptionWithPersistentContext(@TempDir Path tempDir) {
62+
Path profile = tempDir.resolve("profile");
63+
try (BrowserContext context = browserType.launchPersistentContext(profile)) {
64+
Page page = context.newPage();
65+
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.pdf());
66+
assertTrue(e.getMessage().contains("PDF generation is only supported for Headless Chromium"), e.getMessage());
67+
}
5668
}
5769
}

0 commit comments

Comments
 (0)