Skip to content

Instantly share code, notes, and snippets.

@kevgathuku
Last active May 6, 2019 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevgathuku/b6fcc0bf1d5e478f4ed6876b0cc01c0c to your computer and use it in GitHub Desktop.
Save kevgathuku/b6fcc0bf1d5e478f4ed6876b0cc01c0c to your computer and use it in GitHub Desktop.
Detect if Chrome Devtools is open (Doesn't work on Firefox)
// https://stackoverflow.com/a/30638226
// When printing an “Element” Chrome developer tools will request the 'id' property
// If the 'id' property is fetched, then the devtools is open
let checkStatus;
let customElement = document.createElement('p');
document.body.appendChild(customToString);
let element = new Image();
Object.defineProperty(element, 'id', {
get: () => {
checkStatus = 'on';
customElement.textContent = checkStatus;
},
});
// Disadvantage: Called too many times :(
requestAnimationFrame(function loop() {
checkStatus = 'off';
console.log('%c', element);
customElement.textContent = checkStatus;
requestAnimationFrame(loop);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment