Created
November 8, 2022 10:33
-
-
Save burhanuddin7/3852549be0947c9f8b530cba7b89c567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
** | |
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