Hide errors and warnings from console

后端 未结 7 975
梦如初夏
梦如初夏 2021-01-01 23:11

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

相关标签:
7条回答
  • 2021-01-01 23:12

    I usually just go to the implementation of the function that includes that particular console.log warning and comment it out.

    0 讨论(0)
  • 2021-01-01 23:15

    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 
    
    0 讨论(0)
  • 2021-01-01 23:15

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

    0 讨论(0)
  • 2021-01-01 23:19

    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().
    
    0 讨论(0)
  • 2021-01-01 23:24

    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

    0 讨论(0)
  • 2021-01-01 23:28

    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)
    {
    }
    
    0 讨论(0)
提交回复
热议问题