sharp
sharp

Reputation: 633

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?

Upvotes: 1

Views: 85

Answers (2)

Artjom B.
Artjom B.

Reputation: 61892

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");
});
...

Upvotes: 0

Maroun Baydoun
Maroun Baydoun

Reputation: 464

//Keep a reference to the original function
var original = console.log;

//Override the function
console.log = function(arg) {

   //Do what you want with the arguments of the function
   ....

  //Call the original function
  original.call(this, arguments);
}    

Upvotes: 0

Related Questions