Skip to content

API Reference

The package has two entry points: Pa11y for one page and Pa11yCi for many pages. Both return result objects that wrap the JSON from the CLI. Source links point to the main branch.

Pa11y

Source: src/Pa11y.php

namespace JkOster\Pa11y;

public function __construct(protected string $url)
public static function fromUrl(string $url): Pa11y
public function processTimeout(int $sec): self
public function setOption(string $option, $value = null): self
public function standard(string $name): self
public function runner(string $runner): self
public function ignore(string $ignore): self
public function includeNotices(): self
public function includeWarnings(): self
public function rootElement(string $selector): self
public function hideElements(string $selectors): self
public function config(string $path): self
public function timeout(int $ms): self
public function wait(int $ms): self
public function debug(): self
public function screenCapture(string $path): self
public function addRule(string $rule): self
public function commandArgs(): array
public function run(): Pa11yResult

commandArgs() returns {url, '--option', value, ...}. Required options are merged last: reporter=json, config=./pa11y.config.json, level=none. run() resolves the pa11y binary, runs it with a Symfony Process, and throws on a non-zero exit or unreadable JSON.

processTimeout() defaults to 300 seconds. timeout() is the pa11y navigation timeout in milliseconds.

Pa11yCi

Source: src/Pa11yCi.php

namespace JkOster\Pa11y;

public function __construct(protected array $urls)
public static function fromUrls(array $urls): Pa11yCi
public static function fromSitemap(string $url): Pa11yCi
public function setOption(string $optionPath, $value = null): self
public function urls(array $urls): self
public function sitemap(string $sitemapUrl): self
public function sitemapReplace(string $string): self
public function sitemapFind(string $pattern): self
public function sitemapExclude(string $pattern): self
public function includeNotices(bool $include = true): self
public function includeWarnings(bool $include = true): self
public function timeout(int $ms): self
public function wait(int $ms): self
public function standard(string $standard): self
public function runners(array $runners = ['htmlcs']): self
public function actions(array $actions): self
public function headers(array $headers): self
public function screenCapture(string $path): self
public function rules(array $rules): self
public function ignore(array $ignore): self
public function viewport(int $width, int $height, int $deviceScaleFactor = 1, bool $isMobile = false): self
public function hideElements(array $elements): self
public function userAgent(string $userAgent): self
public function method(string $method): self
public function postData(array $postData): self
public function rootElement(string $rootElement): self
public function saveToFile(?string $path = null): self
public function concurrency(int $concurrency): self
public function deleteTempFiles(bool $delete = true): self
public function processTimeout(int $sec): self
public function config(array $config): self
public function debug(bool $debug = true): self
public function run(): Pa11yCiResult

setOption() uses Illuminate\Support\Arr::set, so 'defaults.timeout' writes a nested key. config() deep merges its array over the current options. run() merges DEFAULT_CONFIG with the options, encodes the result as JSON, and calls:

pa11y-ci --config '<inline JSON>' --json

processTimeout() defaults to 600 seconds. saveToFile(null) creates a tempnam() file and marks it for deletion. An explicit path is never deleted by the package.

DEFAULT_CONFIG

[
    'defaults' => [
        'timeout' => 10000,
        'chromeLaunchConfig' => [
            'args' => ['--no-sandbox'],
            'headless' => true,
            'ignoreHTTPSErrors' => true,
        ],
        'viewport' => [
            'width' => 1280,
            'height' => 1024,
            'deviceScaleFactor' => 1,
            'isMobile' => false,
        ],
        'level' => 'none',
        'includeWarnings' => true,
        'includeNotices' => true,
        'reporters' => ['json'],
    ],
    'threshold' => 99999999,
    'concurrency' => 1,
    'urls' => [],
]

Pa11yResult

Source: src/Pa11yResult.php

public function __construct(array $rawResults = [])
public function setRawResults(array $rawResults): self
public function getRawResults(): array
public function getErrorMessage(): ?string
public function json(): string
public function jsonSerialize(): mixed
public function saveJson(string $path): self
public function getRunner(): string
public function getTotalIssueCount(): int
public function getErrors(): array        // Pa11yIssue[]
public function getWarnings(): array      // Pa11yIssue[]
public function getNotices(): array       // Pa11yIssue[]
public function getErrorsCount(): int
public function getWarningsCount(): int
public function getNoticesCount(): int
public function getIssues(?string $code = null): ?array
public function getIssueCount(?string $code): int
public function getGroupedIssues(): array // array<string, Pa11yIssue[]>

Pa11yResult implements ArrayAccess and JsonSerializable. When pa11y returns a single message entry without a code, the constructor stores it as getErrorMessage() and clears the issue list.

Pa11yCiResult

Source: src/Pa11yCiResult.php

public function __construct(array $rawResults, array $config = [], ?string $outputFilePath = null)
public function setRawResults(array $rawResults): self
public function getRawResults(): array
public function json(): string
public function jsonSerialize(): mixed
public function saveJson(string $path): self
public function getConfig(): array
public function getOutputFilePath(): ?string
public function getUrlsCount(): int
public function getPassesCount(): int
public function getFailuresCount(): int
public function getTotalIssuesCount(): int
public function getTotalErrorsCount(): int
public function getTotalWarningsCount(): int
public function getTotalNoticesCount(): int
public function getResultsGroupedByUrl(): array // array<string, Pa11yResult>
public function getAllErrors(): array           // Pa11yIssue[]
public function getAllWarnings(): array         // Pa11yIssue[]
public function getAllNotices(): array          // Pa11yIssue[]
public function getAllIssues(): array           // Pa11yIssue[]
public function getResultsOfUrl(string $url): Pa11yResult
public function getUrls(): array                // string[]

Pa11yCiResult implements ArrayAccess and JsonSerializable. getTotalIssuesCount() reads the errors field from pa11y-ci. getTotalErrorsCount() sums the issues per page.

Pa11yIssue

Source: src/Pa11yIssue.php

public function __construct(array $rawIssue = [])
public function setRawIssue(array $rawIssue): self
public function json(): string
public function jsonSerialize(): mixed
public function getCode(): ?string
public function getType(): ?string
public function getTypeCode(): ?int
public function getMessage(): ?string
public function getContext(): ?string
public function getSelector(): ?string
public function getRunner(): ?string
public function getRunnerExtras(): ?array

Pa11yIssue implements ArrayAccess and JsonSerializable.

Exceptions

Source: src/Exceptions/CouldNotReadOutputJson.php

namespace JkOster\Pa11y\Exceptions;

class CouldNotReadOutputJson extends \Exception
{
    public static function from(string $command = 'pa11y', string $output = ''): self
}

Pa11y::run() and Pa11yCi::run() throw CouldNotReadOutputJson when the output is empty or is not a JSON array. A non-zero CLI exit throws Symfony\Component\Process\Exception\ProcessFailedException before that check.

CLI commands

Pa11y runs:

pa11y <url> [--option value ...] --reporter json --config ./pa11y.config.json --level none

Pa11yCi runs:

pa11y-ci --config '<inline JSON>' --json

Both look up the executable with Symfony ExecutableFinder. The search paths include the package's node_modules/bin directories, /usr/local/bin, and /opt/homebrew/bin. The process working directory is the package root.

pa11y-ci fork requirement

Pa11yCi passes its config as an inline JSON string. Upstream pa11y-ci expects a file path, so the package requires the fork:

npm install -g pa11y github:jk-oster/pa11y-ci

The fork is pinned in package.json to the main commit that adds inline JSON config, sitemap index support, and the file reporter with a single JSON document on stdout.

Node requirement

pa11y 10 declares node ^22.13.0 || >=24. The pinned pa11y-ci 5.0.0 declares the same range. Older Node versions fail before Chrome starts.