puppeteer: Error generating PDFs: Protocol error (Page.printToPDF): Target closed.
- 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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 14
- Comments: 15 (1 by maintainers)
Was getting the same error on pptr v1.12.2 but was able to fix it by setting
pipe: true
when launching the browser.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.
Tried all the suggestions in this issue (we donโt have any big images but we embed a couple of fonts) and nothing works.
This issue should be re-opened as it is unresolved.
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.
Thanks @slate71! The solution worked for me too, but an error regularly appears:
Error: write EPIPE at _errnoException (util.js:992:11) at WriteWrap.afterWrite [as oncomplete] (net.js:864:14)
Have same issue, on win10, chrome 69 and chrmium 74, puppeteer 1.12.2,
@UNDEADgtr The issue is that the PipeTransport does not install handlers for stream errors. I opened https://github.com/GoogleChrome/puppeteer/issues/4374 to track the issue.
Have the same issue, on mac, puppeteer 1.11.0,
The following works fine for me with pptr v1.8.0: BEWARE: I see you use custom chrome instance; make sure it matches the puppeteer version.
There is a related issue upstream in Chrome that results in extremely large PDF output for pages containing emoji. See this Chrome issue: https://bugs.chromium.org/p/chromium/issues/detail?id=921585
Printing these Emoji with Chromium on macOS and Linux both results in ~200MB PDFs:
Here is a repo that demonstrates this problem: https://github.com/justjake/chromium-color-emoji-printing-issue