与卡斯帕/ phantomjs输出客户端控制台(Output client-side console

2019-06-24 19:08发布

通过casperjs文档去我找不到在那里我可以看到从客户端JavaScript中的console.log。 这可能吗?

Answer 1:

我真的不知道要充分了解你的问题,但你可以做类似如下:

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


文章来源: Output client-side console with casper/phantomjs