lighthouse-scanner
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLighthouse CI Accessibility Integration
Lighthouse CI 无障碍集成
What Is Lighthouse CI?
什么是Lighthouse CI?
Lighthouse CI is a suite of tools for running Google Lighthouse audits in CI pipelines. The most common GitHub Actions integration uses .
treosh/lighthouse-ci-actionLighthouse provides:
- Performance, accessibility, best practices, and SEO scoring (0-100)
- Individual audit results with pass/fail status and detailed findings
- Score budgets and assertions to fail builds on regressions
- HTML and JSON report artifacts
- Score comparison across runs for trend tracking
Accessibility focus: The Lighthouse accessibility category runs a subset of axe-core rules and reports a weighted score from 0-100 along with individual audit violations.
Lighthouse CI 是一套用于在CI流水线中运行Google Lighthouse审计的工具套件,最常见的GitHub Actions集成方案使用。
treosh/lighthouse-ci-actionLighthouse提供以下能力:
- 性能、无障碍、最佳实践和SEO评分(0-100分)
- 单条审计的通过/失败状态与详细发现结果
- 分数预算与断言规则,出现回归时可终止构建
- HTML和JSON格式的报告产物
- 跨运行的分数对比功能,用于跟踪变化趋势
无障碍专项说明: Lighthouse的无障碍分类会运行axe-core规则的子集,输出0-100的加权评分,同时列出所有单条审计违规项。
Detecting Lighthouse CI Presence
检测Lighthouse CI的配置存在
Workflow File Detection
工作流文件检测
Search for workflow files referencing Lighthouse CI:
bash
undefined搜索引用Lighthouse CI的工作流文件:
bash
undefinedSearch for the treosh Lighthouse CI action
搜索treosh出品的Lighthouse CI action
grep -rl "treosh/lighthouse-ci-action" .github/workflows/
grep -rl "treosh/lighthouse-ci-action" .github/workflows/
Search for official Lighthouse CI CLI usage
搜索官方Lighthouse CI CLI的使用记录
grep -rl "lhci autorun|lighthouse-ci" .github/workflows/
**Patterns to match in YAML:**
```yaml
- uses: treosh/lighthouse-ci-action@v12grep -rl "lhci autorun|lighthouse-ci" .github/workflows/
**YAML中需要匹配的模式:**
```yaml
- uses: treosh/lighthouse-ci-action@v12Configuration File Detection
配置文件检测
Lighthouse CI uses configuration files in the repository root:
bash
undefinedLighthouse CI会使用仓库根目录下的配置文件:
bash
undefinedCheck for Lighthouse CI config files
检查是否存在Lighthouse CI配置文件
ls lighthouserc.js lighthouserc.json .lighthouserc.js .lighthouserc.json .lighthouserc.yml 2>/dev/null
| Config File | Format |
|------------|--------|
| `lighthouserc.js` | JavaScript module |
| `lighthouserc.json` | JSON |
| `.lighthouserc.js` | JavaScript module (dotfile) |
| `.lighthouserc.json` | JSON (dotfile) |
| `.lighthouserc.yml` | YAML (dotfile) |ls lighthouserc.js lighthouserc.json .lighthouserc.js .lighthouserc.json .lighthouserc.yml 2>/dev/null
| 配置文件 | 格式 |
|------------|--------|
| `lighthouserc.js` | JavaScript模块 |
| `lighthouserc.json` | JSON |
| `.lighthouserc.js` | JavaScript模块(点文件) |
| `.lighthouserc.json` | JSON(点文件) |
| `.lighthouserc.yml` | YAML(点文件) |Configuration Structure
配置结构
Key fields in Lighthouse CI config:
json
{
"ci": {
"collect": {
"url": ["https://example.com", "https://example.com/about"],
"numberOfRuns": 3
},
"assert": {
"assertions": {
"categories:accessibility": ["error", {"minScore": 0.9}]
}
},
"upload": {
"target": "temporary-public-storage"
}
}
}| Section | Purpose | Agent Use |
|---|---|---|
| URLs to audit | Scope of CI scanning |
| How many times to run each URL | Reliability indicator |
| Score budgets and thresholds | Regression detection |
| Where to store reports | Report retrieval |
Lighthouse CI配置的核心字段:
json
{
"ci": {
"collect": {
"url": ["https://example.com", "https://example.com/about"],
"numberOfRuns": 3
},
"assert": {
"assertions": {
"categories:accessibility": ["error", {"minScore": 0.9}]
}
},
"upload": {
"target": "temporary-public-storage"
}
}
}| 配置段 | 用途 | Agent用途 |
|---|---|---|
| 待审计的URL列表 | CI扫描的范围 |
| 每个URL的审计运行次数 | 结果可靠性指标 |
| 分数预算与阈值规则 | 回归检测 |
| 报告存储位置 | 报告拉取 |
Parsing Lighthouse Accessibility Results
解析Lighthouse无障碍审计结果
Accessibility Score
无障碍评分
Lighthouse computes a weighted accessibility score from 0-100 based on individual audit results.
| Score Range | Grade | Interpretation |
|---|---|---|
| 90-100 | A | Good accessibility |
| 70-89 | B-C | Some issues to address |
| 50-69 | D | Significant issues |
| 0-49 | F | Critical accessibility failures |
Lighthouse基于单条审计结果计算0-100的加权无障碍评分:
| 分数范围 | 等级 | 含义 |
|---|---|---|
| 90-100 | A | 无障碍表现良好 |
| 70-89 | B-C | 存在部分待修复问题 |
| 50-69 | D | 存在明显问题 |
| 0-49 | F | 存在严重无障碍故障 |
Individual Audit Results
单条审计结果
Each Lighthouse accessibility audit corresponds to an axe-core rule:
| Audit ID | axe-core Rule | WCAG Criterion | Weight |
|---|---|---|---|
| | 1.1.1 | 10 |
| | 1.4.3 | 7 |
| | 1.3.1 | 7 |
| | 4.1.2 | 7 |
| | 2.4.4 | 7 |
| | 3.1.1 | 7 |
| | 2.4.2 | 7 |
| | 1.3.1 | 3 |
| | 1.4.4 | 10 |
| | 2.4.1 | 7 |
| | 2.4.3 | 7 |
| | 4.1.2 | 10 |
| | 4.1.2 | 10 |
| | 4.1.2 | 10 |
| | 4.1.2 | 7 |
| | 4.1.2 | 7 |
| | 4.1.2 | 10 |
每条Lighthouse无障碍审计都对应一条axe-core规则:
| 审计ID | axe-core规则 | WCAG标准项 | 权重 |
|---|---|---|---|
| | 1.1.1 | 10 |
| | 1.4.3 | 7 |
| | 1.3.1 | 7 |
| | 4.1.2 | 7 |
| | 2.4.4 | 7 |
| | 3.1.1 | 7 |
| | 2.4.2 | 7 |
| | 1.3.1 | 3 |
| | 1.4.4 | 10 |
| | 2.4.1 | 7 |
| | 2.4.3 | 7 |
| | 4.1.2 | 10 |
| | 4.1.2 | 10 |
| | 4.1.2 | 10 |
| | 4.1.2 | 7 |
| | 4.1.2 | 7 |
| | 4.1.2 | 10 |
Severity Mapping
严重性映射
Lighthouse uses weights rather than impact levels. Map to the agent severity model based on weight and audit pass/fail:
| Lighthouse Weight | Audit Status | Agent Severity |
|---|---|---|
| 10 | Fail | Critical |
| 7 | Fail | Serious |
| 3 | Fail | Moderate |
| 1 | Fail | Minor |
| Any | Pass | N/A (not reported) |
Lighthouse使用权重而非影响等级,可根据权重和审计通过/失败状态映射到Agent严重性模型:
| Lighthouse权重 | 审计状态 | Agent严重性 |
|---|---|---|
| 10 | 未通过 | 严重 |
| 7 | 未通过 | 较高 |
| 3 | 未通过 | 中等 |
| 1 | 未通过 | 轻微 |
| 任意 | 通过 | 无需上报 |
Correlation with Local Scans
与本地扫描结果关联
Lighthouse-to-axe-core Mapping
Lighthouse与axe-core的映射关系
Since Lighthouse uses axe-core under the hood, correlation is straightforward:
- Match by audit/rule ID: Lighthouse audit IDs correspond directly to axe-core rule IDs
- Match by URL: Compare scanned URLs from Lighthouse config with local scan targets
- Boost confidence: Findings confirmed by both Lighthouse CI and local axe-core scan receive confidence
high
由于Lighthouse底层基于axe-core实现,二者的结果关联非常简单:
- 按审计/规则ID匹配: Lighthouse审计ID与axe-core规则ID直接对应
- 按URL匹配: 将Lighthouse配置中的扫描URL与本地扫描目标做对比
- 提升置信度: 同时被Lighthouse CI和本地axe-core扫描确认的问题可标记为置信度
高
Source Comparison
来源对比规则
| Scenario | Interpretation | Action |
|---|---|---|
| Found by Lighthouse AND local scan | High confidence | Report as high confidence, full severity weight |
| Found by Lighthouse only | Environment-specific | Report as medium confidence, note "CI-only finding" |
| Found by local scan only | Not covered by Lighthouse subset | Report as medium confidence, note "local-only finding" |
| Lighthouse score regressed | New accessibility issues introduced | Flag as regression, prioritize in report |
| 场景 | 含义 | 处理方式 |
|---|---|---|
| 同时被Lighthouse和本地扫描发现 | 高置信度问题 | 按高置信度上报,使用完整严重性权重 |
| 仅被Lighthouse发现 | 环境专属问题 | 按中置信度上报,标记为「仅CI环境发现」 |
| 仅被本地扫描发现 | 不在Lighthouse规则子集覆盖范围 | 按中置信度上报,标记为「仅本地扫描发现」 |
| Lighthouse分数出现回归 | 新引入无障碍问题 | 标记为回归问题,在报告中优先展示 |
Score Regression Detection
分数回归检测
Track Lighthouse accessibility scores across runs to detect regressions:
跟踪多轮运行的Lighthouse无障碍分数以检测回归:
Comparing Scores
分数对比结构
json
{
"url": "https://example.com",
"previousScore": 95,
"currentScore": 87,
"delta": -8,
"status": "regressed",
"newFailures": ["color-contrast", "image-alt"],
"newPasses": []
}json
{
"url": "https://example.com",
"previousScore": 95,
"currentScore": 87,
"delta": -8,
"status": "regressed",
"newFailures": ["color-contrast", "image-alt"],
"newPasses": []
}Regression Thresholds
回归阈值
| Delta | Severity | Action |
|---|---|---|
| Score drops 10+ points | Critical | Immediate attention, likely multiple new violations |
| Score drops 5-9 points | Serious | New violations introduced, review before merge |
| Score drops 1-4 points | Moderate | Minor regression, track for follow-up |
| Score unchanged or improved | N/A | No regression detected |
| 分数变化 | 严重性 | 处理方式 |
|---|---|---|
| 分数下降10分及以上 | 严重 | 需要立即处理,大概率存在多个新增违规 |
| 分数下降5-9分 | 较高 | 存在新增违规,合并前需要评审 |
| 分数下降1-4分 | 中等 | 轻微回归,后续跟进修复 |
| 分数无变化或提升 | 无 | 未检测到回归 |
Structured Output Format
结构化输出格式
When normalizes Lighthouse data, it produces findings in this format:
lighthouse-bridgejson
{
"source": "lighthouse-ci",
"ruleId": "color-contrast",
"wcagCriterion": "1.4.3",
"wcagLevel": "AA",
"severity": "serious",
"confidence": "high",
"url": "https://example.com/login",
"element": "button.submit-btn",
"description": "Element has insufficient color contrast ratio",
"lighthouseWeight": 7,
"lighthouseScore": {
"overall": 87,
"previousOverall": 95,
"delta": -8,
"status": "regressed"
}
}当标准化Lighthouse数据时,会输出如下格式的结果:
lighthouse-bridgejson
{
"source": "lighthouse-ci",
"ruleId": "color-contrast",
"wcagCriterion": "1.4.3",
"wcagLevel": "AA",
"severity": "serious",
"confidence": "high",
"url": "https://example.com/login",
"element": "button.submit-btn",
"description": "Element has insufficient color contrast ratio",
"lighthouseWeight": 7,
"lighthouseScore": {
"overall": 87,
"previousOverall": 95,
"delta": -8,
"status": "regressed"
}
}GitHub Actions Integration
GitHub Actions集成
treosh/lighthouse-ci-action
treosh/lighthouse-ci-action
The most common Lighthouse CI GitHub Action:
yaml
- name: Run Lighthouse CI
uses: treosh/lighthouse-ci-action@v12
with:
urls: |
https://example.com
https://example.com/about
uploadArtifacts: true
configPath: ./lighthouserc.json最常用的Lighthouse CI GitHub Action:
yaml
- name: Run Lighthouse CI
uses: treosh/lighthouse-ci-action@v12
with:
urls: |
https://example.com
https://example.com/about
uploadArtifacts: true
configPath: ./lighthouserc.jsonAction Inputs
Action入参
| Input | Required | Description |
|---|---|---|
| Yes (or in config) | Newline-separated URLs to audit |
| No | Path to Lighthouse CI config file |
| No | Upload HTML reports as workflow artifacts |
| No | Upload to temporary public storage for sharing |
| No | Number of runs per URL (default: 1) |
| No | Path to a Lighthouse budget JSON file |
| 入参 | 是否必填 | 说明 |
|---|---|---|
| 是(或在配置文件中定义) | 换行分隔的待审计URL列表 |
| 否 | Lighthouse CI配置文件路径 |
| 否 | 将HTML报告作为工作流产物上传 |
| 否 | 上传到临时公共存储用于分享 |
| 否 | 每个URL的运行次数(默认:1) |
| 否 | Lighthouse预算JSON文件路径 |
Extracting Results from Artifacts
从产物中提取结果
Lighthouse CI uploads results as workflow artifacts. To retrieve scores:
- Download the artifact from the workflow run
- Parse the JSON report files
- Extract for the overall score
categories.accessibility.score - Extract individual results for violations
audits.{audit-id}
Lighthouse CI会将结果作为工作流产物上传,提取分数的步骤如下:
- 从工作流运行记录中下载产物
- 解析JSON报告文件
- 提取作为整体评分
categories.accessibility.score - 提取下的单条违规结果
audits.{audit-id}