Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pierce shadowroots on Chromium using caretPositionFromPoint #1845

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Kuuuube
Copy link
Member

@Kuuuube Kuuuube commented Feb 26, 2025

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

@Kuuuube Kuuuube added the kind/enhancement The issue or PR is a new feature or request label Feb 26, 2025
@Kuuuube Kuuuube requested a review from a team as a code owner February 26, 2025 05:28
@Kuuuube Kuuuube added browser/chrome The issue is Chrome-only browser/edge The issue is Edge-only labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser/chrome The issue is Chrome-only browser/edge The issue is Edge-only kind/enhancement The issue or PR is a new feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yomitan doesn't scan in Microsoft Copilot due to shadow root
1 participant