Skip to content

Instantly share code, notes, and snippets.

@oussamahamdaoui
Last active January 29, 2024 10:04
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save oussamahamdaoui/36d2e154503aec714c04f5df1c6edef3 to your computer and use it in GitHub Desktop.
Detect devtools open and close events tested on Chrome and Safari
(function() {
'use strict';
const el = new Image();
let consoleIsOpen = false;
let consoleOpened = false;
Object.defineProperty(el, 'id', {
get: () => {
consoleIsOpen = true;
}
});
const verify = () => {
console.dir(el);
if (consoleIsOpen === false && consoleOpened === true) {
// console closed
window.dispatchEvent(new Event('devtools-opened'));
consoleOpened = false;
} else if (consoleIsOpen === true && consoleOpened === false) {
// console opened
window.dispatchEvent(new Event('devtools-closed'));
consoleOpened = true;
}
consoleIsOpen = false;
setTimeout(verify, 1000);
}
verify();
})();
// Use like this
// window.addEventListener('devtools-opened', ()=>{});
// window.addEventListener('devtools-closed', ()=>{});
@eczn
Copy link

eczn commented Nov 20, 2023

interesting

@zekageri
Copy link

Tested on chrome and brave.
It just flooding the console with some img

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment