{"record":{"id":"530565a8e4f2948f","repo":"stablyai/orca","slug":"browser-rich-text-editing-command-failed","errorCode":null,"errorMessage":"Browser rich-text editing command failed","messagePattern":"Browser rich-text editing command failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/browser/agent-browser-bridge.ts","lineNumber":146,"sourceCode":"    ' const target = document.activeElement;',\n    ' const value = ',\n    valueExpression,\n    ';',\n    ` const selectAll = ${selectAll};`,\n    \" const isEditable = target?.isContentEditable === true || /^(|true|plaintext-only)$/i.test(target?.getAttribute?.('contenteditable') ?? 'false');\",\n    \" if (!target || target === document.body || !isEditable) { throw new Error('Focused rich-text target is unavailable'); }\",\n    ' if (selectAll) {',\n    \"   if (typeof window.getSelection !== 'function') { throw new Error('Rich-text selection is unavailable'); }\",\n    '   const selection = window.getSelection();',\n    \"   if (!selection) { throw new Error('Rich-text selection is unavailable'); }\",\n    '   selection.selectAllChildren(target);',\n    ' }',\n    \" const editCommand = selectAll && value.length === 0 ? 'delete' : 'insertText';\",\n    ' let edited = false;',\n    ' try {',\n    '   edited = document.execCommand(editCommand, false, value) === true;',\n    ' } catch { edited = false; }',\n    \" if (!edited) { throw new Error('Browser rich-text editing command failed'); }\",\n    ' })()'\n  ].join('')\n}\n\nfunction isExplicitContentEditableResult(result: unknown): boolean {\n  const value =\n    result && typeof result === 'object' ? (result as { value?: unknown }).value : undefined\n  return typeof value === 'string' && /^(|true|plaintext-only)$/i.test(value)\n}\n\ntype AgentBrowserExecOptions = {\n  envOverrides?: NodeJS.ProcessEnv\n  timeoutMs?: number\n  timeoutError?: BrowserError\n  stdinText?: string\n}\n\ntype EnqueueTargetedCommandOptions = {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/browser/agent-browser-bridge.ts#L128-L164","documentation":"Thrown by the injected rich-text edit expression when document.execCommand('insertText'|'delete', ...) returns false or throws. execCommand is the bridge's chosen edit path because it produces a real input transaction that rich editors reconcile; when it fails, the value was not committed to the editor's model, so the bridge refuses to report success.","triggerScenarios":"The contentEditable element does not support execCommand text insertion (some custom editors intercept/preventDefault on beforeinput), the editor is read-only/disabled, execCommand is deprecated and unimplemented for a given editor type, or the editable region lost focus mid-edit.","commonSituations":"Filling a rich editor that overrides default input handling (Lexical, Slate, custom ContentEditable), an editor in a disabled/readonly state, or a browser build where execCommand is a no-op for the focused node.","solutions":["Confirm the editor is editable and focused before filling.","For editors known to block execCommand, dispatch input events directly (BeforeInputEvent) via CDP instead.","Retry focus then fill, since focus loss is a common cause of execCommand returning false.","If the editor exposes a programmatic setValue API, use that instead of simulated typing."],"exampleFix":"// before\nawait bridge.fill(editorSelector, text)\n\n// after\nawait bridge.focus(editorSelector)\ntry {\n  await bridge.fill(editorSelector, text)\n} catch (err) {\n  if (/rich-text editing command failed/i.test(err.message)) {\n    // editor blocks execCommand — use CDP input-event dispatch\n    await dispatchInputEventViaCdp(editorSelector, text)\n  } else throw err\n}","handlingStrategy":"fallback","validationCode":"// confirm the editor accepts execCommand before relying on fill:\\nconst editable = await isFocusedEditable(bridge)\\nif (!editable) {\\n  await bridge.focus(selector)\\n}","typeGuard":"async function editorAcceptsExecCommand(bridge: BrowserBridge): Promise<boolean> {\\n  return (await bridge.eval('(() => { try { return document.execCommand(\\\"insertText\\\", false, \\\"\\\") === true; } catch { return false; } })()')) === true\\n}","tryCatchPattern":"try {\\n  await bridge.fill(selector, text)\\n} catch (err) {\\n  if (/Browser rich-text editing command failed/.test((err as Error).message)) {\\n    await dispatchInputEventViaCdp(selector, text) // editor blocks execCommand\\n    return\\n  }\\n  throw err\\n}","preventionTips":["Confirm the editor is editable and focused before filling.","For editors that block execCommand (Lexical, Slate), dispatch input events via CDP.","Retry focus then fill once.","Use the editor's own setValue API when available."],"tags":["browser","electron","rich-text","execcommand","dom","contenteditable"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}