Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Chrome Headless to Wait for Ajax Before Printing to PDF

I'm trying to use chrome headless to print my webpage to a PDF file. The PDf file is with no data, because the headless chrome is printing it before the ajax commands finish.

Any idea on how I can get it to wait?

Here's the command I currently use:

chrome --headless http://localhost:8080/banana/key --run-all-compositor-stages-before-draw --print-to-pdf=C:\\tmp\\tmp.pdf 
like image 340
Gil Shamgar Avatar asked Apr 02 '18 15:04

Gil Shamgar


People also ask

What is difference between Chrome and Chrome headless?

Headless mode is a functionality that allows the execution of a full version of the latest Chrome browser while controlling it programmatically. It can be used on servers without dedicated graphics or display, meaning that it runs without its “head”, the Graphical User Interface (GUI).

How do I make Chrome headless?

Which command starts the google chrome web browser in headless mode? As we have already seen, you just have to add the flag –headless when you launch the browser to be in headless mode. With CLI (Command Line Interface), just write: chrome \<br> – headless \ # Runs Chrome in headless mode.

Can headless Chrome run JavaScript?

As an alternative, and for more functionality, you can run headless Chrome using Puppeteer. Puppeteer is a Node. js library and, as a result, you are writing commands for the headless browser in JavaScript code which is considerably easier than writing those commands in a command line.

Is Chrome 59 a headless browser?

211. This version is released for Windows, Linux, Mac, iOS and android versions and has number of fixes and improvements. Chrome 59 Mac edition supports Headless Mode which is used for modern web automation testing as this mode works without graphical user interface.


1 Answers

chrome --headless http://localhost:8080/banana/key --run-all-compositor-stages-before-draw --print-to-pdf=C:\\tmp\\tmp.pdf --virtual-time-budget=10000 

Try this, virtual-time-budget is the parameter which can delay it.

like image 94
Izayoi Sakuya Avatar answered Sep 16 '22 13:09

Izayoi Sakuya