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 writte
I usually just go to the implementation of the function that includes that particular console.log warning and comment it out.
This is browser based functionality, you may install any addon for browser then you can hide errors/ warnings
I went to about:config
for Firefox and turned javascript.options.strict
to false and the warnings went away. But I feel like this is not a solution.
howtocreate.co.uk/strictJSFirefox.html
Best to user console.clear(); in 90% of your cases it will be resolved
you just simply add some chunk of code into the script it will works.! Chrome:
console._commandLineAPI.clear();
Safari:
console._inspectorCommandLineAPI.clear();
You can create your own variable, which 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().
A dirty way to hide all Javascript console warnings is by overriding the console object's warn
method:
console.warn = () => {};
Obviously, it also works with other console methods
You can handle errors to some extent but if error is not handled by you then it goes to browser and you can not stop browser showing it. You can write code in such a way that you get minimum error and using try-catch
where possible to handle the exceptions.
try
{
//statements suspected to throw exception.
}
catch(e)
{
}