javascriptwkhtmltopdf

wkhtmltopdf doesn't execute associated javascript when creating a pdf from webpage


I am using wkhtmltopdf on Ubuntu 18.04 LTS from command line and am trying to create a pdf from a webpage. The webpage content is updated once a day and filled with current information by javascript. When I use wkthmltopdf it renders all the "bare"/"empty" HTML but without current information included by the javascript, as if the javascript has not yet been loaded for the PDF or just ignored.

I am using wkhtmltopdf --javascript-delay 60000 --no-stop-slow-scripts --enable-javascript https://example.com/ test.pdf Do you know how to create the pdf after the javascript has been loaded and filled the webpage with current information?


Solution

  • My solution:

    After debugging the javascript via wkhtmltopdf (added option --debug-javascript) as @Nitin suggested I found that I had a SyntaxError (parse error).

    I changed parts of the javascript from a "for..of" to "for..in" loop. This solved the problem an the pdf was created correctly. Thanks @Daphoque for explaining that this is probably due to the javascript version used by wkhtmltopdf.