'chrome headless mode run in batch mode

I am trying to convert a series of html files to pdfs and then send the generated pdf file. However, if i start headless crome like

...crome.exe --headless --disable-gpu --print-to-pdf=file01.pdf source01.html

The chrome process immediately even though it could take some time before the pdf is generated. Is there a way or flag to instruct chrome.exe to wait for the pdf to be saved before exiting?

p.s. Is there also a way to see html/js erros on the page?

p.p.s I have given the simplest example. What I actually run has

--run-all-compositor-stages-before-draw 
--virtual-time-budget=10000 # Need to render some stuff first
--enable-logging


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source