JSFiddle - React, Tailwind, and code Playground
by souf123
HTML
<div id="host"></div>
<span>I'm not in the shadow DOM</span>
JavaScript
const host = document.querySelector("#host");
const shadow = host.attachShadow({ mode: "open" });
const span = document.createElement("span");
span.textContent = "I'm in the shadow DOM";
shadow.appendChild(span);
document.addEventListener('selectionchange', () => {
console.log(window.getSelection().getComposedRanges()[0]);
} );