mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-11-04 15:00:11 +00:00
refactor: simplify JavaScript code examples, update code block language, and refine descriptions in a11y debugging skill documentation. (#1009)
This commit is contained in:
1 parent
33446d457e
commit
5cedcaad2c
1 file changed
+21
-35
@@ -7,7 +7,7 @@ description: Uses Chrome DevTools MCP for accessibility (a11y) debugging and aud
|
||||
|
||||
**Accessibility Tree vs DOM**: Visually hiding an element (e.g., `CSS opacity: 0`) behaves differently for screen readers than `display: none` or `aria-hidden="true"`. The `take_snapshot` tool returns the accessibility tree of the page, which represents what assistive technologies "see", making it the most reliable source of truth for semantic structure.
|
||||
|
||||
**Reading web.dev documentation**: If you need to research specific accessibility guidelines (like `https://web.dev/articles/accessible-tap-targets`), you can append `.md.txt` to the URL (e.g., `https://web.dev/articles/accessible-tap-targets.md.txt`) to fetch the clean, raw markdown version. This is much easier to read using the `read_url_content` tool!
|
||||
**Reading web.dev documentation**: If you need to research specific accessibility guidelines (like `https://web.dev/articles/accessible-tap-targets`), you can append `.md.txt` to the URL (e.g., `https://web.dev/articles/accessible-tap-targets.md.txt`) to fetch the clean, raw markdown version. This is much easier to read!
|
||||
|
||||
## Workflow Patterns
|
||||
|
||||
@@ -34,18 +34,14 @@ The accessibility tree exposes the heading hierarchy and semantic landmarks.
|
||||
1. Locate buttons, inputs, and images in the `take_snapshot` output.
|
||||
2. Ensure interactive elements have an accessible name (e.g., a button should not just say `""` if it only contains an icon).
|
||||
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`:
|
||||
```javascript
|
||||
() => {
|
||||
const inputs = Array.from(
|
||||
document.querySelectorAll('input, select, textarea'),
|
||||
);
|
||||
return inputs
|
||||
```js
|
||||
() =>
|
||||
Array.from(document.querySelectorAll('input, select, textarea'))
|
||||
.filter(i => {
|
||||
const hasId = i.id && document.querySelector(`label[for="${i.id}"]`);
|
||||
const hasAria =
|
||||
i.getAttribute('aria-label') || i.getAttribute('aria-labelledby');
|
||||
const hasImplicitLabel = i.closest('label');
|
||||
return !hasId && !hasAria && !hasImplicitLabel;
|
||||
return !hasId && !hasAria && !i.closest('label');
|
||||
})
|
||||
.map(i => ({
|
||||
tag: i.tagName,
|
||||
@@ -53,7 +49,6 @@ The accessibility tree exposes the heading hierarchy and semantic landmarks.
|
||||
name: i.name,
|
||||
placeholder: i.placeholder,
|
||||
}));
|
||||
};
|
||||
```
|
||||
|
||||
````
|
||||
@@ -73,7 +68,7 @@ Testing "keyboard traps" and proper focus management without visual feedback rel
|
||||
|
||||
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`:
|
||||
|
||||
```javascript
|
||||
```js
|
||||
// Usage in console: copy, paste, and call with element: fn(element)
|
||||
el => {
|
||||
const rect = el.getBoundingClientRect();
|
||||
@@ -81,7 +76,7 @@ el => {
|
||||
};
|
||||
````
|
||||
|
||||
_Pass the element's `uid` from the snapshot as an argument to the tool._
|
||||
_Pass the element's `uid` from the snapshot as an argument to `evaluate_script`._
|
||||
|
||||
### 6. Color Contrast
|
||||
|
||||
@@ -94,7 +89,7 @@ If native audits do not report issues (which may happen in some headless environ
|
||||
|
||||
**Note**: This script uses a simplified algorithm and may not account for transparency, gradients, or background images. For production-grade auditing, consider injecting `axe-core`.
|
||||
|
||||
```javascript
|
||||
```js
|
||||
el => {
|
||||
function getRGB(colorStr) {
|
||||
const match = colorStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
||||
@@ -133,28 +128,19 @@ _Pass the element's `uid` to test the contrast against WCAG AA (4.5:1 for normal
|
||||
|
||||
Verify document-level accessibility settings often missed in component testing:
|
||||
|
||||
```javascript
|
||||
(() => {
|
||||
const f = () => {
|
||||
return {
|
||||
lang:
|
||||
document.documentElement.lang ||
|
||||
'MISSING - Screen readers need this for pronunciation',
|
||||
title: document.title || 'MISSING - Required for context',
|
||||
viewport:
|
||||
document.querySelector('meta[name="viewport"]')?.content ||
|
||||
'MISSING - Check for user-scalable=no (bad practice)',
|
||||
reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)')
|
||||
.matches
|
||||
? 'Enabled'
|
||||
: 'Disabled',
|
||||
};
|
||||
};
|
||||
try {
|
||||
console.log(f());
|
||||
} catch (e) {} // Log for manual console usage
|
||||
return f;
|
||||
})();
|
||||
```js
|
||||
() => ({
|
||||
lang:
|
||||
document.documentElement.lang ||
|
||||
'MISSING - Screen readers need this for pronunciation',
|
||||
title: document.title || 'MISSING - Required for context',
|
||||
viewport:
|
||||
document.querySelector('meta[name="viewport"]')?.content ||
|
||||
'MISSING - Check for user-scalable=no (bad practice)',
|
||||
reducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
||||
? 'Enabled'
|
||||
: 'Disabled',
|
||||
});
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Reference in new issue
Block a user