jackwener/OpenCLI · error · CommandExecutionError

Failed to insert text into Doubao composer

Error message

Failed to insert text into Doubao composer

What it means

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.

Source

Thrown at clis/doubao/utils.js:698

        throw new CommandExecutionError(prepared?.reason || 'Could not find Doubao input element');
    }
    let hasText = false;
    if (page.nativeType) {
        try {
            await page.nativeType(text);
            await page.wait(0.2);
            await page.evaluate(syncComposerAfterNativeTypeScript());
            const nativeState = await page.evaluate(composerStateScript());
            hasText = !!nativeState?.hasText && normalizeComposerText(nativeState?.text || '') === expectedText;
        }
        catch { }
    }
    if (!hasText) {
        const fallbackState = await page.evaluate(fillComposerScript(text));
        hasText = !!fallbackState?.hasText && normalizeComposerText(fallbackState?.text || '') === expectedText;
    }
    if (!hasText) {
        throw new CommandExecutionError('Failed to insert text into Doubao composer');
    }
    let submittedBy = 'enter';
    const clicked = await page.evaluate(clickSendButtonScript());
    if (clicked) {
        submittedBy = 'button';
    }
    else if (page.nativeKeyPress) {
        try {
            await page.nativeKeyPress('Enter');
        }
        catch {
            await page.pressKey('Enter');
        }
    }
    else {
        await page.pressKey('Enter');
    }
    await page.wait(0.8);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the send — transient focus loss often causes partial insertion
  2. Simplify the message text (remove exotic characters/markdown) and resend
  3. Ensure the composer element is focused before typing; reload the chat page
  4. Check normalization: compare trimmed text manually to see what diverged

Example fix

// before
if (!hasText) throw new CommandExecutionError('Failed to insert text into Doubao composer');
// after
if (!hasText) {
  await page.focusComposer();
  const retry = await page.evaluate(fillComposerScript(text));
  if (!(retry?.hasText && normalizeComposerText(retry.text||'') === expectedText)) {
    throw new CommandExecutionError('Failed to insert text into Doubao composer');
  }
}
Defensive patterns

Strategy: validation

Validate before calling

const st = await page.evaluate(fillComposerScript(text));
const ok = !!st?.hasText && st.text.trim() === text.replace(/\r\n/g,'\n').trim();
if (!ok) throw new Error('Composer text mismatch; abort before submit');

Type guard

function composerMatches(s, expected) {
  return !!s && typeof s === 'object' && s.hasText === true && (s.text||'').replace(/\r\n/g,'\n').trim() === expected;
}

Try / catch

try {
  await sendDoubaoMessage(page, text);
} catch (e) {
  if (/Failed to insert text/.test(e.message)) {
    await page.reload();
    await ensureDoubaoChatPage(page);
    await sendDoubaoMessage(page, text);
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: Doubao editor sanitizes/transforms input (e.g. markdown, emoji normalization); newlines collapsed; composer focused but keystrokes dropped; contenteditable insertion blocked by site scripts.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/51d1da902d7425c7. Report an issue: GitHub.