简体   繁体   中英

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.

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); 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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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