{"record":{"id":"a4dc5ab07526a5cc","repo":"jackwener/OpenCLI","slug":"failed-to-insert-text-into-gemini-composer","errorCode":null,"errorMessage":"Failed to insert text into Gemini composer","messagePattern":"Failed to insert text into Gemini composer","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gemini/utils.js","lineNumber":1317,"sourceCode":"    if (!prepared?.ok) {\n        throw new CommandExecutionError(prepared?.reason || 'Could not find Gemini composer');\n    }\n    let hasText = false;\n    if (page.nativeType) {\n        try {\n            await page.nativeType(text);\n            await page.wait(0.2);\n            const nativeState = await page.evaluate(composerHasTextScript());\n            hasText = !!nativeState?.hasText;\n        }\n        catch { }\n    }\n    if (!hasText) {\n        const fallbackState = await page.evaluate(insertComposerTextFallbackScript(text));\n        hasText = !!fallbackState?.hasText;\n    }\n    if (!hasText) {\n        throw new CommandExecutionError('Failed to insert text into Gemini composer');\n    }\n    const submitAction = await page.evaluate(submitComposerScript());\n    if (submitAction === 'button') {\n        await page.wait(1);\n        return 'button';\n    }\n    if (page.nativeKeyPress) {\n        try {\n            await page.nativeKeyPress('Enter');\n        }\n        catch {\n            await page.evaluate(dispatchComposerEnterScript());\n        }\n    }\n    else {\n        await page.evaluate(dispatchComposerEnterScript());\n    }\n    await page.wait(1);","sourceCodeStart":1299,"sourceCodeEnd":1335,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/utils.js#L1299-L1335","documentation":"Thrown by sendGeminiMessage when, after trying native typing (page.nativeType) and the in-page insertComposerTextFallbackScript, the composer still reports no text (hasText false). The library refuses to submit an empty message, so it aborts with this CommandExecutionError.","triggerScenarios":"nativeType silently fails (e.g. focus stolen, composer is a shadow-DOM/contenteditable the driver can't type into) AND the DOM-insertion fallback also fails to register text — e.g. the composer re-rendered and cleared input, the target element is readonly/disabled, or composerHasTextScript checks a different node than the one typed into.","commonSituations":"Very long messages hitting input length limits; Gemini swapping the composer element mid-type (re-render); clipboard/keyboard permissions missing in the automation context; UI updates changing the contenteditable structure so both typing and the fallback miss the real input.","solutions":["Retry sendGeminiMessage — transient re-render clearing input is the most common cause.","Check that the message doesn't exceed Gemini's input limits; try a short test string.","Verify page.nativeType works in your automation backend (permissions, focus) or rely on the fallback path.","Inspect insertComposerTextFallbackScript's target selectors against the current composer DOM and update if Gemini changed markup.","Before sending, focus the composer explicitly and dismiss any overlay that might steal focus."],"exampleFix":"// before\nawait sendGeminiMessage(page, veryLongText);\n// after\nawait sendGeminiMessage(page, veryLongText.slice(0, 5000)); // stay under composer limits","handlingStrategy":"fallback","validationCode":"// verify typing registered before submitting\nconst hasText = await page.evaluate(`(() => { const el = document.querySelector('rich-textarea, [contenteditable=\"true\"]'); return !!el && !!(el.textContent || '').trim(); })()`);\nif (!hasText) console.warn('composer empty before submit; aborting send');","typeGuard":null,"tryCatchPattern":"try {\n  await sendGeminiMessage(page, text);\n} catch (e) {\n  if (String(e.message).includes('Failed to insert text')) {\n    await page.wait(1); // let composer re-render settle\n    await sendGeminiMessage(page, text.slice(0, 4000)); // retry, shorter payload\n  } else throw e;\n}","preventionTips":["Keep messages under Gemini's composer length limits.","Avoid sending while other automation actions may steal focus.","Test page.nativeType support in your driver before relying on it.","Update fallback-insertion selectors after Gemini UI changes."],"tags":["gemini","browser-automation","input","composer"],"backgroundTag":"input-insertion-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}