简体   繁体   English

从外部页面查找javascript错误,将结果输出到文件

[英]finding javascript errors from external page, output results to file

I have been tasked to created a script that is performing health checks on a web page, 我受命创建一个脚本来对网页进行运行状况检查,

for the most part I can get the information I need using cURL and a couple of other tools. 在大多数情况下,我可以使用cURL和其他一些工具来获取所需的信息。

So this is the set up. 这就是设置。

I have a php class on Server A, a cron job on this server executes a php script that begins the health check by loading a page on Server B, using cURL i can get timeout information, response codes etc, but I am stuck when it comes to discovering if the given web page has Javascript errors (that would appear in the console); 我在服务器A上有一个php类,此服务器上的cron作业执行了一个php脚本,该脚本通过使用cURL加载服务器B上的页面来开始运行状况检查,我可以获取超时信息,响应代码等,但是当它停滞时来发现给定的网页是否存在Javascript错误(该错误会出现在控制台中); and i would really appreciate any help that anyone could give. 我真的很感谢任何人都可以提供的帮助。

Is there a way to make an API call via PHP that would contact a page on Server B, load that page, then load the any error console entries into a text file? 有没有一种方法可以通过PHP进行API调用,从而与服务器B上的一个页面联系,加载该页面,然后将任何错误控制台条目加载到文本文件中?

These details are available via any browser, is it the browser that generates these errors or can I use a script that will fool the script into thinking its a browser and grab the errors? 这些详细信息可通过任何浏览器获得,是浏览器会产生这些错误,还是我可以使用一个脚本来欺骗脚本以使其成为浏览器并抓住错误?

I really could do with any help! 我真的可以提供任何帮助!

Thank you. 谢谢。

In javascript you can use phantom.js to read console message. 在javascript中,您可以使用phantom.js读取控制台消息。

var webPage = require('webpage');
var page = webPage.create();

page.onConsoleMessage = function(msg, lineNum, sourceId) {
  console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};

source : http://phantomjs.org/api/webpage/handler/on-console-message.html 来源: http : //phantomjs.org/api/webpage/handler/on-console-message.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM