-
Notifications
You must be signed in to change notification settings - Fork 667
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
[cssom-view] Specify document.caretPositionFromPoint in shadow DOM scenario #9932
Comments
@zcorpan @fantasai @tabatkins Curious if any of you have any thoughts on how we can better define the behavior of |
Are there other APIs that pierce shadow DOM?
+1 to this idea. |
Asked opinions from web developer's point of view and got some feedback. Web developer's basic requirement is to be able to get a caret position inside shadow roots. The Firefox approach (piercing through the shadow boundary) is acceptable. In fact, sticking to the already existing behavior would allow web developer to simplify the implementation. Given that, should we specify the already existing Firefox approach and put it in spec? |
So in my opinion, the Gecko approach should definitely not be put in the spec. It trivially reveals shadow root contents, including for closed roots, which is very bad:
I'd +1 the comments above that this should follow the behavior of |
Based on all feedback, the best approach seems to be the The alternative approach is to put the API on Web developer needs to adjust the current usage of current API to get position in a shadow root. The existing behavior violates the boundary of closed shadow tree so we should consider fixing it as well. |
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> Liu: This API is defined in cssom-view, and spec doesn't have a definition for behavior in shadow DOM<fantasai> Liu: Existing behavior is [missed] <fantasai> Liu: Other alternatives are to not pierce shadow DOM <fantasai> Liu: Another approach is to add a new parameter with set of shadow roots, and will return positio inside the shadow roots <fantasai> Liu: Gathered feedback from community, and preference is to add parameter and only pierce the specified shadow roots <fantasai> Liu: If this is acceptable, should we adopt? <fantasai> Liu: Firefox's implementation is that the API can pierce the shadow tree, and tree can be open or closed shadow tree <fantasai> mfreed: I'm definitely not a fan of revealing contents of shadow trees, particularly closed ones <fantasai> mfreed: I heard proposed to use getComposedRanges behavior, where if you don't know about the shadow tree you get the shadow host <dandclark> q+ <sanketj_> q+ <fantasai> astearns: I'm not familiar with these APIs. Is getComposedRanges same pattern as what's proposed here? <fantasai> mfreed: Yes. parameters to say which you know about, and it will pierce those, and give you host for those that you don't <astearns> ack dandclark <fantasai> dandclark: getComposedRanges spec link dropped in the issue doesn't take a parameter <fantasai> dandclark: do browsers implement something else? <fantasai> mfreed: It's only implemented in WebKit, definitely not in Blink yet <fantasai> astearns: Looking at WebIDL there's a parameter, just not in description <fantasai> dandclark: OK <astearns> ack sanketj_ <dholbert> q+ <fantasai> sanketj_: Seems that Firefox is only one that pierces closed shadow tree, so getComposedRanges addresses that, so +1 <astearns> ack dholbert <fantasai> dholbert: With this version of the API, that takes list of shadow roots to pierce, if web developer listed every shadow root in their page they would get existing Firefox behavior? <fantasai> mfreed: yes, but not possible if you don't have reference to the shadow root you can't provide it <fantasai> mfreed: so e.g. closed shadow root, unless you set it up, you can't get it <fantasai> astearns: wrt the spec descriptions, the descriptions don't mention parameters, but the algorithms do process them <fantasai> astearns: Sounds like we're ready to resolve? Any additional comments? <fantasai> astearns: Proposed resolution is that caretPositionFromPoint can follow the getComposedRanges behavior and have a shadowRoots parameter <fantasai> RESOLVED: add shadowRoots parameter to caretPositionFromPoint, same as getComposedRanges |
Per w3c#9932, add `shadowRoots` parameter to `caretPositionFromPoint` API.
…API. (#10200) * Update Overview.bs Per #9932, add `shadowRoots` parameter to `caretPositionFromPoint` API. * Update Overview.bs Bubble `caret range` out of the shadow roots. * Update Overview.bs Address PR comments. * Update Overview.bs Address PR comment. * Update Overview.bs Address PR comment. * Update Overview.bs linked created issue(10230) to the spec.
The PR was merged, closing. |
The spec for caretPositionFromPoint has been updated to require providing `shadowRoots` in order to dig into Shadow DOM content.[1] This has been implemented in Chrome[2] and is due to ship in 128 (in beta at the time of this patch). It has also been implemented in Firefox[3] but is currently only enabled on the Nightly channel.[4] This API is quite annoying for extensions that simply want to scan all the text in the document but I guess it makes sense for regular Web apps. [1] w3c/csswg-drafts#9932 [2] https://issues.chromium.org/issues/41117286 [3] https://bugzilla.mozilla.org/show_bug.cgi?id=1889503 [4] https://searchfox.org/mozilla-central/rev/64f196824745c5db5ef7bb23725cfb9a41586149/modules/libpref/init/StaticPrefList.yaml#4742-4751
The spec for caretPositionFromPoint has been updated to require providing `shadowRoots` in order to dig into Shadow DOM content.[1] This has been implemented in Chrome[2] and is due to ship in 128 (in beta at the time of this patch). It has also been implemented in Firefox[3] but is currently only enabled on the Nightly channel.[4] This API is quite annoying for extensions that simply want to scan all the text in the document but I guess it makes sense for regular Web apps. [1] w3c/csswg-drafts#9932 [2] https://issues.chromium.org/issues/41117286 [3] https://bugzilla.mozilla.org/show_bug.cgi?id=1889503 [4] https://searchfox.org/mozilla-central/rev/64f196824745c5db5ef7bb23725cfb9a41586149/modules/libpref/init/StaticPrefList.yaml#4742-4751
Current spec is vague about the behavior in shadow DOM: https://www.w3.org/TR/cssom-view-1/#dom-document-caretpositionfrompoint
Gecko's current behavior in shadow DOM:
The returned
CaretPosition
'soffset
is the text offset of the hit tested text node and theoffsetNode
depends on the mode of the shadow tree:Gecko's existing behavior can address most of the need for web developers. Should we specify the behavior?
Or are there other alternatives that we should consider:
caretPositionFromPoint
do not pierce shadow DOM. Instead, put the API onDocumentOrShadowRoot
.document.caretPositionFromPoint(x, y, closedShadowRoot);
The text was updated successfully, but these errors were encountered: