JSFiddle - React, Tailwind, and code Playground
HTML
<div id="hello">Hello</div>
<div id="app" />
JavaScript
const appRoot = document.getElementById("app");
const shadowRoot = appRoot.attachShadow({ mode: "open" });
const widgetRoot = document.createElement("div");
widgetRoot.id = "widgetRoot";
shadowRoot.appendChild(widgetRoot);
const scriptElement = document.createElement("script");
widgetRoot.appendChild(scriptElement);
scriptElement.setAttribute("type", "text/javascript");
scriptElement.textContent = `
alert(document.getElementById('hello').innerHTML);
`;