Skip to content

Commit 9a73b60

Browse files
committed
Reformat
1 parent 569dbe6 commit 9a73b60

1 file changed

Lines changed: 60 additions & 30 deletions

File tree

skills/a11y-debugging/SKILL.md

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ description: Uses Chrome DevTools MCP for accessibility (a11y) debugging and aud
1414
### 1. Browser Issues & Audits
1515

1616
Chrome automatically checks for common accessibility problems. Use `list_console_messages` to check for these native audits first:
17-
- `types`: `["issue"]`
18-
- `includePreservedMessages`: `true` (to catch issues that occurred during page load)
17+
18+
- `types`: `["issue"]`
19+
- `includePreservedMessages`: `true` (to catch issues that occurred during page load)
1920

2021
This often reveals missing labels, invalid ARIA attributes, and other critical errors without manual investigation.
2122

@@ -35,14 +36,24 @@ The accessibility tree exposes the heading hierarchy and semantic landmarks.
3536
3. **Orphaned Inputs**: Verify that all form inputs have associated labels. Use `evaluate_script` to check for inputs missing `id` (for `label[for]`) or `aria-label`:
3637
```javascript
3738
() => {
38-
const inputs = Array.from(document.querySelectorAll('input, select, textarea'));
39-
return inputs.filter(i => {
40-
const hasId = i.id && document.querySelector(`label[for="${i.id}"]`);
41-
const hasAria = i.getAttribute('aria-label') || i.getAttribute('aria-labelledby');
42-
const hasImplicitLabel = i.closest('label');
43-
return !hasId && !hasAria && !hasImplicitLabel;
44-
}).map(i => ({ tag: i.tagName, id: i.id, name: i.name, placeholder: i.placeholder }));
45-
}
39+
const inputs = Array.from(
40+
document.querySelectorAll('input, select, textarea'),
41+
);
42+
return inputs
43+
.filter(i => {
44+
const hasId = i.id && document.querySelector(`label[for="${i.id}"]`);
45+
const hasAria =
46+
i.getAttribute('aria-label') || i.getAttribute('aria-labelledby');
47+
const hasImplicitLabel = i.closest('label');
48+
return !hasId && !hasAria && !hasImplicitLabel;
49+
})
50+
.map(i => ({
51+
tag: i.tagName,
52+
id: i.id,
53+
name: i.name,
54+
placeholder: i.placeholder,
55+
}));
56+
};
4657
```
4758
4. Check images for `alt` text.
4859

@@ -54,8 +65,13 @@ Testing "keyboard traps" and proper focus management without visual feedback rel
5465
```javascript
5566
() => {
5667
const active = document.activeElement;
57-
return { tag: active.tagName, id: active.id, className: active.className, text: active.innerText };
58-
}
68+
return {
69+
tag: active.tagName,
70+
id: active.id,
71+
className: active.className,
72+
text: active.innerText,
73+
};
74+
};
5975
```
6076
2. Use the `press_key` tool with `"Tab"` or `"Shift+Tab"` to move focus.
6177
3. Re-run the script in step 1 to ensure focus moved to the expected next interactive element.
@@ -66,22 +82,25 @@ Testing "keyboard traps" and proper focus management without visual feedback rel
6682
According to web.dev, tap targets should be at least 48x48 pixels with sufficient spacing. Since the accessibility tree doesn't show sizes, use `evaluate_script`:
6783
6884
```javascript
69-
(el) => {
85+
el => {
7086
const rect = el.getBoundingClientRect();
71-
return { width: rect.width, height: rect.height };
72-
}
87+
return {width: rect.width, height: rect.height};
88+
};
7389
```
74-
*Pass the element's `uid` from the snapshot as an argument to the tool.*
90+
91+
_Pass the element's `uid` from the snapshot as an argument to the tool._
7592

7693
### 6. Color Contrast
7794

78-
To verify color contrast ratios without the DevTools UI, use `evaluate_script` to compute the relative luminance of the text (`color`) and background (`backgroundColor`).
95+
To verify color contrast ratios without the DevTools UI, use `evaluate_script` to compute the relative luminance of the text (`color`) and background (`backgroundColor`).
7996

8097
```javascript
81-
(el) => {
98+
el => {
8299
function getRGB(colorStr) {
83100
const match = colorStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
84-
return match ? [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])] : [255, 255, 255];
101+
return match
102+
? [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])]
103+
: [255, 255, 255];
85104
}
86105
function luminance(r, g, b) {
87106
const a = [r, g, b].map(function (v) {
@@ -90,20 +109,25 @@ To verify color contrast ratios without the DevTools UI, use `evaluate_script` t
90109
});
91110
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
92111
}
93-
112+
94113
const style = window.getComputedStyle(el);
95114
const fg = getRGB(style.color);
96115
let bg = getRGB(style.backgroundColor);
97-
116+
98117
// Basic contrast calculation (Note: Doesn't account for transparency over background images)
99118
const l1 = luminance(fg[0], fg[1], fg[2]);
100119
const l2 = luminance(bg[0], bg[1], bg[2]);
101120
const ratio = (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
102-
103-
return { color: style.color, bg: style.backgroundColor, contrastRatio: ratio.toFixed(2) };
104-
}
121+
122+
return {
123+
color: style.color,
124+
bg: style.backgroundColor,
125+
contrastRatio: ratio.toFixed(2),
126+
};
127+
};
105128
```
106-
*Pass the element's `uid` to test the contrast against WCAG AA (4.5:1 for normal text, 3:1 for large text).*
129+
130+
_Pass the element's `uid` to test the contrast against WCAG AA (4.5:1 for normal text, 3:1 for large text)._
107131
108132
### 7. Global Page Checks
109133
@@ -112,16 +136,22 @@ Verify document-level accessibility settings often missed in component testing:
112136
```javascript
113137
() => {
114138
return {
115-
lang: document.documentElement.lang || 'MISSING - Screen readers need this for pronunciation',
139+
lang:
140+
document.documentElement.lang ||
141+
'MISSING - Screen readers need this for pronunciation',
116142
title: document.title || 'MISSING - Required for context',
117-
viewport: document.querySelector('meta[name="viewport"]')?.content || 'MISSING - Check for user-scalable=no (bad practice)',
118-
reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'Enabled' : 'Disabled'
143+
viewport:
144+
document.querySelector('meta[name="viewport"]')?.content ||
145+
'MISSING - Check for user-scalable=no (bad practice)',
146+
reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches
147+
? 'Enabled'
148+
: 'Disabled',
119149
};
120-
}
150+
};
121151
```
122152
123153
## Troubleshooting
124154
125155
If standard a11y queries fail or the `evaluate_script` snippets return unexpected results:
126156
127-
* **Visual Inspection**: If automated scripts cannot determine contrast (e.g., text over gradient images or complex backgrounds), use `take_screenshot` to capture the element. While models cannot measure exact contrast ratios from images, they can visually assess legibility and identifying obvious issues.
157+
- **Visual Inspection**: If automated scripts cannot determine contrast (e.g., text over gradient images or complex backgrounds), use `take_screenshot` to capture the element. While models cannot measure exact contrast ratios from images, they can visually assess legibility and identifying obvious issues.

0 commit comments

Comments
 (0)