accessibility-checker-engine
Overview
accessibility-checker-engine
is a DOM, rule-based engine for detecting issues in web applications. The engine is used by the IBM Equal Access Accessibility Checker suite of tools. The rules and engine are fully written in JavaScript and can be injected directly into web pages and applications.
Get the engine
Install accessibility-checker-engine in a Node environment to inject into a browser environment:
$ npm install --save-dev accessibility-checker-engine
Use a CDN to access the engine in a browser environment:
<script src="https://unpkg.com/accessibility-checker-engine@latest/ace.js"></script>
Quick start
See CodeSandbox Demo for a more complete example.
const checker = new ace.Checker();
const report = await checker.check(document, ["IBM_Accessibility"]);
API
The most important entry point API is the check
method of ace.Checker
object. You can use a callback or Promise mechanism to retrieve the accessibility results for further processing in your javascript or NodeJS program.
const checker = new ace.Checker();
checker.check(doc, ["IBM_Accessibility"])
.then(function(report) {
});
doc
- can be one of:
- a Document Object Model (
DOM
) object representing an HTML document which is usually available in a browser environment as document
- a
DOM
element representing a fragment HTML which can be retrieved from a DOM
by matching against one or more selectors.
["IBM_Accessibility"]
- apply IBM accessibility ruleset.report
- accessibility results contains identified accessibility issues and their descriptions from the given doc
, and a summary of the issues. The report is in JSON format (see details).
Checklist and Rulesets
The rule are based on the IBM Checklist, which is a superset of WCAG 2.1 AA. We also provide a WCAG 2.0 AA rulesets. Mappings from the checklists to rules are defined in the ruleset file
Report
The accessibility report is in JSON format, and contains information about the identified accessibility issues and their descriptions.
{
report: {
scanID: "18504e0c-fcaa-4a78-a07c-4f96e433f3e7",
toolID: "@ibma/aat-v2.0.6",
label: "MyTestLabel",
numExecuted: 137,
nls: {
"WCAG20_Html_HasLang": {
"Pass_0": "Page language detected as {0}"
},
},
summary: {
URL: "https://www.ibm.com/en-US/",
counts: {
violation: 1,
potentialviolation: 0,
recommendation: 0,
potentialrecommendation: 0,
manual: 0,
pass: 136,
ignored: 0
},
scanTime: 29,
ruleArchive: "September 2019 Deployment (2019SeptDeploy)",
policies: [
"IBM_Accessibility"
],
reportLevels: [
"violation",
"potentialviolation",
"recommendation",
"potentialrecommendation",
"manual"
],
startScan: 1470103006149
},
results: [
{
"ruleId": "WCAG20_Html_HasLang",
"reasonId": "Pass_0",
"value": [
"VIOLATION",
"PASS"
],
"path": {
"dom": "/html[1]",
"aria": "/document[1]"
},
"ruleTime": 0,
"message": "Page language detected as en",
"messageArgs": [
"en"
],
"apiArgs": [],
"bounds": {
"left": 0,
"top": 0,
"height": 143,
"width": 800
},
"snippet": "<html lang=\"en\">",
"category": "Accessibility",
"ignored": false,
"level": "pass"
},
]
}
}
Usage examples
This section provides 'AS-IS' code examples, snippets, or logic. The users are expected to make changes according to their environments.
Command-line in a browser developer tool
You can use the wrapper method checkDemo
in ace
object, which is specifically created for checking accessibility in a browser developer tool. The checkDemo
method outputs both raw accessibility results in JSON format, and the results sorted by elements identified by their xPath. Following are the example steps to use ace.checkDemo()
to display the results in a Chrome developer tool:
- Navigate to a page or type the url to the page in Chrome browser
- Open the developer tool in Chrome browser: click
Customize and Control Google Chrome
button, select More Tools
, then select Developer Tool
- Select
Console
tab to show command prompt - Open
ace.js
select and copy all the content - Paste the content you copied to the command prompt in the developer tool, then press
Enter
- Type in the command prompt:
ace.checkDemo()
, then Enter
You can view the accessibility report for the page:
Programmatic
The following code snippet demonstrates how to use ACE to test a web page for accessibility in an embedded Chrome environment (puppeteer
). See accessibility-checker for a more complete tool for this environment.
(async () => {
const chromeLauncher = require('chrome-launcher');
const axios = require('axios');
const puppeteer = require('puppeteer');
const chrome = await chromeLauncher.launch({
logLevel: 'info',
output: 'json'
});
const response = await axios.get(`http://localhost:${chrome.port}/json/version`);
const { webSocketDebuggerUrl } = response.data;
const browser = await puppeteer.connect({ browserWSEndpoint: webSocketDebuggerUrl });
const [page] = await browser.pages();
await page.goto('http://localhost:3000', { waitUtil: 'domcontentloaded' };
await page.addScriptTag({ path: path.join(__dirname, 'ace.js') });
await page.evaluate(() => {
const checker = new ace.Checker();
checker.check(document, ["IBM_Accessibility"])
.then(function (report) {
for (let idx = 0; idx < report.results.length; ++idx) {
}
});
});
})();
Browser extensions
You can use the accessibility-checker-extension for Chrome or Firefox. The browser extensions integrate the accessibility web engine (ace.js) and formatted results into the browser developer tool to visually view the accessibility issues and the locations of violating components. For more information and instructions, please view accessibility-checker-extensions.
Integration with test frameworks
You can use the karma-accessibility-checker to integrate accessibility web engine into Karma or Selenium test framework. For more information and instructions, please view karma-accessibility-checker.
Reporting bugs
If you think you've found a bug, have questions or suggestions, please report the bug in GitHub Issues.
This software includes material copied from or derived from the open ACT-Rules Community. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).