Pierce shadowroots on Chromium using caretPositionFromPoint #1845
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1044
Almost a year ago I wrote this comment #1044 (comment) on our shadow dom issues. Since then, Chromium has gotten
caretPositionFromPoint
into stable builds and support for theshadowRoots
option has been added. There also should have been plenty of time for all maintained Chromium forks to get up to date with this feature.This allows piercing any shadow root specified by the options. Firefox's implementation pierces all shadow roots by default but we aren't so lucky to get that on Chromium (the people making the w3c spec were against handling it like this w3c/csswg-drafts#9932 (comment)).
_findShadowRoots
here will get us all the shadow roots within all children of the input element.The shadow roots are only searched for if
caretPositionFromPoint
hasnt drilled down to the text to begin with (if we already have the text theres no point in searching for it further). And if the text isn't found, it will start searching for shadow roots at whatever element it ended up drilling down to until it hit shadow dom.Tested on Firefox 136 and Chromium 133. Unsure if this will blow up on any older versions (testing on kiwi would be a good idea). The feature
caretPositionFromPoint
is checked for with fallback provided.Easy test case: https://chromestatus.com/feature/5201014343073792. This site is covered in shadow roots.