node.js解析页面并捕获外部前端js错误

时间:2015-05-31 22:32:32

标签: javascript node.js parsing cheerio

是否可以解析具有一些js错误的外部页面http://example.com(例如' $未定义'),捕获这些错误并通过console.log()打印它们?

1 个答案:

答案 0 :(得分:1)

是的,有可能。基本上,您需要下载页面并在无头浏览器中呈现它,例如PhantomJS

有人已经这样做了:http://npmjs.com/package/phantom-check

$ phantom-check http://example.com
Phantom is checking http://example.com

[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://example.com/, HTTP GET
[debug] [phantom] Navigation requested: url=http://example.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://example.com/"
[debug] [phantom] Successfully injected Casper client-side utilities

Page http://example.com has no errors