Skip to content

Commit

Permalink
chore: pdf generation now works in headed mode too (#33879)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Dec 6, 2024
1 parent 993546c commit 733f9a2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
4 changes: 0 additions & 4 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2762,10 +2762,6 @@ This method requires Playwright to be started in a headed mode, with a falsy [`o

Returns the PDF buffer.

:::note
Generating a pdf is currently only supported in Chromium headless.
:::

`page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
[`method: Page.emulateMedia`] before calling `page.pdf()`:

Expand Down
2 changes: 0 additions & 2 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3609,8 +3609,6 @@ export interface Page {
/**
* Returns the PDF buffer.
*
* **NOTE** Generating a pdf is currently only supported in Chromium headless.
*
* `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
* [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) before calling
* `page.pdf()`:
Expand Down
10 changes: 4 additions & 6 deletions tests/library/pdf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
import { browserTest as it, expect } from '../config/browserTest';
import fs from 'fs';

it('should be able to save file', async ({ contextFactory, headless, browserName }, testInfo) => {
it.skip(!headless || browserName !== 'chromium', 'Printing to pdf is currently only supported in headless chromium.');

it('should be able to save file', async ({ contextFactory, browserName }, testInfo) => {
it.skip(browserName !== 'chromium', 'Printing to pdf is currently only supported in chromium.');
const context = await contextFactory();
const page = await context.newPage();
const outputFile = testInfo.outputPath('output.pdf');
await page.pdf({ path: outputFile });
expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0);
});

it('should be able to generate outline', async ({ contextFactory, server, headless, browserName }, testInfo) => {
it.skip(!headless || browserName !== 'chromium', 'Printing to pdf is currently only supported in headless chromium.');
// const context = await contextFactory();
it('should be able to generate outline', async ({ contextFactory, server, browserName }, testInfo) => {
it.skip(browserName !== 'chromium', 'Printing to pdf is currently only supported in chromium.');
const context = await contextFactory({
baseURL: server.PREFIX,
});
Expand Down

0 comments on commit 733f9a2

Please sign in to comment.