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.

Protocol error (Page.printToPDF): Show invalid printer settings error, thrown while printing pdfs

See original GitHub issue

Steps to reproduce

  • Puppeteer version: 6.14.7
  • Platform / OS version: Ubuntu 18.04.5 LTS
  • Node.js version: v14.8.0
  • local-chromium: linux-782078

Prerequisites Have two similar methods, which generate pdf, calling page.pdf() Example functions:

async printFolderQrCode(folderId) {
    const page = await this.openNewPage();
    const pdfPath = ...;

    const uri = new URL(...t);
    uri.search = ...;

    await page.goto(uri);
    await page.pdf({ path: pdfPath });
    await page.close();
    return pdfPath;
  }
`
`
  async printDocumentTypeQrCodes() {
    const page = await this.openNewPage();
    const pdfPath = ...;

    const uri = new URL(...);
    uri.search = ...;

    await page.goto(uri);
    await page.pdf({ path: pdfPath });
    await page.close();

    return pdfPath;
  }

Execution Executed the functions in both ways sync and async (using Promeise.all())

Expected result? Two pdfs are stored on the fs, and the methods return their paths.

Actual result Sometimes, the execution results in failure, with exception thrown:

Error: Protocol error (Page.printToPDF): Show invalid printer settings error
      at /home/dbonchev/Documaster/wfc/software/automation/wfc-test-automation/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:208:63
      at new Promise (<anonymous>)
      at CDPSession.send (node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:207:16)
      at Page.pdf (node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:1152:43)

In 2/3 of the executions, everything is OK, and pdfs are printed, but in 1/3 of the cases the error above is thrown. This anomaly has appeared, once I updated the puppeteer version @latest.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

3reactions
koga021commented, Oct 15, 2020

To resolve my problem, im using many of code (try/catch) validation and looping. Every important code, im using while with try/catch , and break with my code if it not return error on my try catch. Following this way, every error returned maping or not, go to my initial global looping and make all again and again.

async function(){
//global while true
while (true){
   try{
      //And more while(true) with try/catch with all parts of my code
     ///await puppeteer.launch , await page.goto, cut imagem, sender to s3, and database connection
     // all importants code i using while with try catch.
    break;
   }
   catch(error) {
      console.log("error, repeat all! initial code")
            
}


}

}

1reaction
joamagcommented, Apr 15, 2021

Found the original problem: We were calling window.print() at the start of the document load which creates a collision between puppeteer trying to “print” a PDF and the printing dialog created by Javascript call (window.print()).

Read more comments on GitHub >

github_iconTop Results From Across the Web

chromedp - Go - Show invalid printer settings error (-32000)
The error message can be interpreted as "I can not show a dialog to alert the user that the provided printer settings are...
Read more >
Gettting Error while trying to create pdf using browserhot
Fixed. We were executing command called window.print();.
Read more >
How to Fix the "Windows PDF Printer Error: Invalid Font When ...
Type Adobe Acrobat Reader in the Start Menu search bar and select the Best match. Click Edit in the top-left corner and then...
Read more >
About to lose my mind trying to get Page.printToPDF to work ...
Should be valid HTML markup with following classes used to inject printing values into them: date : formatted print date; title : document...
Read more >
Known issues with PaperCut MF, NG, Hive, Pocket and ...
Google Cloud Directory certificate import fails while setting up user sync ... Print Deploy Client may show "Can't reach this page" error on...
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