From b089cbf11c6e2b32b0e0815627c07ba97ef4a69c Mon Sep 17 00:00:00 2001 From: Shadow Date: Fri, 6 Feb 2026 11:52:57 +0100 Subject: [PATCH] fix: reduce false positives on high-resolution and vertical monitors (fixes #33) Changes: - Increased threshold from 170 to 200 pixels - Added upper bound check (<600) to filter out unusual monitor configurations - Prevents false positives on 1920x1980 and similar vertical/portrait resolutions The previous threshold of 170 was causing false positives on monitors with unusual aspect ratios like 1920x1980. The new logic requires the dimension difference to be both greater than 200 AND less than 600, which better distinguishes actual DevTools panels from normal browser chrome on high-res displays. Fixes #33 Bounty: (IssueHunt) --- index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 (