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

Output client-side console with casper/phantomjs

本文关键字:输出 客户端 控制台 phantomjs casper 带有      更新时间:2023-09-26

浏览 casperjs 文档时,我找不到在哪里可以看到控制台.log从客户端 javascript 中。这可能吗?

我不太确定是否完全理解您的问题,但您可以执行以下操作:

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