javascript 使用 casper/phantomjs 输出客户端控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10745345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:53:50 来源:igfitidea点击:
Output client-side console with casper/phantomjs
提问by Abhik Bose Pramanik
Going through the casperjs documentation I couldn't find where I could see the console.log from client-side javascript. Is this possible?
通过 casperjs 文档,我找不到可以从客户端 javascript 看到 console.log 的地方。这可能吗?
回答by NiKo
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