{"record":{"id":"51d1da902d7425c7","repo":"jackwener/OpenCLI","slug":"failed-to-insert-text-into-doubao-composer","errorCode":null,"errorMessage":"Failed to insert text into Doubao composer","messagePattern":"Failed to insert text into Doubao composer","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/doubao/utils.js","lineNumber":698,"sourceCode":"        throw new CommandExecutionError(prepared?.reason || 'Could not find Doubao input element');\n    }\n    let hasText = false;\n    if (page.nativeType) {\n        try {\n            await page.nativeType(text);\n            await page.wait(0.2);\n            await page.evaluate(syncComposerAfterNativeTypeScript());\n            const nativeState = await page.evaluate(composerStateScript());\n            hasText = !!nativeState?.hasText && normalizeComposerText(nativeState?.text || '') === expectedText;\n        }\n        catch { }\n    }\n    if (!hasText) {\n        const fallbackState = await page.evaluate(fillComposerScript(text));\n        hasText = !!fallbackState?.hasText && normalizeComposerText(fallbackState?.text || '') === expectedText;\n    }\n    if (!hasText) {\n        throw new CommandExecutionError('Failed to insert text into Doubao composer');\n    }\n    let submittedBy = 'enter';\n    const clicked = await page.evaluate(clickSendButtonScript());\n    if (clicked) {\n        submittedBy = 'button';\n    }\n    else if (page.nativeKeyPress) {\n        try {\n            await page.nativeKeyPress('Enter');\n        }\n        catch {\n            await page.pressKey('Enter');\n        }\n    }\n    else {\n        await page.pressKey('Enter');\n    }\n    await page.wait(0.8);","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/doubao/utils.js#L680-L716","documentation":"sendDoubaoMessage tries native typing, then falls back to fillComposerScript to insert text. It only accepts the fallback if hasText is true and the normalized composer text exactly equals the expected text. If neither method left the correct text in the composer, this CommandExecutionError is thrown.","triggerScenarios":"page.nativeType missing or failed and fillComposerScript's resulting hasText is false, or the composer text diverges from the expected normalized input (partial insertion, sanitizer stripping characters, trailing whitespace mismatch).","commonSituations":"Doubao editor sanitizes/transforms input (e.g. markdown, emoji normalization); newlines collapsed; composer focused but keystrokes dropped; contenteditable insertion blocked by site scripts.","solutions":["Retry the send — transient focus loss often causes partial insertion","Simplify the message text (remove exotic characters/markdown) and resend","Ensure the composer element is focused before typing; reload the chat page","Check normalization: compare trimmed text manually to see what diverged"],"exampleFix":"// before\nif (!hasText) throw new CommandExecutionError('Failed to insert text into Doubao composer');\n// after\nif (!hasText) {\n  await page.focusComposer();\n  const retry = await page.evaluate(fillComposerScript(text));\n  if (!(retry?.hasText && normalizeComposerText(retry.text||'') === expectedText)) {\n    throw new CommandExecutionError('Failed to insert text into Doubao composer');\n  }\n}","handlingStrategy":"validation","validationCode":"const st = await page.evaluate(fillComposerScript(text));\nconst ok = !!st?.hasText && st.text.trim() === text.replace(/\\r\\n/g,'\\n').trim();\nif (!ok) throw new Error('Composer text mismatch; abort before submit');","typeGuard":"function composerMatches(s, expected) {\n  return !!s && typeof s === 'object' && s.hasText === true && (s.text||'').replace(/\\r\\n/g,'\\n').trim() === expected;\n}","tryCatchPattern":"try {\n  await sendDoubaoMessage(page, text);\n} catch (e) {\n  if (/Failed to insert text/.test(e.message)) {\n    await page.reload();\n    await ensureDoubaoChatPage(page);\n    await sendDoubaoMessage(page, text);\n  } else throw e;\n}","preventionTips":["Verify composer content after insertion and before submitting","Avoid characters the Doubao editor may transform","Ensure composer focus before typing","Retry on transient focus-loss failures"],"tags":["doubao","composer","text-insertion","send-message"],"backgroundTag":"text-insertion-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}