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 回答