0
我使用CasperJS來捕獲瀏覽器控制檯的日誌,但它不起作用。如何在CasperJS中輸出客戶端console.log?
var casper = require('casper').create({
logLevel: "debug"
});
var domain, port, userName, designID, token, outPath, reportUrl, explorerUrl, sourcePage;
var images = [];
if(casper.cli.has(5)){
// Get argvs
domain = casper.cli.get(0).toLowerCase();
port = casper.cli.get(1);
userName = casper.cli.get(2);
designID = casper.cli.get(3);
token = casper.cli.get(4);
outPath = casper.cli.get(5);
}
reportUrl = 'http://' + domain + ':' + port + '/design?file_id=' + designID;
casper.on('remote.message', function(message) {
this.log('remote message caught: ' + message);
});
casper.start(reportUrl, 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();
在Chrome中,頁面會輸出一些日誌,如:
get userdata
get designdata
Success!
但在CasperJS,它不輸出任何日誌。