Skip to content

Instantly share code, notes, and snippets.

@faridv
Created August 4, 2019 17:17
Show Gist options
  • Save faridv/9424e519772bec775cbfc50832879145 to your computer and use it in GitHub Desktop.
Save faridv/9424e519772bec775cbfc50832879145 to your computer and use it in GitHub Desktop.
(function takeOverConsole() {
var console = window.console;
function intercept(method) {
var original = console[method];
console[method] = function () {
var message = Array.prototype.slice.apply(arguments).join(' ');
original.call(console, arguments);
var xhr = new XMLHttpRequest();
// xhr.open('get', '/log.php?error=' + message);
xhr.open('get', '/log.php?error=' + JSON.stringify(arguments));
xhr.send();
}
}
// var methods = ['warn', 'error']
var methods = ['error'];
for (var i = 0; i < methods.length; i++)
intercept(methods[i]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment