{"record":{"id":"51ab46050690d41b","repo":"microsoft/playwright","slug":"pdf-creation-is-only-working-with-chromium","errorCode":null,"errorMessage":"PDF creation is only working with Chromium","messagePattern":"PDF creation is only working with Chromium","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/cli/browserActions.ts","lineNumber":329,"sourceCode":"    console.log(`Waiting for timeout ${captureOptions.waitForTimeout}...`);\n    await page.waitForTimeout(parseInt(captureOptions.waitForTimeout, 10));\n  }\n}\n\nexport async function screenshot(options: Options, captureOptions: CaptureOptions, url: string, path: string) {\n  const { context } = await launchContext(options, { headless: true });\n  console.log('Navigating to ' + url);\n  const page = await openPage(context, url);\n  await waitForPage(page, captureOptions);\n  console.log('Capturing screenshot into ' + path);\n  await page.screenshot({ path, fullPage: !!captureOptions.fullPage });\n  // launchContext takes care of closing the browser.\n  await page.close();\n}\n\nexport async function pdf(options: Options, captureOptions: CaptureOptions, url: string, path: string) {\n  if (options.browser !== 'chromium')\n    throw new Error('PDF creation is only working with Chromium');\n  const { context } = await launchContext({ ...options, browser: 'chromium' }, { headless: true });\n  console.log('Navigating to ' + url);\n  const page = await openPage(context, url);\n  await waitForPage(page, captureOptions);\n  console.log('Saving as pdf into ' + path);\n  await page.pdf!({ path, format: captureOptions.paperFormat });\n  // launchContext takes care of closing the browser.\n  await page.close();\n}\n\nfunction lookupBrowserType(options: Options): BrowserType {\n  let name = options.browser;\n  if (options.device) {\n    const device = playwright.devices[options.device];\n    name = device.defaultBrowserType;\n  }\n  let browserType: any;\n  switch (name) {","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/cli/browserActions.ts#L311-L347","documentation":"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.","triggerScenarios":"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.","commonSituations":"Forgetting the engine restriction; global config defaulting to firefox/webkit; scripted invocation that passes through a user-chosen browser without filtering pdf.","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."],"exampleFix":"# before\nnpx playwright pdf --browser=firefox page.html out.pdf\n\n# after\nnpx playwright pdf --browser=chromium page.html out.pdf","handlingStrategy":"validation","validationCode":"function assertChromiumForPdf(browser?: string) {\n  if (browser && browser !== 'chromium')\n    throw new Error(`PDF requires chromium; got ${browser}`);\n}","typeGuard":"function supportsPdf(browser: string): boolean {\n  return browser === 'chromium';\n}","tryCatchPattern":"try {\n  await pdf(options, capture, url, path);\n} catch (e) {\n  if (/PDF creation is only working with Chromium/.test(e.message)) {\n    options.browser = 'chromium';\n    return pdf(options, capture, url, path);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["cli","pdf","chromium","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}