a11y-toolkit: Live-element contrast sampling
a11y_contrast_domMeasures real contrast ratio of text against its actual background (image, gradient, video) on a live page, automating screenshot and pixel sampling for WCAG checks.
Instructions
REAL contrast of an element against whatever is behind it (image, gradient, video, photo): loads the page in Chromium, screenshots the element matched by selector with its text turned transparent — so only the real background is sampled, no text pixels, no antialiasing edges — and contrasts the pixels with the text color (computed from the element when not given). The automated version of a11y_contrast_image: no manual screenshot, no region math. Requires local Playwright. — Use instead of a11y_contrast_image when the text lives in a live page (captures and measures it automatically); for flat pairs use a11y_contrast_pair. Returns JSON: {url, selector, text_color, worst_ratio, median_ratio, p95_ratio, area_passes_aa_normal_text_4_5, worst_zone?, sampled_pixels, interpretation}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | Page URL where the element lives (http/https or file://) | |
| lang | No | Output language (default en) | |
| sample | No | Pixel step (default 4) | |
| browser | No | Browser engine (auto = detect the first available) | |
| timeout | No | Page load timeout seconds (default 45) | |
| selector | Yes | CSS selector of the text element to measure | |
| auth_state | No | Path to a Playwright storage_state JSON to measure behind login — stays local | |
| text_color | No | Text color (default: computed from the element) |