JSFiddle - React, Tailwind, and code Playground
JavaScript
let iframe = document.createElement("iframe");
iframe.onload = () => {
iframe.contentWindow.focus();
let doc = iframe.contentDocument;
doc.designMode = "on";
doc.body.focus();
//let editor = doc.getElementById("editor");
//editor.focus();
//doc.getSelection().collapse(editor, 0);
iframe.style.display = "none";
doc.execCommand("insertText", false, "foo");
iframe.style.display = "block";
};
iframe.srcdoc = "<div id=\"editor\" contenteditable></div>";
document.body.appendChild(iframe);