diff --git a/extension/content.js b/extension/content.js index e4446a6..3a95324 100644 --- a/extension/content.js +++ b/extension/content.js @@ -157,7 +157,26 @@ function typeText(id, text) { throw new Error(`Element with mcp-id ${id} not found`); } el.focus(); - el.value = text; + + if (el.isContentEditable) { + // For contenteditable elements, try to replace the content using a selection and execCommand + // This is more likely to trigger framework state updates (like in Slate.js or Draft.js) + try { + const selection = window.getSelection(); + const range = document.createRange(); + range.selectNodeContents(el); + selection.removeAllRanges(); + selection.addRange(range); + document.execCommand('insertText', false, text); + } catch (e) { + // Fallback to innerText if execCommand fails + el.innerText = text; + } + } else { + // Standard input/textarea + el.value = text; + } + // Dispatch input and change events so frameworks (React, Vue, etc.) notice el.dispatchEvent(new Event("input", { bubbles: true })); el.dispatchEvent(new Event("change", { bubbles: true }));