在 wkhtmltopdf 中调试 javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17151755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debugging javascript in wkhtmltopdf
提问by Janusz Krawiec
Where I can see the output of javascript debug when wkhtmltopdf runs in debug mode (--debug-javascript)
当 wkhtmltopdf 在调试模式下运行时,我可以在哪里看到 javascript 调试的输出(--debug-javascript)
回答by CShark
Another (I would say easiest) means of debugging javascript in WKHTMLTOPDF is to download QT Browser, the underlying browser used by WKHTMLTOPDF, and to inspect the javascript execution for your page from within the browser.
在 WKHTMLTOPDF 中调试 javascript 的另一种(我会说是最简单的)方法是下载 QT 浏览器,WKHTMLTOPDF 使用的底层浏览器,并从浏览器中检查页面的 javascript 执行情况。
You can download it from here
你可以从这里下载
Instructions on debugging javascript in QT here
在此处在 QT 中调试 javascript 的说明
You can basically debug your JavaScript in QT Browser just as you would in Chrome or Firefox.
您基本上可以在 QT 浏览器中调试 JavaScript,就像在 Chrome 或 Firefox 中一样。
回答by Jasper
Rendering test.html
渲染 test.html
<!DOCTYPE html>
<html>
<head></head>
<body>
BODY
<script>
console.log('Hi!');
</script>
</body>
</html>
like this
像这样
wkhtmltopdf test.html test.pdf --debug-javascript
should return something like this
应该返回这样的东西
Loading pages (1/5)
Warning: :0 Hi!
Resolving links (2/5)
Counting pages (3/5)
Printing pages (5/5)
Done
回答by halfbit
Although Daffy Punks answer is correct, I had an additional idea some weeks ago, that helped me a lot. This I want to share: Show it inside PDF
尽管 Daffy Punks 的回答是正确的,但几周前我有了一个额外的想法,这对我帮助很大。这个我想分享:在PDF里面显示
When rendering the layout for PDF I put an additional (hidden) DIV #pdf_errors
在渲染 PDF 布局时,我添加了一个额外的(隐藏的) DIV #pdf_errors
And very early in source - if #pdf_errors
is here - I let point console output to fill this div, and on error - I show it. Its not really debugging, but at least I see now what was going wrong.
在源代码的早期 - 如果#pdf_errors
在这里 - 我让点控制台输出来填充这个 div,并且在错误时 - 我显示它。它不是真正的调试,但至少我现在看到出了什么问题。
Source in coffeescript, my plain javascript times are long gone ...
在 coffeescript 中,我的纯 javascript 时代早已一去不复返了......
if ($pdf=$("#pdf_is_here")).length
for type in ["log","warn","error"]
do (type) =>
console[type]= (a...) =>
$pdf.append("<div class='#{type}'>#{s}</div>") for s in a
window.onerror= (messageOrEvent, source, lineno, colno, error) =>
$pdf.append("<div class='critical'>#{messageOrEvent}</div>")
$pdf.show()
$pdf.hide() # just in case css is not here