Raised: $0
0% of monthly goal Help us cross the finish line!
Goal: $12,000
Raised: $0 Goal: $12,000
0% of monthly goal Help us cross the finish line!
Sponsor DDEV

If you find this add-on useful, please star it on GitHub — stars show appreciation and help maintainers know their work matters.

add-on registry tests last commit release

DDEV axe

Overview

This add-on adds a ddev axe command that checks your DDEV project’s pages for accessibility problems with axe (@axe-core/cli). It runs in the web container with headless Chromium from Debian, so you don’t need Node.js, Chrome or chromedriver on your computer. It works on Apple Silicon (arm64) and amd64.

Installation

ddev add-on get davereid/ddev-axe
ddev restart

The restart adds Chromium to the web image, which takes a minute or two the first time. After installation, commit the .ddev directory to version control.

Usage

Command Description
ddev axe Check the project’s primary URL
ddev axe https://example.ddev.site/contact https://example.ddev.site/about Check the given URLs
ddev axe --sitemap Check every URL in the project’s /sitemap.xml
ddev axe --sitemap=https://example.ddev.site/sitemap-pages.xml Check every URL in another sitemap
ddev axe --sitemap --min-priority=0.8 Check the sitemap’s URLs with a priority of 0.8 or more
ddev axe --help List the options, including axe’s own

The command exits with status 1 when axe finds a problem, so you can use it in CI.

The first run downloads @axe-core/cli with npx, so it needs network access. DDEV keeps npm’s cache in the project’s cache volume, so later runs start quickly.

Options

Option Description
URL... The pages to check. Each needs its http:// or https:// scheme. Without URLs or --sitemap, the project’s primary URL is checked.
--sitemap[=URL] Check every <loc> in a sitemap. Sitemap indexes are followed. Defaults to <primary URL>/sitemap.xml.
--min-priority=N With --sitemap, check only the entries whose <priority> is N or more, where N is from 0.0 to 1.0. An entry without a <priority> counts as 0.5, the sitemap protocol’s default, and the command says how many there were.

Any other option goes to axe. These defaults come first, so passing the same option replaces them:

Chromium needs no-sandbox to run in the container, and ignore-certificate-errors because it doesn’t trust DDEV’s local HTTPS certificate. If you pass your own --chrome-options, include those too.

For example, to also check axe’s best-practice rules, or to skip a rule:

ddev axe --tags wcag2a,wcag2aa,wcag21a,wcag21aa,best-practice
ddev axe --disable color-contrast --sitemap

Matching CI results

The defaults and the sitemap filtering match davereid/axe-sitemap-action and the axe options it’s used with in CI, so a page that passes locally should pass there too. Two things can still differ:

Sharing Chromium with other add-ons

Several add-ons need a browser, and when each installs its own copy, the web image gets bigger and slower to build. This add-on installs Debian’s packages through DDEV’s webimage_extra_packages setting, in .ddev/config.axe.yaml:

webimage_extra_packages:
  - chromium
  - chromium-driver

DDEV merges lists like this one from every .ddev/config.*.yaml and removes duplicates. When several add-ons list these packages, Chromium is installed once, in a single apt-get install. No add-on needs a custom Dockerfile for it, and removing one add-on leaves the browser in place for the others.

If you maintain an add-on that needs Chromium in the web container, you can follow the same convention:

  1. List chromium and chromium-driver in webimage_extra_packages in your add-on’s own config.<add-on>.yaml.
  2. Find the binaries on the PATH (command -v chromium, command -v chromedriver) instead of hard-coding a location.
  3. Run Chromium headless with --no-sandbox, and with --ignore-certificate-errors (or another way to trust DDEV’s certificate) for HTTPS URLs.

Debian builds chromium and chromium-driver from the same source, so their versions always match, and both are available for amd64 and arm64. Google Chrome has no Linux arm64 build, so it doesn’t work on Apple Silicon.

An add-on that installs a different Chromium version in its own Dockerfile can conflict with these packages. ddev axe uses whichever chromedriver comes first on the PATH, so that add-on also needs to install the matching driver.

This convention is proposed for DDEV’s add-on docs in ddev/ddev#9234: add your thoughts there.

Alternatives

Mschuddings/ddev-axe_a11y also runs axe from DDEV, with a different approach: it runs the checker in its own container, writes HTML reports and can compare results with a baseline, but doesn’t read sitemaps (it takes a CSV list of URLs). This add-on runs in the web container and prints axe’s console output, so a check passes or fails the same way as in CI.

Removal

ddev add-on remove axe
ddev restart

Credits

Contributed and maintained by @davereid

If you find this add-on useful, please star it on GitHub — stars show appreciation and help maintainers know their work matters.