Agent Wranglers

WEB-24Recommended

Audit every page in a browser before release

Run an accessibility checker and a lab tool such as Lighthouse in a browser. Test light and dark mode, at phone and desktop width, and watch the console for policy errors.

How to do it

Script a browser driver, such as Playwright, to open every page type. Run axe-core, an accessibility checker, with the WCAG 2.0, 2.1 and 2.2 AA rules and best practices. Run Lighthouse, and collect console errors. Run the accessibility part in CI on every build, as in accessibility in CI.

Examples

JavaScript example

import { chromium } from 'playwright';
import { readFileSync } from 'node:fs';
const axe = readFileSync('node_modules/axe-core/axe.min.js', 'utf8');
const browser = await chromium.launch();
for (const colorScheme of ['light', 'dark']) {
  const page = await browser.newPage({ colorScheme, viewport: { width: 360, height: 800 } });
  page.on('console', m => m.type() === 'error' && console.log('console:', m.text()));
  await page.goto('https://example.com/');
  // evaluate, not addScriptTag: a strict CSP blocks an injected <script>
  const { violations } = await page.evaluate(`(() => { ${axe}; return axe.run({
    runOnly: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa', 'best-practice'] }); })()`);
  console.log(colorScheme, violations.map(v => v.id));
}
await browser.close();

Python example

from pathlib import Path
from playwright.sync_api import sync_playwright
axe = Path("node_modules/axe-core/axe.min.js").read_text()
run_axe = f"(() => {{ {axe}; return axe.run({{ runOnly: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa', 'best-practice'] }}); }})()"
with sync_playwright() as p:
    browser = p.chromium.launch()
    for scheme in ("light", "dark"):
        page = browser.new_page(color_scheme=scheme, viewport={"width": 360, "height": 800})
        page.on("console", lambda m: m.type == "error" and print("console:", m.text))
        page.goto("https://example.com/")
        print(scheme, [v["id"] for v in page.evaluate(run_axe)["violations"]])
    browser.close()

How to check

No axe violations and no console errors, such as CSP or Trusted Types errors, on any page. Run Lighthouse on the home page and one page of each type, and keep its scores as a record.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/site-architecture/browser-audits-before-release">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.