I'm looking for a way to use JavaScript to store debug messages that appear in the Chrome console when xmlhttprequests are performed. Example output provided below:
Thanks in advance!
I'm looking for a way to use JavaScript to store debug messages that appear in the Chrome console when xmlhttprequests are performed. Example output provided below:
Thanks in advance!
You cannot read console messages from JavaScript. You will not be able to read these messages.
However, using the same general concept as John Culviner's answer to Add a “hook” to all AJAX requests on a page, you can detect the events in JavaScript that cause these messages to appear.
(function() {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
this.addEventListener('load', function() {
console.log('XHR finished loading', method, url);
});
this.addEventListener('error', function() {
console.log('XHR errored out', method, url);
});
origOpen.apply(this, arguments);
};
})();
This overwrites every XHR object's open method with a new function that adds load and error listeners to the XHR request. When the request completes or errors out, the functions have access to the method and url variables that were used with the open method.
You can do something more useful with method and url than simply passing them into console.log if you wish.
possible dublicate How to read from Chrome's console in JavaScript