Accessibility Developer Tools (ADT)

2.12.0 · active · verified Sun Apr 19

The Accessibility Developer Tools (ADT) library provides a suite of accessibility-related testing and utility code primarily for web browsers. Its core functionality includes an accessibility audit API, offering a collection of rules to check for common accessibility problems within an HTML page. Beyond auditing, it offers utilities such as contrast ratio calculation, ARIA attribute validation, and accessible name computation following WAI-ARIA specifications. The current stable version is 2.12.0, with a release cadence that appears somewhat irregular, often driven by bug fixes, performance enhancements, and new audit rules. Key differentiators include its focus on practical, rule-based audits for web content and its integration capabilities with testing frameworks like Selenium and headless browsers like PhantomJS. It's often used in CI/CD pipelines to automate accessibility checks.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `accessibility-developer-tools` within a Node.js environment using Puppeteer to audit a web page. It injects the library into a headless browser, runs a full accessibility audit, and logs the results including failing elements.

import puppeteer from 'puppeteer';

async function runAccessibilityAudit(url) {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.goto(url, { waitUntil: 'networkidle0' });

  // Inject accessibility-developer-tools library
  // This assumes the library is installed and available in node_modules
  // or fetched from a CDN directly.
  // For simplicity, we'll use a direct CDN path here for the browser-global version.
  await page.addScriptTag({
    url: 'https://raw.githubusercontent.com/GoogleChrome/accessibility-developer-tools/stable/dist/js/axs_testing.js'
  });

  // Run the audit and get results
  const results = await page.evaluate(() => {
    if (typeof axs === 'undefined' || !axs.Audit || !axs.Audit.run) {
      return { error: 'accessibility-developer-tools not loaded or initialized.' };
    }
    const auditResults = axs.Audit.run();
    return auditResults.map(result => ({
      ruleName: result.rule.name,
      result: result.result,
      elements: result.elements ? result.elements.map(el => el.outerHTML) : []
    }));
  });

  console.log(`Accessibility audit for ${url}:`);
  results.forEach(item => {
    console.log(`  Rule: ${item.ruleName} - Result: ${item.result}`);
    if (item.elements && item.elements.length > 0) {
      console.log('    Failing elements:', item.elements.slice(0, 3).join(' ')); // Log first 3 elements
    }
  });

  await browser.close();
}

// Example usage: You'd typically run this against a local or staging URL
runAccessibilityAudit('https://www.google.com');

view raw JSON →