-
Notifications
You must be signed in to change notification settings - Fork 847
Open
Labels
Description
Product
axe-core
Product Version
4.11.0
Latest Version
- I have tested the issue with the latest version of the product
Issue Description
Expectation + Actual
At the moment, passing a ShadowRoot instance as context to axe.run() results in an error: "No elements found for include in page Context".
It's either a bug, or an issue with TypeScript types (see below).
Consider either:
- Supporting a
ShadowRootas context (the TS types suggest that context may be of typeNode, andShadowRootis a descendant ofNode). - Aligning the types with the documentation, which mentions that context should be an "element" (not a "node" —
Elementis also a descendant ofNode).
How to Reproduce
CodePen: https://codepen.io/pavelp/pen/QwNEpwv
Additional context
- I ran into this due to noticing a bug in Accented, a library that I maintain. There's a
MutationObserverthere, and the nodes that the mutation observer passes to its callback get passed as context toaxe.run(). The mutation observer may pass aShadowRootinstance there, causing the bug. It will be easy enough to fix it downstream by passing the shadow root'shosttoaxe.run()instead of passing the shadow root. However, axe would be a little more robust if it accepted the shadow root directly. - It's not clear whether such treatment of shadow roots was intentional or not, and how easy that would be to change. I poked at the code a little, and it seems that axe maintains a cache of all the elements on the page, and the code that populates it omits the shadow roots themselves, jumping straight to their children.