My web application generates a PDF from an HTML page via Google Chrome 76.0.3809.100 headless on Debian GNU/Linux 9.9 (stretch). My call looks like this:
google-chrome --headless --ignore-certificate-errors --hide-scrollbars --print-to-pdf='mypdf.pdf' --run-all-compositor-stages-before-draw --no-sandbox --virtual-time-budget=60000 https://example.com/mypage.html
Everything works perfectly... about 9 times out of 10. But sometime I got an empty PDF.
I thought it was a bug in my code, so I tried to run the same command from the command line directly. I also added --dump-dom
to exclude the PDF generation and display the HTML on the console. Again, about 9 times out of 10 it works, one... it doesn't.
When it doesn't, I get this error:
[0814/090047.461433:ERROR:headless_shell.cc(434)] Failed to serialize document: Uncaught
Well, actually this is my full console output, but all the other messages are there also when it runs OK, so I don't think they matter:
Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
Fontconfig warning: ignoring UTF-8: not a valid region tag
[0814/090046.673042:ERROR:command_buffer_proxy_impl.cc(107)] ContextResult::kTransientFailure: Shared memory region is not valid
[0814/090046.674622:WARNING:ipc_message_attachment_set.cc(49)] MessageAttachmentSet destroyed with unconsumed attachments: 0/1
[0814/090046.736342:ERROR:cert_verify_proc_nss.cc(969)] CERT_PKIXVerifyCert for example.com failed err=-8102
[0814/090047.461433:ERROR:headless_shell.cc(434)] Failed to serialize document: Uncaught
[0814/090047.474334:ERROR:browser_process_sub_thread.cc(203)] Waited 3 ms for network service
Ok, so back to "my bad" route. I switched https://example.com/mypage.html
to https://google.com
and... lo and behold! Same "sometime" error!
I'm fresh out of ideas, even more since I cannot replicate the behaviour in a consistent manner: sometime it works, sometime it doesn't.
Any help is appreciated, thanks!