Skip to content

Should it be possible to use a ShadowRoot as context? #4941

@pomerantsev

Description

@pomerantsev

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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreIssues in the core code (lib/core)fixBug fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions