Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output client-side console with casper/phantomjs

Going through the casperjs documentation I couldn't find where I could see the console.log from client-side javascript. Is this possible?

like image 879
Abhik Bose Pramanik Avatar asked May 24 '12 21:05

Abhik Bose Pramanik


1 Answers

I'm not really sure to fully understand your question, but you can do something like the following:

var casper = require('casper').create({
    logLevel: "debug"
});

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

casper.start('http://google.com/', function() {
    this.evaluate(function sendLog(log) {
        // you can access the log from page DOM
        console.log('from the browser, I can tell you there are ' + log.length + ' entries in the log');
    }, this.result.log);
});

casper.run();

Output:

$ casperjs log.js 
from the browser, I can tell you there are 4 entries
like image 82
NiKo Avatar answered Nov 15 '22 15:11

NiKo