日々精進

新しく学んだことを書き留めていきます

CasperJSのヘッドレスブラウザ内のconsole.logの出力をコンソールに出す

普通にthis.evaluateの中でconsole.logを実行してもコンソールには出力されない。
そのconsole.logはヘッドレスブラウザの中で実行されるので。
コンソールに出力させるには以下のようにする。

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

CasperJSのデバッグしんどいなぁ。ステップ実行できるようにならないかな。。
参考:javascript - Output client-side console with casper/phantomjs - Stack Overflow