Skip to content

Ancestry selector of shadow root child not guaranteed unique #4563

@WilcoFiers

Description

@WilcoFiers

Working on some shadow DOM stuff, I noticed that in order to determine whether there are multiple children in the shadow root, we're checking parentElement. For children of the shadow root this is null, which results in an ancestry that just uses the node name. You can reproduce it in the following:

<script src="/axe.js"></script>
<script>
  window.onload = () => {
    axe.run({ runOnly: 'button-name', ancestry: true }, (err, results) => {
      console.log(err || results);
    });
  };
</script>
<custom-elm>
  <template shadowrootmode="open">
    <button></button>
    <button></button>
  </template>
</custom-elm>

This will give ['html > body > custom-elm', 'button'] as the ancestry for. BOTH buttons. This doesn't seem to happen with the regular selector axe-core has, which is probably why this has gone unnoticed for so long.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions