是否可以解析外部页面http://example.com有一些 js 错误(例如“$未定义”),捕获这些错误并通过 console.log() 打印它们?
最佳答案
是的,这是可能的。基本上,您需要下载页面并将其呈现在 headless 浏览器中,例如 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
关于javascript - node.js 解析页面并捕获外部前端 js 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30563396/