最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - wkhtmltopdf and the jQuery.ready() function - Stack Overflow

programmeradmin0浏览0评论

I've been trying to generate a PDF using the wkhtmltopdf tool (/). The page from which I want to generate a PDF using jQuery and has some initializations using a jQuery.ready() function, something like this:

jQuery(function() {
    // do something
});

However, when I try to generate a PDF from the page the script is not executed. I've tried setting a delay to wait for the JavaScript to be executed with the option:

--javascript-delay 30000

But the result is the same.

When I've enabled wkhtmltopdf's JavaScript debugging option I get a warning, which I'm not sure if it's related to the problem:

Warning: undefined:0 TypeError: 'null' is not an object

Has anyone encountered this problem? Is there some kind of workaround?

EDIT: Seems the problem is caused by the error Warning: undefined:0 TypeError: 'null' is not an object. I've managed to print the error on the PDF using:

window.onerror = function(error, url, line) {
    $('body').before('<b> Error: ' + error + '</b> <br />');
    $('body').before('<b> Url: ' + url + '</b> <br />');
    $('body').before('<b> Line: ' + line + '</b> <br />');
    console.log(error, ' ', url, ' ', line);
};

But the information is very limited and I have no idea what might cause it:

Error: TypeError: 'null' is not an object
Url: undefined
Line: 0 

I've been trying to generate a PDF using the wkhtmltopdf tool (http://wkhtmltopdf/). The page from which I want to generate a PDF using jQuery and has some initializations using a jQuery.ready() function, something like this:

jQuery(function() {
    // do something
});

However, when I try to generate a PDF from the page the script is not executed. I've tried setting a delay to wait for the JavaScript to be executed with the option:

--javascript-delay 30000

But the result is the same.

When I've enabled wkhtmltopdf's JavaScript debugging option I get a warning, which I'm not sure if it's related to the problem:

Warning: undefined:0 TypeError: 'null' is not an object

Has anyone encountered this problem? Is there some kind of workaround?

EDIT: Seems the problem is caused by the error Warning: undefined:0 TypeError: 'null' is not an object. I've managed to print the error on the PDF using:

window.onerror = function(error, url, line) {
    $('body').before('<b> Error: ' + error + '</b> <br />');
    $('body').before('<b> Url: ' + url + '</b> <br />');
    $('body').before('<b> Line: ' + line + '</b> <br />');
    console.log(error, ' ', url, ' ', line);
};

But the information is very limited and I have no idea what might cause it:

Error: TypeError: 'null' is not an object
Url: undefined
Line: 0 
Share Improve this question edited Nov 7, 2014 at 12:26 Alex Kulinkovich 4,78815 gold badges49 silver badges54 bronze badges asked May 21, 2014 at 5:31 IvoIvo 1,2281 gold badge15 silver badges33 bronze badges 4
  • 1 Sounds like the JavaScript in the page does not work with Qt's somewhat old webkit. Can you add the code or a link to the page? – jgillich Commented May 21, 2014 at 8:30
  • Sadly, I can't provide the code of the web page. Is there a way to see a meaningful stack trace? Because this error is pletely useless. – Ivo Commented May 21, 2014 at 12:04
  • --debug-javascript maybe? You could also try a QtWebKit-based browser like Arora (code.google./p/arora), which has WebKit's inspector. – jgillich Commented May 21, 2014 at 12:23
  • Thanks, gonna try arora. As for --debug-javascript I've tried that and returns the same error as the one I posted. – Ivo Commented May 21, 2014 at 12:56
Add a ment  | 

1 Answer 1

Reset to default 9

The problem turned out to be that Qt doesn't support localStorage, so one of the initialization scripts failed which cause the jQuery.ready() not being executed.

I've managed to debug it with a browser with Qt support: QtWeb. (Tried Arora as well, couldn't run it on my system).

发布评论

评论列表(0)

  1. 暂无评论