Hide message source in browser inspector

4

Is there a way to hide the route shown to the right of the JS console when a message is generated?

Let me explain, for example, when you generate a console.log(""); it tells you that the Virtual Machine generated it, well, that route appears when I generate messages in the console and it tells me what file and what line generated it.

There are some messages that I send to the console but I do not want to know where it was generated, that is, I do not want them to know where it was generated, only to see it as it is informative.

Example of this is for example when you open the console on Facebook, a message appears but it does not show the route that generates it.

How can you do that?

and neither the log it generates when executing this function:

//Función que borra el log generado en la consola según el navegador
    function clearConsole() {
        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;
        }
        console.API.clear();
    }
    
asked by Fabian Montoya 03.02.2017 в 18:30
source

1 answer

7

You can do it like this:

setTimeout(console.log.bind(console, 'Mesaje'));

We have to:

  • Using fn.bind , you get a new one function fn with pre-set parameters.

  • Using setTimeout : we execute a function.

As the function console.log is native code, when using console.log.bind we generate a function console.log with pre-set parameters and with setTimeout we can execute it. In this way we can ensure that the " origin " is not printed.

// Update

To prevent your clearConsole function from displaying the " source ", you can do so:

function clearConsole() {
        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;
        }

        if (console.API) {
          setTimeout(console.API.clear.bind(console));
        }
    }
    
answered by 03.02.2017 / 19:43
source