Hide errors and warnings from the console

In PHP and other languages, there are ways to suppress error / warning messages.

Is there a way in javascript or jquery to prevent errors and warnings from being written to the console log?

+10
javascript jquery
source share
5 answers

You can handle errors to some extent, but if the error is not handled by you, it goes to the browser and you cannot stop the browser from displaying. You can write code in such a way as to get a minimal error and use try-catch , where possible, to handle exceptions.

 try { //statements suspected to throw exception. } catch(e) { } 
+13
source share

This is browser-based functionality, you can install any browser add-on, then you can hide errors / warnings

I went to about:config for Firefox and turned javascript.options.strict to false and the warnings were gone. But I feel that this is not a solution.

 howtocreate.co.uk/strictJSFirefox.html 
+1
source share

just add some code to the script, it will work.! Chromium:

 console._commandLineAPI.clear(); 

Safari:

 console._inspectorCommandLineAPI.clear(); 

You can create your own variable that works in both:

 if (typeof console._commandLineAPI !== 'undefined') { console.API = console._commandLineAPI; } else if (typeof console._inspectorCommandLineAPI !== 'undefined') { console.API = console._inspectorCommandLineAPI; } else if (typeof console.clear !== 'undefined') { console.API = console; } 

After that you can simply use

 console.API.clear(). 
0
source share

After doing some research and development for this problem, I came across this solution, which will hide the warnings / errors / logs of your choice.

 (function () { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { console.warn = function () { }; window['console']['warn'] = function () { }; // For confirmation again this.addEventListener('load', function () { console.warn('Something bad happened.'); window['console']['warn'] = function () { }; }); }; })(); 

Add this code before the jQuery plugin (e.g. / .. / jquery.min.js), even if this JavaScript code does not require jQuery. Because some warnings are in jQuery itself.

0
source share

Best for user console.clear (); in 90% of your cases this will be resolved

0
source share

All Articles