a11y-debugging by chromedevtools/chrome-devtools-mcp
npx skills add https://github.com/chromedevtools/chrome-devtools-mcp --skill a11y-debugging无障碍树 vs DOM : 视觉上隐藏元素(例如,CSS opacity: 0)对于屏幕阅读器的行为与 display: none 或 aria-hidden="true" 不同。take_snapshot 工具返回页面的无障碍树,它代表了辅助技术所“看到”的内容,使其成为语义结构最可靠的真实来源。
阅读 web.dev 文档 : 如果你需要研究特定的无障碍指南(如 https://web.dev/articles/accessible-tap-targets),可以在 URL 后追加 .md.txt(例如,https://web.dev/articles/accessible-tap-targets.md.txt)来获取干净、原始的 Markdown 版本。这样阅读起来要容易得多!
首先运行 Lighthouse 无障碍审计,以获得全面的基线。该工具提供高级别分数,并列出具体的失败元素及修复建议。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
mode 设置为 "navigation" 以刷新页面并捕获加载问题。outputDirPath(例如,/tmp/lh-report)以保存完整的 JSON 报告。scores(0-1 范围)。分数 < 1 表示存在违规。audits.failed 计数。解析:不要逐行读取整个文件。使用像 jq 这样的 CLI 工具或 Node.js 单行命令来筛选失败项:
# 提取失败的审计及其详细信息
node -e "const r=require('./report.json'); Object.values(r.audits).filter(a=>a.score!==null && a.score<1).forEach(a=>console.log(JSON.stringify({id:a.id, title:a.title, items:a.details?.items})))"
这样可以高效地提取失败元素的 selector 和 snippet,而无需将完整报告加载到上下文中。
Chrome 会自动检查常见的无障碍问题。使用 list_console_messages 来检查这些原生审计:
types: ["issue"]includePreservedMessages: true(以捕获页面加载期间发生的问题)这通常无需手动调查就能揭示缺失的标签、无效的 ARIA 属性和其他关键错误。
无障碍树暴露了标题层级和语义地标。
take_snapshot 捕获无障碍树。h1、h2、h3 等)逻辑合理且不跳级。快照将包含标题角色。take_screenshot 检查视觉布局,并与快照结构进行比较,以发现可能打乱逻辑流程的 CSS 浮动或绝对定位。take_snapshot 输出中定位按钮、输入框和图像。"")。evaluate_script 并配合在 references/a11y-snippets.md 中找到的 “查找孤立表单输入框”代码片段。alt 文本。在没有视觉反馈的情况下测试“键盘陷阱”和正确的焦点管理,依赖于跟踪焦点元素。
press_key 工具配合 "Tab" 或 "Shift+Tab" 来移动焦点。take_snapshot 捕获更新后的无障碍树。根据 web.dev,点击目标应至少为 48x48 像素,并具有足够的间距。由于无障碍树不显示尺寸,请使用 evaluate_script 并配合在 references/a11y-snippets.md 中找到的 “测量点击目标尺寸”代码片段。
将快照中元素的 uid 作为参数传递给 evaluate_script。
要验证颜色对比度比率,首先检查原生无障碍问题:
list_console_messages 并设置 types: ["issue"]。如果原生审计未报告问题(在某些无头环境中可能发生),或者需要手动检查特定元素,请使用 evaluate_script 并配合在 references/a11y-snippets.md 中找到的 “检查颜色对比度”代码片段。
使用在 references/a11y-snippets.md 中找到的 “全局页面检查”代码片段,验证在组件测试中经常被忽略的文档级无障碍设置。
如果标准的无障碍查询失败或 evaluate_script 代码片段返回意外结果:
take_screenshot 捕获该元素。虽然模型无法从图像中测量确切的对比度比率,但它们可以视觉评估可读性并识别明显的问题。每周安装量
79
代码仓库
GitHub 星标数
28.2K
首次出现
2026年2月22日
安全审计
安装于
codex76
gemini-cli74
opencode74
kimi-cli73
amp73
github-copilot73
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!
Start by running a Lighthouse accessibility audit to get a comprehensive baseline. This tool provides a high-level score and lists specific failing elements with remediation advice.
mode to "navigation" to refresh the page and capture load issues.outputDirPath (e.g., /tmp/lh-report) to save the full JSON report.scores (0-1 scale). A score < 1 indicates violations.audits.failed count.Parsing : Do not read the entire file line-by-line. Use a CLI tool like jq or a Node.js one-liner to filter for failures:
# Extract failing audits with their details
node -e "const r=require('./report.json'); Object.values(r.audits).filter(a=>a.score!==null && a.score<1).forEach(a=>console.log(JSON.stringify({id:a.id, title:a.title, items:a.details?.items})))"
Chrome automatically checks for common accessibility problems. Use list_console_messages to check for these native audits:
types: ["issue"]includePreservedMessages: true (to catch issues that occurred during page load)This often reveals missing labels, invalid ARIA attributes, and other critical errors without manual investigation.
The accessibility tree exposes the heading hierarchy and semantic landmarks.
take_snapshot to capture the accessibility tree.h1, h2, h3, etc.) are logical and do not skip levels. The snapshot will include heading roles.take_screenshot to inspect the visual layout and compare it against the snapshot structure to catch CSS floats or absolute positioning that jumbles the logical flow.take_snapshot output."" if it only contains an icon).evaluate_script with the "Find Orphaned Form Inputs" snippet found in references/a11y-snippets.md.alt text.Testing "keyboard traps" and proper focus management without visual feedback relies on tracking the focused element.
press_key tool with "Tab" or "Shift+Tab" to move focus.take_snapshot to capture the updated accessibility tree.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 with the "Measure Tap Target Size" snippet found in references/a11y-snippets.md.
Pass the element'suid from the snapshot as an argument to evaluate_script.
To verify color contrast ratios, start by checking for native accessibility issues:
list_console_messages with types: ["issue"].If native audits do not report issues (which may happen in some headless environments) or if you need to check a specific element manually, use evaluate_script with the "Check Color Contrast" snippet found in references/a11y-snippets.md.
Verify document-level accessibility settings often missed in component testing using the "Global Page Checks" snippet found in references/a11y-snippets.md.
If standard a11y queries fail or the evaluate_script snippets return unexpected results:
take_screenshot to capture the element. While models cannot measure exact contrast ratios from images, they can visually assess legibility and identify obvious issues.Weekly Installs
79
Repository
GitHub Stars
28.2K
First Seen
Feb 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex76
gemini-cli74
opencode74
kimi-cli73
amp73
github-copilot73
React视图过渡API使用指南:实现原生浏览器动画与状态管理
5,700 周安装
This efficiently extracts the selector and snippet of failing elements without loading the full report into context.