简体   繁体   中英

Can I scrape a website's JavaScript Debugger Console data?

I use Pingdom Uptime Monitor to make sure my website is alive and well It works great

I also want to make sure that I keep a clean and empty JS console on my site. If it's not empty, it means something has likely gone wrong, and I need to investigate. I want to be alerted when something appears in my JS console, without checking manually.

I haven't found any info on how to make a GET request to receive a website's JS Console debugger info (don't need the website's HTML, JS, or CSS)

This could also easily be rolled into a SaaS. Thanks.

The JS console output doesn't come from the server; you can't get it with an HTTP request. Console output is produced by the page's scripts running in the browser, and the only way to get it is by loading the page and running its scripts like a browser would. PhantomJS might help for that.

A headless browser might be a perfect solution for this problem. Personally I would recommend Google Puppeteer.

Solution can be as easy as:

page.on('console', msg => {
  for (let i = 0; i < msg.args().length; ++i)
    console.log(`${i}: ${msg.args()[i]}`);
});
page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));

Please refer to docs .

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