20

casperjs のドキュメントを調べたところ、クライアント側の JavaScript から console.log を確認できる場所が見つかりませんでした。これは可能ですか?

4

1 に答える 1

44

あなたの質問を完全に理解できるかどうかはわかりませんが、次のようなことができます。

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

出力:

$ casperjs log.js 
from the browser, I can tell you there are 4 entries
于 2012-05-28T11:09:07.270 に答える