Complementing @JulianoNunes's response, you can create a function for this, because the variable will continue with the true
value if the user opens the console and then closes it. So you can run it every time 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 should also be noted that if the console.log()
function is overwritten, 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 does not seem possible , after all it would be a security flaw for browsers to let developers do this process. In the past could block access to it, a feature which Facebook had created, but is already out of date.