From a5c71c05091940a2474647c711c964107aa03363 Mon Sep 17 00:00:00 2001 From: Josh at WLTechBlog Date: Tue, 9 Dec 2025 12:01:55 -0700 Subject: [PATCH] More contrast/visibility fixes --- daemon/daemon.go | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 66cfdd1..a609f73 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -9227,20 +9227,47 @@ func (d *Daemon) checkContrast(tabID string, selector string, timeout int) (*Con // Get computed styles const style = window.getComputedStyle(element); + // COMPREHENSIVE VISIBILITY CHECK // Skip elements that are not visible (WCAG only applies to visible content) - // Check for display: none, visibility: hidden, opacity: 0 - if (style.display === 'none' || - style.visibility === 'hidden' || - parseFloat(style.opacity) === 0) { + + // Method 1: Check CSS properties + const display = style.display; + const visibility = style.visibility; + const opacity = parseFloat(style.opacity); + + if (display === 'none' || visibility === 'hidden' || opacity === 0) { return; } - // Also skip if element has no dimensions (effectively hidden) + // Method 2: Check dimensions (effectively hidden) const rect = element.getBoundingClientRect(); if (rect.width === 0 || rect.height === 0) { return; } + // Method 3: Check if element or any parent has display: none + // This catches cases where parent containers are hidden + let parent = element.parentElement; + while (parent && parent !== document.body) { + const parentStyle = window.getComputedStyle(parent); + if (parentStyle.display === 'none' || + parentStyle.visibility === 'hidden' || + parseFloat(parentStyle.opacity) === 0) { + return; + } + parent = parent.parentElement; + } + + // Method 4: Use offsetParent check (null means element is not rendered) + // This is the most reliable check for display:none and visibility:hidden + if (element.offsetParent === null && element.tagName !== 'BODY') { + // Exception: fixed/sticky positioned elements have null offsetParent but are visible + const position = style.position; + if (position !== 'fixed' && position !== 'sticky') { + return; + } + } + const fgColor = style.color; const fontSize = style.fontSize; const fontWeight = style.fontWeight;