puppeteer / puppeteer

Node.js API for Chrome
https://pptr.dev
Apache License 2.0
87.64k stars 9.03k forks source link

[Bug]: Differences between PDFs created with headless: 'new' and headless: true #10868

Open vasylshylov opened 10 months ago

vasylshylov commented 10 months ago

Minimal, reproducible example

import puppeteer from 'puppeteer';

async function makePdf(headless) {
  const browser = await puppeteer.launch({
    headless,
  });

  const page = await browser.newPage();

  await page.goto('https://orange-dorise-3.tiiny.site/');

  await page.emulateMediaType('screen');

  await page.pdf({
    path: `headless-${headless}.pdf`,
    printBackground: true,
  });
}

await Promise.all([
  makePdf(true),
  makePdf('new'),
]);

process.exit(0);

Error string

no error

Bug behavior

Background

I am using Puppeteer for generating PDF files from my HTML pages, which often contain YouTube videos embedded via iframe. I encountered an issue when using the headless: 'new' option, where the preview image of these videos is missing in the generated PDF.

Simple page example

Expectation

PDF files created with both headless: 'new' and headless: true options should be identical.

Reality

The PDF files are different. The file headless-true.pdf includes a YouTube video preview, while the file headless-new.pdf does not contain this preview.

Puppeteer configuration file (if used)

No response

Puppeteer version

21.1.1

Node version

18.17.1

Package manager

npm

Package manager version

9.6.7

Operating system

macOS

github-actions[bot] commented 10 months ago

The issue has been labeled as confirmed by the automatic analyser. Someone from the Puppeteer team will take a look soon!


Analyzer run

Ann-Dederkal commented 10 months ago

I've faced the same issue.

OrKoN commented 10 months ago

The results of the headless:new mode are consistent with the headful (headless: false) results. Interestingly, the regular print view of Chrome does not produce anything for this page. The issue probably has something to do with out-of-process iframes. Adding '--disable-site-isolation-trials' to args is a workaround for this issue.

gokinasaiajay commented 10 months ago

Is is good to used for plan pdf printing, with headless:"new". is it stabilised mode of puppeteer.