diff --git a/index.js b/index.js index 196d467..10dffdf 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,9 @@ const devtools = { orientation: undefined, }; -const threshold = 170; +// Increased threshold to reduce false positives on high-resolution and vertical monitors +// Previous value of 170 caused false positives on 1920x1980 and similar resolutions +const threshold = 200; const emitEvent = (isOpen, orientation) => { globalThis.dispatchEvent(new globalThis.CustomEvent('devtoolschange', { @@ -22,8 +24,15 @@ const emitEvent = (isOpen, orientation) => { }; const main = ({emitEvents = true} = {}) => { - const widthThreshold = globalThis.outerWidth - globalThis.innerWidth > threshold; - const heightThreshold = globalThis.outerHeight - globalThis.innerHeight > threshold; + // Calculate the difference between outer and inner window dimensions + const widthDifference = globalThis.outerWidth - globalThis.innerWidth; + const heightDifference = globalThis.outerHeight - globalThis.innerHeight; + + // Check if the differences exceed the threshold + // Added additional check: differences should be reasonable (< 600) to avoid false positives + // on unusual monitor configurations like 1920x1980 vertical displays + const widthThreshold = widthDifference > threshold && widthDifference < 600; + const heightThreshold = heightDifference > threshold && heightDifference < 600; const orientation = widthThreshold ? 'vertical' : 'horizontal'; if (