What is wrong with page.pdf() in Puppeteer?
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 6.10.3
- Platform / OS version: Mac OS X 10.14.1
- Node.js version: v12.4.0
What steps will reproduce the problem?
https://github.com/GoogleChrome/puppeteer/blob/master/README.md
I am trying the following example from the above page.
#!/usr/bin/env node
// vim: set noexpandtab tabstop=2:
const puppeteer = require('puppeteer');
(async () => {
// const browser = await puppeteer.launch();
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle2'});
await page.pdf({path: '/tmp/hn.pdf', format: 'A4'});
await browser.close();
})();
What is the expected result?
No error.
What happens instead?
But I got the following error. Would you please let me know what is wrong and how to fix the problem? Thanks.
$ ./main.js
(node:73800) UnhandledPromiseRejectionWarning: Error: Protocol error (Page.printToPDF): PrintToPDF is not implemented
at /usr/local/lib/node_modules/puppeteer/lib/Connection.js:183:56
at new Promise (<anonymous>)
at CDPSession.send (/usr/local/lib/node_modules/puppeteer/lib/Connection.js:182:12)
at Page.pdf (/usr/local/lib/node_modules/puppeteer/lib/Page.js:977:39)
at Page.<anonymous> (/usr/local/lib/node_modules/puppeteer/lib/helper.js:112:23)
at main.js:11:13
at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:73800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:73800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7
Top Results From Across the Web
Puppeteer not work correctly with handlebars and get only ...
1 Answer 1 · Hi thanks for you help, i replaced await page.goto( data:text/html;charset=UTF-8,${htmlContent} , { waitUntil: "networkidle0", }); ...
Read more >Convert web pages into PDFs with Puppeteer and NodeJS
Learn how you can generate a PDF document from any web page using NodeJS, Puppeteer, and Chromium.
Read more >Generating PDFs - Checkly
It is important to take a quick look at the official docs for page.pdf() (Puppeteer or Playwright), as it is almost certain that...
Read more >Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, keyboard shortcuts, ... page.pdf() generates a pdf of the page with print css media....
Read more >How to Convert HTML into PDF with Node.Js and Puppeteer
Note : PDF generation is currently only supported in Chrome headless. Step 2. Navigate to a URL. Then, we will call the page.goto()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you need to be in headless true to use PDF
Loading extension only works when headless is set to false. And at the same time I need to set headless to true for PDF