polyfills: Missing DocumentOrShadowRoot interface implementation
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?
About this issue
- Original URL
- State: open
- Created 10 years ago
- Comments: 15 (5 by maintainers)
Commits related to this issue
- Merge pull request #66 from FluorescentHallucinogen/patch-1 Exclude more files from Bower package — committed to webcomponents/polyfills by dfreedm 10 years ago
- Preserve scope of event callbacks Fixes #66. — committed to webcomponents/polyfills by darrylyeo 10 years ago
I have recently done some investigation regarding
getSelectionAPI, 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: w3c/webcomponents#79 There is no final agreement around it yet, although we might hear some news in the end of October: https://github.com/w3c/webcomponents/issues/763#issuecomment-426514447
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 implementsgetSelection().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()(ordocument.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 rootwindow.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 treewindow.getSelection().removeAllRanges()worksSummary: 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 rootwindow.getSelection()does not leak nodes from shadow trees (reporting node asbody)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()worksExpecting both Safari 10 and 12 versions to behave the same.
@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.
@bicknellr @aomarks as you currently work on the polyfills, do you mind reopening this?