Reputation: 51
Can we remove or hide errors and warnings from the console? Is there a way in Javascript or jQuery to prevent errors and warnings from being written to the console?
Upvotes: 5
Views: 14769
Reputation: 337560
You can redefine window.console
to remove the logging features:
var noOp = function() {}
window.console = {
log: noOp,
dir: noOp
// all other methods...
};
console.log('foo'); // nothing happens
Alternatively you can call console.clear()
to remove all existing items within the console.
However I wouldn't advise doing either of these. A much better approach would be to fix your codebase so that you avoid errors and implement graceful error handling where unexpected errors may occur. You can achieve the latter through try
/catch
blocks.
Upvotes: 8
Reputation: 101
Redefine your console log function like below
console.log = function() {}
Upvotes: 0
Reputation: 1206
There are two way you can manage it,
console.clear()
Or a try/catch
block
Upvotes: 2