Allen S
Allen S

Reputation: 3539

JS/jQuery: Is it possible to extract content from the browser's console?

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?

Upvotes: 1

Views: 121

Answers (1)

eskimomatt
eskimomatt

Reputation: 185

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);

Upvotes: 1

Related Questions