Casperjs catch console.log and console.error

Piotr Wójcik picture Piotr Wójcik · Oct 4, 2013 · Viewed 8.7k times · Source

I'am trying to catch site console.log and console.error by casperjs. In the case of console.log I have working code:

casper.on('remote.message', function(message) {
    this.echo('remote message caught: ' + message);
});

But I can't figure out how to catch console.error. I need this for catching any resources error (like images not found).

Answer

Beowulfenator picture Beowulfenator · Apr 13, 2016

There's also the page.error handler:

casper.on("page.error", function(msg, trace) {
     this.echo("Error: " + msg, "ERROR");
});

Depending on which errors you need to catch, this one may be better.