How to clear javascript console programmatically?

How can we clear the console in Chrome, Firefox and other browsers. I tried the following commands but no one works:

Chrome: clear()

Firefox: console.clear()

Any ideas?

+6
source share
2 answers

It is different for each browser, so you can write a script to make it work for different browsers. or you can use this script

console.API;

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

console.API.clear();
Run codeHide result

for other browsers.

Note. Successfully tested (after editing, 08/2016) on Safari v9.1 for Mac OS and Chrome v52.0 for Mac OS

+18
source

In Firefox, as of July 25, 2019, I first tried typing:

console.API.clear();

, console.API . , , -, , , , , :

console.clear();

, , . , , Firefox, , , , .

+1

Source: https://habr.com/ru/post/1016513/


All Articles