More contrast/visibility fixes

This commit is contained in:
Josh at WLTechBlog
2025-12-09 12:01:55 -07:00
parent 0c8622294b
commit a5c71c0509

View File

@@ -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;