Skip to content

Instantly share code, notes, and snippets.

@teawithfruit
Created January 28, 2020 14:12
Show Gist options
  • Save teawithfruit/994b4d0e0a9e4373669da72eb7032a56 to your computer and use it in GitHub Desktop.
Save teawithfruit/994b4d0e0a9e4373669da72eb7032a56 to your computer and use it in GitHub Desktop.
A function for hijacking the console
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