输出带有casper/phantomjs的客户端控制台

Abh*_*nik 20 javascript console headless-browser phantomjs casperjs

通过casperjs文档我无法找到从客户端javascript中看到console.log的位置.这可能吗?

NiK*_*iKo 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();
Run Code Online (Sandbox Code Playgroud)

输出:

$ casperjs log.js 
from the browser, I can tell you there are 4 entries
Run Code Online (Sandbox Code Playgroud)