If we have two nodes outer and inner, each one of them has shadowRoot
const inner = document.createElement("span");
inner.attachShadow({ mode: "open" }).innerHTML = "inner";
const outer = document.createElement("span");
outer.attachShadow({ mode: "open" }).append("outer ", inner);
document.body.append(outer);
Then we select a text exists in both
If we try to get selected text
window.getSelection().toString()
We get 'er '
which is incorrect! Even if try to get selection on the shadowRoot of inner span it not correct.
- How to get selection is this case?