stablyai/orca · error · Error

Focused rich-text target is unavailable

Error message

Focused rich-text target is unavailable

What it means

Thrown by injected JavaScript that focusedRichTextEditExpression builds and evaluates inside the browser page. It fires when document.activeElement is null, is document.body, or is not contentEditable (neither isContentEditable nor a 'true'/'plaintext-only' contenteditable attribute). The bridge requires a real editable host to drive edits through the browser's own input pipeline so rich editors (ProseMirror, etc.) reconcile correctly.

Source

Thrown at src/main/browser/agent-browser-bridge.ts:134

    ' } })()'
  ].join('')
}

// Why: rich editors reconcile only real browser edit transactions; a direct-DOM fallback can leave their model stale.
function focusedRichTextEditExpression(
  valueExpression: string,
  options?: { selectAll?: boolean }
): string {
  const selectAll = options?.selectAll ? 'true' : 'false'
  return [
    '(() => {',
    ' const target = document.activeElement;',
    ' const value = ',
    valueExpression,
    ';',
    ` const selectAll = ${selectAll};`,
    " const isEditable = target?.isContentEditable === true || /^(|true|plaintext-only)$/i.test(target?.getAttribute?.('contenteditable') ?? 'false');",
    " if (!target || target === document.body || !isEditable) { throw new Error('Focused rich-text target is unavailable'); }",
    ' if (selectAll) {',
    "   if (typeof window.getSelection !== 'function') { throw new Error('Rich-text selection is unavailable'); }",
    '   const selection = window.getSelection();',
    "   if (!selection) { throw new Error('Rich-text selection is unavailable'); }",
    '   selection.selectAllChildren(target);',
    ' }',
    " const editCommand = selectAll && value.length === 0 ? 'delete' : 'insertText';",
    ' let edited = false;',
    ' try {',
    '   edited = document.execCommand(editCommand, false, value) === true;',
    ' } catch { edited = false; }',
    " if (!edited) { throw new Error('Browser rich-text editing command failed'); }",
    ' })()'
  ].join('')
}

function isExplicitContentEditableResult(result: unknown): boolean {
  const value =

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Ensure the target element is focused and is genuinely contentEditable before filling — call the bridge's focus step and re-check.
  2. Wait for the rich editor to finish mounting before filling (e.g. wait for a contenteditable attribute).
  3. Use the bridge's explicit contenteditable detection (isExplicitContentEditableTarget) to confirm the target type.
  4. Retry the focus+fill sequence once, since transient focus loss is common.

Example fix

// before
await bridge.fill('[data-editor]', text)

// after
await bridge.focus('[data-editor]')
// confirm the editor is editable, then fill
await bridge.fill('[data-editor]', text)
Defensive patterns

Strategy: validation

Validate before calling

// run in the page before fill to confirm an editable host is focused:\nconst isEditable = await bridge.eval(\n  '(() => { const t = document.activeElement; return !!t && t !== document.body && ' +\n  '(t.isContentEditable === true || /^(|true|plaintext-only)$/i.test(t.getAttribute?.(\"contenteditable\") ?? \"false\")); })()'\n)\nif (!isEditable) {\n  throw new Error('No focused contentEditable target — focus the editor first')\n}

Type guard

async function isFocusedEditable(bridge: BrowserBridge): Promise<boolean> {\n  return Boolean(await bridge.eval(\n    '(() => { const t = document.activeElement; return !!t && t !== document.body && (t.isContentEditable === true || /^(|true|plaintext-only)$/i.test(t.getAttribute?.(\"contenteditable\") ?? \"false\")); })()'\n  ))\n}

Try / catch

try {\n  await bridge.focus(selector)\n  await bridge.fill(selector, text)\n} catch (err) {\n  if (/Focused rich-text target is unavailable/.test((err as Error).message)) {\n    await bridge.focus(selector)\n    await bridge.fill(selector, text) // one retry\n    return\n  }\n  throw err\n}

Prevention

When it happens

Trigger: Calling fill on an element while focus has moved away from the editable target — e.g. the page blurred it, a modal stole focus, the element was never focused first, or the selector resolved to a non-editable node (plain div, span, or body).

Common situations: Filling a rich editor that lazily mounts, focus lost to a popup/autocomplete between the focus step and the eval, filling a non-contentEditable element by mistake, or a page that programmatically blurs on focus.

Related errors


AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12). Data as JSON: /api/errors/f8d05e3296992db9. Report an issue: GitHub.