1

When I do console.log(info) is it possible to later use JS to extract everything from the browsers console and add it to a var? I would like to extract all contents of the console and send it to the server through AJAX

Basically I'm looking for something like:

var console_content = console.read();

Is there anything in JS or jQuery that will make this possible?

Allen S
  • 3,471
  • 4
  • 34
  • 46
  • possible duplicate of [Can you programmatically access the Firebug console output?](http://stackoverflow.com/questions/4375522/can-you-programmatically-access-the-firebug-console-output) – mayrs Apr 15 '14 at 13:31

1 Answers1

1

instead of writing to the console (which you really shouldn't do in a production environment) why not just push each thing you want to log to an array and then pass it to the server with a PUT when you want to?:

var _log = [];

//instead of console.log(message)

_log.push({message:'message goes here'});

//using jquery because it's easier
function pushAjax(url, data, callback, method) {
    return jQuery.ajax({
        url: url,
        type: method,
        data: data,
        success: callback
    });
}

//call your push function when you want...
pushAjax('www.yourserver.com',_log,'PUT',successFunction);
eskimomatt
  • 195
  • 9
  • What about errors that are reflected in the console that you didn't log? E.g. library generated errors, or when some exception occurs? – Allen S Apr 16 '14 at 08:19