Skip to content

[css-highlight-api] Exposing shadow DOM highlights in highlightsFromPoint() #7766

Description

@dandclark

The highlightsFromPoint() function, discussed here, should probably not return highlights in shadow DOMs by default. But, there should still be a way for authors to allow interaction with highlights in shadows using highlightsFromPoint().

I can think of two ways to have this function expose shadow DOM highlights.

The first is to handle it like getInnerHTML() does for Declarative Shadow DOM, in which it takes an includeShadowRoots option as well as a list of closed shadow roots. Highlights inside those shadows can be returned without breaking encapsulation, sinc the caller has proven that they already know about them: https://web.dev/declarative-shadow-dom/#serialization. Highlights could do something similar:

const hitTestResults = CSS.highlights.highlightsFromPoint({
  includeShadowRoots: true,
  closedRoots: [shadowRoot1, shadowRoot2, ...]
});

Alternatively, we could put highlightsFromPoint() on DocumentOrShadowRoot. When called on a Document, it would return only highlights in that document (not in its shadow roots). When called on a shadow root, it would return only highlights in that shadow, or perhaps highlights in that shadow plus highlights in the document (but not highlights in any nested shadow roots). This is analogous to how elementsFromPoint() works in Blink and Gecko today, though the spec doesn't yet reflect that elementsFromPoint() is callable on shadow DOM and I see some cross-browser inconsistencies in which elements are returned.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions