@code-pushup/axe-plugin

中文文档
0.126.4发布于 2026/09/11MITTypeScriptES Module构建来源已验证近 30 天下载 2844

Code PushUp plugin for detecting accessibility issues using Axe 🌐

原始使用文档
文档目录15 节
  1. Getting started
  2. Configuration
  3. Multiple URLs
  4. Authentication
  5. Presets
  6. Preset details
  7. Groups
  8. Category integration
  9. Building categories with ref helpers
  10. Custom categories with specific groups
  11. Combining with Lighthouse
  12. Helper functions
  13. Type safety
  14. Deprecated helpers
  15. Resources

@code-pushup/axe-plugin

npm downloads dependencies

🕵️ Code PushUp plugin for automated accessibility testing with Axe. 🌐


The plugin runs accessibility audits on web pages using axe-core via Playwright. It identifies WCAG violations and best practice recommendations, providing 100+ accessibility metrics with detailed guidance for fixing problems.

Why accessibility testing matters: The European Accessibility Act (EAA) requires digital products and services in the EU to meet accessibility standards closely aligned with the Web Content Accessibility Guidelines (WCAG). This plugin provides comprehensive automated testing to help meet compliance requirements and build inclusive experiences.

Getting started

  1. If you haven't already, install @code-pushup/cli and create a configuration file.

  2. Install as a dev dependency with your package manager:

    npm install --save-dev @code-pushup/axe-plugin
    
    yarn add --dev @code-pushup/axe-plugin
    
    pnpm add --save-dev @code-pushup/axe-plugin
    
  3. Add this plugin to the plugins array in your Code PushUp CLI config file (e.g. code-pushup.config.ts).

    Pass in the URL you want to test:

    import axePlugin from '@code-pushup/axe-plugin';
    
    export default {
      // ...
      plugins: [
        // ...
        axePlugin('https://example.com'),
      ],
    };
    

    By default, the plugin runs WCAG 2.1 Level AA audits. You can customize this using presets.

  4. Run the CLI with npx code-pushup collect and view or upload the report (refer to CLI docs).

    Note: The plugin uses Playwright to run tests in Chromium. The browser will be installed automatically if not already present.

Configuration

axePlugin(urls: PluginUrls, options?: AxePluginOptions)

Parameters:

  • urls - URL(s) to test. See Multiple URLs section below, or PluginUrls reference
  • options - Optional configuration object

Options:

PropertyTypeDefaultDescription
presetAxePreset'wcag21aa'Accessibility ruleset preset
setupScriptstringundefinedPath to authentication setup script
scoreTargetsobjectundefinedPass/fail thresholds for audits or groups

See Presets and Authentication sections below.

Multiple URLs

The plugin supports testing single or multiple URLs:

// Single URL (string)
axePlugin('https://example.com');

// Multiple URLs (array)
axePlugin(['https://example.com', 'https://example.com/about']);

// Weighted URLs (record)
axePlugin({
  'https://example.com': 3, // homepage has 3x weight
  'https://example.com/about': 1, // about page has 1x weight
});

URLs with higher weights contribute more to overall scores. For example, a URL with weight 3 has three times the influence of a URL with weight 1.

Authentication

To test login-protected pages, provide a setupScript that authenticates before analysis:

axePlugin('https://example.com/dashboard', {
  setupScript: './axe-setup.ts',
});

The setup script must export a default async function that receives a Playwright Page instance:

// axe-setup.ts
import type { Page } from 'playwright-core';

export default async function (page: Page): Promise<void> {
  await page.goto('https://example.com/login');
  await page.fill('#username', process.env.USERNAME);
  await page.fill('#password', process.env.PASSWORD);
  await page.click('button[type="submit"]');
  await page.waitForURL('**/dashboard');
}

The script runs once before analyzing URLs. Authentication state (cookies, localStorage) is automatically shared across all URL analyses.

Alternative: Cookie-based authentication

If you have a session token, you can inject it directly via cookies:

// axe-setup.ts
import type { Page } from 'playwright-core';

export default async function (page: Page): Promise<void> {
  await page.context().addCookies([
    {
      name: 'session_token',
      value: process.env.SESSION_TOKEN,
      domain: 'example.com',
      path: '/',
    },
  ]);
}

Presets

Choose which accessibility ruleset to test against using the preset option:

axePlugin('https://example.com', {
  preset: 'wcag22aa',
});

Available presets:

PresetDescriptionUse case
wcag21aaWCAG 2.1 Level A and AA (default)Standard web accessibility compliance
wcag22aaWCAG 2.2 Level A and AALatest WCAG standard
best-practiceBest practices (non-WCAG recommendations)Deque's additional recommendations
allAll available rulesComprehensive testing

Preset details

wcag21aa (default)

wcag22aa

  • Tests compliance with WCAG 2.2 Level A and Level AA
  • Includes all WCAG 2.1 rules plus new success criteria
  • Future-proof for upcoming regulations

best-practice

  • Non-WCAG recommendations from Deque Systems
  • Goes beyond legal requirements
  • Helps create more inclusive experiences

all

  • Runs every rule available in axe-core
  • Includes WCAG 2.0, 2.1, 2.2, experimental rules, and best practices
  • Most comprehensive testing

Note: Different pages may trigger different sets of rules depending on their content. For example, a page without video won't run video-related audits.

Groups

The plugin organizes audits into category groups based on axe-core's accessibility categories:

  • aria - ARIA
  • color - Color & Contrast
  • forms - Forms
  • keyboard - Keyboard
  • language - Language
  • name-role-value - Names & Labels
  • parsing - Parsing
  • semantics - Semantics
  • sensory-and-visual-cues - Visual Cues
  • structure - Structure
  • tables - Tables
  • text-alternatives - Text Alternatives
  • time-and-media - Media

Use npx code-pushup print-config --onlyPlugins=axe to list all audits and groups for your configuration.

Category integration

The plugin provides helpers to integrate Axe results into your categories.

Building categories with ref helpers

Use axeGroupRefs and axeAuditRefs to build categories. These helpers automatically handle multi-URL expansion:

import axePlugin, { axeGroupRefs } from '@code-pushup/axe-plugin';

const axe = axePlugin('https://example.com');

export default {
  plugins: [axe],
  categories: [
    {
      slug: 'a11y',
      title: 'Accessibility',
      refs: axeGroupRefs(axe),
    },
  ],
};

For multi-URL setups, refs are automatically expanded for each URL with appropriate weights:

import axePlugin, { axeGroupRefs } from '@code-pushup/axe-plugin';

const axe = axePlugin({
  'https://example.com': 2,
  'https://example.com/about': 1,
});

export default {
  plugins: [axe],
  categories: [
    {
      slug: 'a11y',
      title: 'Accessibility',
      refs: axeGroupRefs(axe),
    },
  ],
};

Custom categories with specific groups

For fine-grained control, specify which groups to include:

import axePlugin, { axeGroupRefs } from '@code-pushup/axe-plugin';

const axe = axePlugin('https://example.com');

export default {
  plugins: [axe],
  categories: [
    {
      slug: 'a11y',
      title: 'Accessibility',
      refs: [...axeGroupRefs(axe, 'aria', 2), ...axeGroupRefs(axe, 'color'), ...axeGroupRefs(axe, 'keyboard')],
    },
  ],
};

Combining with Lighthouse

For comprehensive accessibility testing, combine Axe with Lighthouse's accessibility group in a single category:

import axePlugin, { axeGroupRefs } from '@code-pushup/axe-plugin';
import lighthousePlugin, { lighthouseGroupRefs } from '@code-pushup/lighthouse-plugin';

const urls = ['https://example.com', 'https://example.com/about'];
const axe = axePlugin(urls);
const lighthouse = await lighthousePlugin(urls);

export default {
  plugins: [axe, lighthouse],
  categories: [
    {
      slug: 'a11y',
      title: 'Accessibility',
      refs: [...lighthouseGroupRefs(lighthouse, 'accessibility'), ...axeGroupRefs(axe)],
    },
  ],
};

This gives you both Lighthouse's performance-focused accessibility audits and Axe's comprehensive WCAG coverage in one category score.

Helper functions

FunctionDescription
axeGroupRefsCreates category refs to Axe group(s), handles multi-URL
axeAuditRefsCreates category refs to Axe audit(s), handles multi-URL

[!TIP] Weights determine each ref's influence on the category score. Use weight 0 to include a ref as info only, without affecting the score.

Type safety

The AxeGroupSlug type is exported for discovering valid group slugs:

import type { AxeGroupSlug } from '@code-pushup/axe-plugin';

const group: AxeGroupSlug = 'aria';

Deprecated helpers

The following helpers are deprecated and will be removed in a future version:

FunctionReplacement
axeCategoriesBuild categories manually with axeGroupRefs
axeGroupRefUse axeGroupRefs (plural) for multi-URL support
axeAuditRefUse axeAuditRefs (plural) for multi-URL support

Resources

版本与发布记录

@code-pushup/axe-plugin 共发布 62 个版本,首次发布于 2025/11/12;过去 12 个月发布了 62 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.126.4latest2026/09/111 个月前
0.126.32026/05/195 个月前
0.126.22026/03/317 个月前
0.126.12026/03/317 个月前
0.126.02026/03/307 个月前
0.125.02026/03/277 个月前

关于 @code-pushup/axe-plugin 的常见问题

@code-pushup/axe-plugin 是什么?

Code PushUp plugin for detecting accessibility issues using Axe 🌐

如何安装 @code-pushup/axe-plugin?

在项目目录运行 npm install @code-pushup/axe-plugin,或使用 pnpm add / yarn add / bun add。

@code-pushup/axe-plugin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@code-pushup/axe-plugin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@code-pushup/axe-plugin 可以商用吗?

@code-pushup/axe-plugin 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@code-pushup/axe-plugin 的下载量有多少?

根据 npm 官方下载统计,@code-pushup/axe-plugin 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,844 次,日均约 95 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@code-pushup/axe-plugin 还在维护吗?

最新版本 0.126.4 发布于 2026/09/11(1 个月前);至今共发布 62 个版本,其中过去 12 个月发布了 62 个;首次发布于 2025/11/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。