{"record":{"id":"ca7be5fab1f98bd3","repo":"stablyai/orca","slug":"rich-text-selection-is-unavailable","errorCode":null,"errorMessage":"Rich-text selection is unavailable","messagePattern":"Rich-text selection is unavailable","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/browser/agent-browser-bridge.ts","lineNumber":136,"sourceCode":"}\n\n// Why: rich editors reconcile only real browser edit transactions; a direct-DOM fallback can leave their model stale.\nfunction focusedRichTextEditExpression(\n  valueExpression: string,\n  options?: { selectAll?: boolean }\n): string {\n  const selectAll = options?.selectAll ? 'true' : 'false'\n  return [\n    '(() => {',\n    ' 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)","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/browser/agent-browser-bridge.ts#L118-L154","documentation":"Thrown by the injected rich-text edit expression when selectAll is requested but typeof window.getSelection !== 'function'. This is an environment capability check: the selection API is unavailable, so a select-all-then-insert operation cannot proceed. Extremely rare in modern Chromium/Electron guests but possible in heavily restricted or non-standard embeds.","triggerScenarios":"Calling a rich-text fill with selectAll:true inside a browser context where window.getSelection has been deleted, shadowed, or is otherwise not a function (e.g. a stripped-down or sandboxed guest that removes the Selection API).","commonSituations":"A page or embedding that deletes/overrides window.getSelection, an unusual webview configuration, or an extension that clobbers the selection API.","solutions":["Detect window.getSelection availability before requesting selectAll, and fall back to inserting without selecting all.","Avoid selectAll for editors that expose their own select-all API.","If the environment is known to lack the Selection API, insert at the cursor instead of replacing all content.","Report the environment limitation to the user rather than retrying."],"exampleFix":"// before\nawait bridge.fill(editorSelector, text, { selectAll: true })\n\n// after\nconst canSelectAll = await bridge.eval('typeof window.getSelection === \"function\"')\nawait bridge.fill(editorSelector, text, { selectAll: canSelectAll === true })","handlingStrategy":"type-guard","validationCode":"const selectAllSupported = await bridge.eval('typeof window.getSelection === \\\"function\\\"')\\nawait bridge.fill(selector, text, { selectAll: selectAllSupported === true })","typeGuard":"async function selectionApiAvailable(bridge: BrowserBridge): Promise<boolean> {\\n  return (await bridge.eval('typeof window.getSelection === \\\"function\\\"')) === true\\n}","tryCatchPattern":null,"preventionTips":["Detect window.getSelection availability before requesting selectAll.","Fall back to cursor-position insertion when the Selection API is absent.","Do not assume modern APIs in heavily restricted guests.","Report environment limitations rather than retrying."],"tags":["browser","electron","rich-text","selection-api","capability-check"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}