Created
January 28, 2020 14:12
-
-
Save teawithfruit/994b4d0e0a9e4373669da72eb7032a56 to your computer and use it in GitHub Desktop.
A function for hijacking the console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
captureConsole() { | |
let console = window.console | |
if(!console) return | |
function intercept(method) { | |
let original = console[method] | |
console[method] = function() { | |
if(original.apply) { | |
// do something with arguments | |
original.apply(console, arguments) | |
} else { | |
let message = Array.prototype.slice.apply(arguments).join(' ') | |
// do something with message | |
original(message) | |
} | |
} | |
} | |
const methods = ['log', 'warn', 'error'] | |
for(const tupel of methods) { | |
intercept(tupel) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment