[WIP] Add lower-level runner API to support non-browser runners #524
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Initially discussed on Slack. Currently just a draft PR with lots of missing parts.
Pa11y supports custom runners, but those runners are only executed within the context of the browser (with Puppeteer’s
page.evaluate
). I would like to make runners that rely on "server-side" processing, either Node modules that cannot run in the browser, or CLI tools from other languages that can only be integrated with Node code.This PR reworks the runners’ integration to introduce a new lower-level API that supports the scenario described above, as well as making it possible for runners to manipulate the Puppeteer page if they want to – e.g. to read the page’s accessibility tree, or see if the page has horizontal scrolling on smaller viewport sizes.
This implementation does two things:
processPage
" method for runners, which is invoked instead ofrun
when present, and gives runners access to the Puppeteer page, expecting an array of issues back.I’m not particularly convinced this is the best abstraction / API, but it’s the one that was the least work to get experimenting with.
There are a few things I haven’t touched yet and would likely need to address in some way:
loadRunnerScript
still executes even if the runner has noscripts
norrun
method.scripts: []
, andrun: () => {}
.assertReporterCompatibility
only runs withinloadRunnerScript
. IfloadRunnerScript
is changed, that compatibility check would need to be done elsewhere.context
andselector
as Pa11y does relies on the runner providing a DOM element.ignore
by code only works for runners that have codes :)rootElement
filtering depends on the DOMhideElements
also depends on the DOMTo try this out, here are install instructions with the runner I’m currently working on based on the v.Nu HTML validator:
Output
$ pa11y --runner vnu https://www.example.com/ Welcome to Pa11y > Running Pa11y on URL https://www.example.com/ Results for URL: https://www.example.com/ • Error: A document must not include both a “meta” element with an “http-equiv” attribute whose value is “content-type”, and a “meta” element with a “charset” attribute. ├── html-validation ├── └── f-8"> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> < • Notice: The “type” attribute for the “style” element is not needed and should be omitted. ├── html-validation ├── └── e=1"> <style type="text/css"> b • Notice: Consider adding a “lang” attribute to the “html” start tag to declare the language of this document. ├── html-validation ├── └── TYPE html><html><head> 1 Errors 2 Notices
Here is the source of that runner: pa11y-runner-vnu, and extra install instructions. If you don’t want to install
vnu
, here is a much simpler dummy runner you can try this with: