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?

1

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

What about errors that are reflected in the console that you didn't log? E.g. library generated errors, or when some exception occurs?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.