javascriptautomationcasperjs

How to retrieve browser web console log and write it into a file?


I am trying to process the log from a specific webpage. Are there any suggestions how to retrieve the logs and put into text file from any web page using CasperJS?


Solution

  • You can use the remote.message event to receive all console.log() from the page. Using that, you can write them into a file using PhantomJS' fs module (fs.write()).

    var fs = require('fs');
    casper.on("remote.message", function(msg){
        fs.write("file", msg+"\n", "a");
    });
    ...