WkHtmlToX projects uses WebKit as a backend to virutally render a web page and execute its JavaScript to get the final page for printing.
The issue is that the version of WebKit used is very old and this makes debugging JS regressions difficult. WkHtmlToX does offer a way to output the console, but it gives no way to do active debugging and provides no line numbers!
To debug JavaScript using the same WebKit version, I tracked down the version of Chromium that uses a close enough webkit version that this library leverages (534.34). Chromium 13.0.767.1, which is available here as a standalone exe for windows.
If your page does not already have a handler for window.onerror
, add one with the following code in your page boot code.
// Detect old safari version used by QT and Chromium 13.0.767.1
if (naviagtor.userAgent.indexOf("Safari/534.3") > -1) {
window.onerror = function _window_onerr(msg, url, line){
console.error("Error Occurred: " + String(msg) + ", url: " + String(url) + ", line: " + String(line))
}
}
When you test in Chromium, you will get the line number that is failing.
I have no idea why the QT WebKit used by this library is loosing the line number but I suspect is a compilation setting somewhere in the stack.
Note: This description is for the version of WkHtmlToPdf that has a user agent containing 'Safari/534.3'. Please let me know if a newer version os created and I can dig up the respective version of Chromium.
Hope this helps.
Date of ChromiumPortable 13.0.767.1 is 2011-05-18