Complementing the @Julianonunes response, you can create a function for this, as the variable will continue with the value true
if the user opens the console and then closes it. Thus, you can run it whenever you check whether the Console is open or not. So you can do:
// set interval que testa se o console está aberto
setInterval(function(){
document.body.innerText = isDevtoolsOpened();
}, 1000);
// função que faz a verificação
function isConsoleOpened() {
let devtools = /./;
devtools.toString = function() {
this.opened = true;
}
console.log("%c", devtools);
return devtools.opened ? true : false;
}
It is also worth remembering that if the function console.log()
is superscripted, as in stacksnippets, this will not work, since the function can be triggered at any time, regardless of whether the Console is open or not.
Close the console seems impossible, after all it would be a security failure of the browsers to let the developers perform this process. Formerly could block access to it, a feature that Facebook had created, but is already outdated.
cool, there is a way to close the console.log?
– Ivan Ferrer
I believe this is not possible because you would be interfering in the way the browser works.
– echojn
Does this work for other browsers? The question you linked mentions Chrome.
– Renan Gomes