microsoft/playwright · error · Error
PDF creation is only working with Chromium
Error message
PDF creation is only working with Chromium
What it means
Thrown by the `pdf` CLI sub-command when `options.browser` is not 'chromium'. Chromium is the only browser engine with PDF printing support, so the command refuses to proceed for firefox/webkit before launching a context.
Source
Thrown at packages/playwright-core/src/cli/browserActions.ts:329
console.log(`Waiting for timeout ${captureOptions.waitForTimeout}...`);
await page.waitForTimeout(parseInt(captureOptions.waitForTimeout, 10));
}
}
export async function screenshot(options: Options, captureOptions: CaptureOptions, url: string, path: string) {
const { context } = await launchContext(options, { headless: true });
console.log('Navigating to ' + url);
const page = await openPage(context, url);
await waitForPage(page, captureOptions);
console.log('Capturing screenshot into ' + path);
await page.screenshot({ path, fullPage: !!captureOptions.fullPage });
// launchContext takes care of closing the browser.
await page.close();
}
export async function pdf(options: Options, captureOptions: CaptureOptions, url: string, path: string) {
if (options.browser !== 'chromium')
throw new Error('PDF creation is only working with Chromium');
const { context } = await launchContext({ ...options, browser: 'chromium' }, { headless: true });
console.log('Navigating to ' + url);
const page = await openPage(context, url);
await waitForPage(page, captureOptions);
console.log('Saving as pdf into ' + path);
await page.pdf!({ path, format: captureOptions.paperFormat });
// launchContext takes care of closing the browser.
await page.close();
}
function lookupBrowserType(options: Options): BrowserType {
let name = options.browser;
if (options.device) {
const device = playwright.devices[options.device];
name = device.defaultBrowserType;
}
let browserType: any;
switch (name) {View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Force chromium for the pdf command: `playwright pdf --browser=chromium <url>`.
- Drop the `--browser` flag if no non-chromium default is set.
- Branch in scripts to skip pdf when the engine is not chromium.
Example fix
# before npx playwright pdf --browser=firefox page.html out.pdf # after npx playwright pdf --browser=chromium page.html out.pdf
Defensive patterns
Strategy: validation
Validate before calling
function assertChromiumForPdf(browser?: string) {
if (browser && browser !== 'chromium')
throw new Error(`PDF requires chromium; got ${browser}`);
} Type guard
function supportsPdf(browser: string): boolean {
return browser === 'chromium';
} Try / catch
try {
await pdf(options, capture, url, path);
} catch (e) {
if (/PDF creation is only working with Chromium/.test(e.message)) {
options.browser = 'chromium';
return pdf(options, capture, url, path);
}
throw e;
} Prevention
- Hard-code `--browser=chromium` in pdf command wrappers.
- Skip pdf generation in scripts when the engine is firefox/webkit.
- Document the chromium-only restriction next to PDF entry points.
When it happens
Trigger: Running `playwright pdf --browser=firefox <url>` or `--browser=webkit`, or omitting `--browser` while a default/config sets firefox/webkit. The check `if (options.browser !== 'chromium') throw` runs at the top of the pdf function.
Common situations: Forgetting the engine restriction; global config defaulting to firefox/webkit; scripted invocation that passes through a user-chosen browser without filtering pdf.
Related errors
- Invalid viewport size format: use "width,height", for exampl
- Invalid geolocation format, should be "lat,long". For exampl
- Device descriptor not found: '${options.device}', available
- Invalid color scheme, should be one of "light", "dark"
- Unknown permission: ${permission}
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/51ab46050690d41b.
Report an issue: GitHub.