(page: import("puppeteer-core").Page)
| 142 | } |
| 143 | |
| 144 | async function runContrastAudit(page: import("puppeteer-core").Page): Promise<ContrastEntry[]> { |
| 145 | const duration = await getCompositionDuration(page); |
| 146 | if (duration <= 0) return []; |
| 147 | |
| 148 | await page.addScriptTag({ content: loadContrastAuditScript() }); |
| 149 | |
| 150 | const results: ContrastEntry[] = []; |
| 151 | for (let i = 0; i < CONTRAST_SAMPLES; i++) { |
| 152 | const t = +(((i + 0.5) / CONTRAST_SAMPLES) * duration).toFixed(3); |
| 153 | await seekTo(page, t); |
| 154 | |
| 155 | const screenshot = (await page.screenshot({ encoding: "base64", type: "png" })) as string; |
| 156 | const entries = await page.evaluate( |
| 157 | (b64: string, time: number) => |
| 158 | typeof (window as unknown as Record<string, unknown>).__contrastAudit === "function" |
| 159 | ? ((window as unknown as Record<string, unknown>).__contrastAudit as Function)(b64, time) |
| 160 | : [], |
| 161 | screenshot, |
| 162 | t, |
| 163 | ); |
| 164 | results.push(...(entries as ContrastEntry[])); |
| 165 | } |
| 166 | |
| 167 | return results; |
| 168 | } |
| 169 | |
| 170 | function loadContrastAuditScript(): string { |
| 171 | const candidates = [ |
no test coverage detected