Product
axe-core
Product Version
4.11.0
Latest Version
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
ShadowRoot as context (the TS types suggest that context may be of type Node, and ShadowRoot is a descendant of Node).
- Aligning the types with the documentation, which mentions that context should be an "element" (not a "node" —
Element is also a descendant of Node).
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
MutationObserver there, and the nodes that the mutation observer passes to its callback get passed as context to axe.run(). The mutation observer may pass a ShadowRoot instance there, causing the bug. It will be easy enough to fix it downstream by passing the shadow root's host to axe.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.
Product
axe-core
Product Version
4.11.0
Latest Version
Issue Description
Expectation + Actual
At the moment, passing a
ShadowRootinstance ascontexttoaxe.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:
ShadowRootas context (the TS types suggest that context may be of typeNode, andShadowRootis a descendant ofNode).Elementis also a descendant ofNode).How to Reproduce
CodePen: https://codepen.io/pavelp/pen/QwNEpwv
Additional context
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.