Output client-side console with casper/phantomjs

蓝咒 提交于 2019-12-30 03:44:16

问题


Going through the casperjs documentation I couldn't find where I could see the console.log from client-side javascript. Is this possible?


回答1:


I'm not really sure to fully understand your question, but you can do something like the following:

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

Output:

$ casperjs log.js 
from the browser, I can tell you there are 4 entries


来源:https://stackoverflow.com/questions/10745345/output-client-side-console-with-casper-phantomjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!