question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error generating PDFs: Protocol error (Page.printToPDF): Target closed.

See original GitHub issue
  • Puppeteer version: puppeteer@1.5.0-next.1528948338383
  • Chromium 66.0.3359.181 Built on Ubuntu , running on Ubuntu 17.10
  • Node.js version: v9.11.2
  • Fails on VirtualBox VM with plentiful resources (4cores, >8GB mem free)

Also an issue inside docker container with puppeteer 1.0.0, Ubuntu 18.04 and node v8.

What steps will reproduce the problem?

(async () => {
    const browser = await puppeteer.launch({
        executablePath: '/usr/bin/chromium-browser',
        args: ['--headless', '--disable-gpu', '--full-memory-crash-report', '--unlimited-storage',
               '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
    });
    const page = await browser.newPage();
    await page.goto(url, {waitUntil: 'networkidle0'});
    await page.pdf({path: outfile, format: 'A4'});
    await browser.close();
})().catch(error => {
    console.error(error);
    process.exit(1);
});

What is the expected result?

PDF file saved to outfile, exit code 0

What happens instead?

chromium-browser goes 100% CPU at page.pdf() and after 35s:

{ Error: Protocol error (Page.printToPDF): Target closed.
at Promise (/home/jon/dev/web-exporter/node_modules/puppeteer/lib/Connection.js:202:56)
at new Promise (<anonymous>)
at CDPSession.send (/home/jon/dev/web-exporter/node_modules/puppeteer/lib/Connection.js:201:12)
at Page.pdf (/home/jon/dev/web-exporter/node_modules/puppeteer/lib/Page.js:851:39)
at /home/jon/dev/web-exporter/web_exporter.js:40:20
at <anonymous> message: 'Protocol error (Page.printToPDF): Target closed.' }

Exit code of 1.

I’ve tried various different args for chromium-browser and page.pdf. This application has been working generating 100s of PDFs for 6 months. In the last few days however would fail with the output above on specific pages.

The page being loaded is a react application with a 10s of small images (50-200 pixels square) embedded. The issue reproducibley fails on small number of ‘bad’ pages. Unfortunately the URL is not public.

I can open the url without issue in chrome and the same chromium-browser (non-headless), also the print to pdf works as expected.

Any help in tracking down this issue much appreciated.

Jon

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

39reactions
slate71commented, Mar 7, 2019

Was getting the same error on pptr v1.12.2 but was able to fix it by setting pipe: true when launching the browser.

 const browser = await puppeteer.launch({
        pipe: true,
        args: ['--headless', '--disable-gpu', '--full-memory-crash-report', '--unlimited-storage',
               '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
    });

The issue starting popping up when trying to generate a PDF with approximately 100 various .jpgs. Using the default Websocket to connect to the browser would bail during encoding to base64. Using a pipe to connect to the browser instead seems to fix the issue of bailing during encoding.

pipe <boolean> Connects to the browser over a pipe instead of a WebSocket. Defaults to false

4reactions
danfoustcommented, Dec 9, 2020

I ran into this issue when trying to print pdfs with a company logo that had extremely large dimensions.

It was only 300kb, but it was 10,000x7000 pixels with lots of white-space

Resizing the logo to a reasonable size (ex 800x600) fixed the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ProtocolError: Protocol error (Page.printToPDF): Printing is not ...
PDF creation is only supported in headless mode. So this should work: const browser = await Puppeteer.launch({ headless: true });.
Read more >
Protocol error (Page.printToPDF): Target closed. - jsreport forum
I Seem to be getting this error quite a lot after updating to version 2.5.0: Protocol error (Page.printToPDF): Target closed.
Read more >
[Ultimate PDF] Protocol error(Page.navigate) - OutSystems
Hello,. We are having issues with generating PDF's since the last update. The error we get is;. Protocol error(Page.navigate): Target closed.
Read more >
Gettting Error while trying to create pdf using browserhot
printToPDF ): Show invalid printer settings error at ... at Page.pdf (/usr/lib/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:1212:43) at getOutput ...
Read more >
Protocol error (IO.close): Target closed.", when ... - Medium
Great article, helped me dodge the html-pdf issues with AWS Lambda. But, I had to do one thing differently. I kept getting, "Error:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found