(page: Page | Frame)
| 86 | * - ARIA labels with injection patterns |
| 87 | */ |
| 88 | export async function markHiddenElements(page: Page | Frame): Promise<string[]> { |
| 89 | return page.evaluate((ariaPatterns: string[]) => { |
| 90 | const found: string[] = []; |
| 91 | const elements = document.querySelectorAll('body *'); |
| 92 | |
| 93 | for (const el of elements) { |
| 94 | if (el instanceof HTMLElement) { |
| 95 | const style = window.getComputedStyle(el); |
| 96 | const text = el.textContent?.trim() || ''; |
| 97 | if (!text) continue; // skip empty elements |
| 98 | |
| 99 | let isHidden = false; |
| 100 | let reason = ''; |
| 101 | |
| 102 | // Check opacity |
| 103 | if (parseFloat(style.opacity) < 0.1) { |
| 104 | isHidden = true; |
| 105 | reason = 'opacity < 0.1'; |
| 106 | } |
| 107 | // Check font-size |
| 108 | else if (parseFloat(style.fontSize) < 1) { |
| 109 | isHidden = true; |
| 110 | reason = 'font-size < 1px'; |
| 111 | } |
| 112 | // Check off-screen positioning |
| 113 | else if (style.position === 'absolute' || style.position === 'fixed') { |
| 114 | const rect = el.getBoundingClientRect(); |
| 115 | if (rect.right < -100 || rect.bottom < -100 || rect.left > window.innerWidth + 100 || rect.top > window.innerHeight + 100) { |
| 116 | isHidden = true; |
| 117 | reason = 'off-screen'; |
| 118 | } |
| 119 | } |
| 120 | // Check same fg/bg color (text hiding) |
| 121 | else if (style.color === style.backgroundColor && text.length > 10) { |
| 122 | isHidden = true; |
| 123 | reason = 'same fg/bg color'; |
| 124 | } |
| 125 | // Check clip-path hiding |
| 126 | else if (style.clipPath === 'inset(100%)' || style.clip === 'rect(0px, 0px, 0px, 0px)') { |
| 127 | isHidden = true; |
| 128 | reason = 'clip hiding'; |
| 129 | } |
| 130 | // Check visibility: hidden |
| 131 | else if (style.visibility === 'hidden') { |
| 132 | isHidden = true; |
| 133 | reason = 'visibility hidden'; |
| 134 | } |
| 135 | |
| 136 | if (isHidden) { |
| 137 | el.setAttribute('data-gstack-hidden', 'true'); |
| 138 | found.push(`[${el.tagName.toLowerCase()}] ${reason}: "${text.slice(0, 60)}..."`); |
| 139 | } |
| 140 | |
| 141 | // Check ARIA labels for injection patterns |
| 142 | const ariaLabel = el.getAttribute('aria-label') || ''; |
| 143 | const ariaLabelledBy = el.getAttribute('aria-labelledby'); |
| 144 | let labelText = ariaLabel; |
| 145 | if (ariaLabelledBy) { |
no test coverage detected