Skip to content

Instantly share code, notes, and snippets.

@burhanuddin7
Created November 8, 2022 10:33
Show Gist options
  • Save burhanuddin7/3852549be0947c9f8b530cba7b89c567 to your computer and use it in GitHub Desktop.
Save burhanuddin7/3852549be0947c9f8b530cba7b89c567 to your computer and use it in GitHub Desktop.
/***
**
Ref: https://github.com/sindresorhus/devtools-detect
***/
var devtools = {
isOpen: false,
orientation: undefined,
},
threshold = 160;
// for older browser version check for globalThis object
if (typeof globalThis === 'undefined') {
var globalThis = window;
}
var emitEvent = function emitEvent(isOpen, orientation) {
globalThis.dispatchEvent(new globalThis.CustomEvent('devtoolschange', {
detail: {
isOpen: isOpen,
orientation: orientation
}
}));
};
var detectDevtoolsFn = function detectDevtoolsFn() {
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0],
_refEmitEvents = _ref.emitEvents,
emitEvents = _refEmitEvents === undefined ? true : _refEmitEvents;
var widthThreshold = globalThis.outerWidth - globalThis.innerWidth > threshold,
heightThreshold = globalThis.outerHeight - globalThis.innerHeight > threshold,
orientation = widthThreshold ? 'vertical' : 'horizontal';
if (!(heightThreshold && widthThreshold) && (globalThis.Firebug && globalThis.Firebug.chrome && globalThis.Firebug.chrome.isInitialized || widthThreshold || heightThreshold)) {
if ((!devtools.isOpen || devtools.orientation !== orientation) && emitEvents) {
emitEvent(true, orientation);
}
devtools.isOpen = true;
devtools.orientation = orientation;
} else {
if (devtools.isOpen && emitEvents) {
emitEvent(false, undefined);
}
devtools.isOpen = false;
devtools.orientation = undefined;
}
};
window.addEventListener("load", function() {
// call devtools fn to check if it is open or not
detectDevtoolsFn({ emitEvents: false });
if (devtools.isOpen) {
console.log('DevTools is open on Browser Window!');
} else {
console.log('DevTools is closed on Browser Window!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment