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

Missing DocumentOrShadowRoot interface implementation #66

Open
bedeoverend opened this issue Mar 17, 2017 · 14 comments
Open

Missing DocumentOrShadowRoot interface implementation #66

bedeoverend opened this issue Mar 17, 2017 · 14 comments
Assignees

Comments

@bedeoverend
Copy link

Doesn't appear implement the DocumentOrShadowRoot interface - or only activeElement property seems to be implemented. Particularly for dealing with selections and ranges this is needed. I'm trying to use Prosemirror inside a component but this causes it to break - any chance some, if not all this interface will get implemented?

@bedeoverend
Copy link
Author

Worth noting it seems only Chrome has implemented this - WebKit has an open bug

@sorvell
Copy link
Collaborator

sorvell commented Apr 4, 2017

I think at least some subset of the range/selection api could be implemented. It will likely be significant code and therefore, I'd imagine making it opt-in. The focus currently is on getting the core functionality of the library production ready rather than adding more advanced features.

@dam0vm3nt
Copy link

Hi guys, meanwhile this get fixed, is there any realiable way of getting the caret position in a contenteditable inside a shadyRoot ? Can I use window.getSelection() ?

@olegomon
Copy link

olegomon commented May 4, 2018

@sorvell There is there any progress on implementing the full interface for the DocumentOrShadowRoot interface? I think the full support for it is required for any WYSIWYG editors which are based on the "contenteditable" elements.

Also note that there is an attempt to implement "shadowRoot.getSelection()" polyfill already.
See shadow-selection-polyfill

@web-padawan
Copy link
Contributor

web-padawan commented Oct 4, 2018

I have recently done some investigation regarding getSelection API, sharing the results.

Short summary

Only Chrome supports getSelection() on the Shadow Root. Neither Firefox 63 beta, nor Safari have it enabled. In Firefox 63 global API still works, Safari 10+ needs a polyfill.

Long Story

Original issue is being discussed here: WICG/webcomponents#79
There is no final agreement around it yet, although we might hear some news in the end of October: WICG/webcomponents#763 (comment)

There is an unofficial polyfill by one guy from Google, which only covers part of functionality:
https://github.com/GoogleChromeLabs/shadow-selection-polyfill

Especially, it is not designed to emulate the whole getSelection() API , but only implements getSelection().getRangeAt(0) which appears to be working nice, still it needs to be properly tested, preferably covered by automated tests (as much as possible).

This issue is affects lots of WYSIWYG editors relying on window.getSelection() (or document.getSelection() which is the same), when those are placed inside of the shadow root:

Below goes the result of testing window.getSelection() API in the browsers lacking it on shadow root:

Firefox 63 beta

https://bugzilla.mozilla.org/show_bug.cgi?id=1430308

  • getSelection() not implemented on shadow root
  • window.getSelection() returns nodes from shadow trees (leaking as if they were not in shadow)
  • window.getSelection().addRange() applies the selection when passing range with start and end nodes from the inside of shadow tree
  • window.getSelection().removeAllRanges() works

Summary: Firefox 63 beta could be using global API for now, but this might break in future

Safari 11

https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/dom/DocumentOrShadowRoot.idl#L30
https://bugs.webkit.org/show_bug.cgi?id=163921

  • getSelection() is not implemented on shadow root
  • window.getSelection() does not leak nodes from shadow trees (reporting node as body)
  • window.getSelection().addRange() works when passing range with start and end nodes from shadow tree (so using global API seems to work here)
  • window.getSelection().removeAllRanges() works

Expecting both Safari 10 and 12 versions to behave the same.

@dfreedm dfreedm self-assigned this Oct 5, 2018
@dfreedm dfreedm transferred this issue from webcomponents/shadydom Jun 7, 2019
@samthor
Copy link

samthor commented Jun 7, 2019

FYI I wrote a disgusting polyfill for .getSelection inside a Shadow Root here: https://github.com/GoogleChromeLabs/shadow-selection-polyfill

@web-padawan
Copy link
Contributor

@azakus @sorvell this issue appears to be closed by accident, most likely in progress of migrating to monorepo. The actual issue is still valid, so please reopen.

Also, the opt-in implementation for this would be highly appreciated.

@web-padawan
Copy link
Contributor

@bicknellr @aomarks as you currently work on the polyfills, do you mind reopening this?

@aomarks aomarks reopened this Jun 12, 2020
@stale
Copy link

stale bot commented Jun 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 13, 2021
@web-padawan
Copy link
Contributor

Is there any chance to implement a proper polyfill based on the one created by @samthor?

@stale stale bot removed the wontfix label Jun 13, 2021
@samthor
Copy link

samthor commented Jun 13, 2021

It stopped working on the latest Safari; I wouldn't recommend trying to bring it back, sorry.

@stale
Copy link

stale bot commented Jun 23, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 23, 2022
@web-padawan
Copy link
Contributor

web-padawan commented Jan 4, 2023

For anyone interested, we ended up with adding a new shadow selection shim to our Quill fork, see vaadin/quill#2.

@luijar
Copy link

luijar commented Sep 6, 2023

Hey guys, just stopping by to see if anyone knew what the status is for implementing Selection API consistently across browsers was, at least within a shadow root? Not even expecting to cross shadow boundaries yet, but at least within the same root. Any information would help, thanks!

@stale stale bot removed the wontfix label Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants