jackwener/OpenCLI · error · CliError

SELECTOR

SELECTOR

Error message

Could not find element: Trae CN chat input

What it means

A SELECTOR CliError thrown by sendTraePrompt (clis/trae-cn/utils.js:682) when injectPromptScript(prompt) cannot locate the chat composer input in the Trae CN IDE webview. Without the composer, the prompt text cannot be injected, so the library aborts with 'Could not find element: Trae CN chat input'. Raised from public entry points askCommand/result.

Source

Thrown at clis/trae-cn/utils.js:682

      const last = rows[rows.length - 1];
      return last && last.Role === 'Assistant' ? last : null;
    })()
  `;
}

export async function readTraeMessages(page, limit = 20, maxChars = 0) {
  const messages = await page.evaluate(readMessagesScript(limit, maxChars));
  if (!messages || messages.length === 0) {
    throw new EmptyResultError('trae-cn read', 'No conversation history found in Trae CN.');
  }
  return messages;
}

export async function sendTraePrompt(page, text) {
  const prompt = ensurePrompt(text);
  const beforeCount = await page.evaluate(countTurnsScript());
  const injected = await page.evaluate(injectPromptScript(prompt));
  if (!injected?.ok) throw selectorError('Trae CN chat input');
  await page.wait(0.3);
  const submitted = await page.evaluate(submitPromptScript());
  let mode = submitted?.mode || 'unknown';
  if (!submitted?.ok) {
    if (submitted?.reason === 'send_button_disabled' && typeof page.pressKey === 'function') {
      await page.pressKey('Enter');
      await page.wait(0.8);
      mode = 'keyboard';
    } else {
      throw selectorError('Trae CN send button');
    }
  } else {
    await page.wait(0.8);
  }
  const deadline = Date.now() + 2500;
  while (Date.now() < deadline) {
    if (await page.evaluate(submittedPromptScript(beforeCount, prompt))) {
      return { prompt, mode };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Update the composer selector inside injectPromptScript to match the current Trae CN DOM
  2. Ensure the chat panel is open and the IDE finished loading before calling sendTraePrompt (add an explicit wait/retry on the composer selector)
  3. Dismiss any blocking dialogs (update prompts, onboarding) in the Trae CN window first
  4. Pin/align the Trae CN version with the selectors and report the mismatch upstream if it persists

Example fix

// before
const injected = await page.evaluate(injectPromptScript(prompt));
if (!injected?.ok) throw selectorError('Trae CN chat input');
// after
let injected = await page.evaluate(injectPromptScript(prompt));
for (let i = 0; !injected?.ok && i < 5; i++) {
  await page.wait(1); // let webview finish loading
  injected = await page.evaluate(injectPromptScript(prompt));
}
if (!injected?.ok) throw selectorError('Trae CN chat input');
Defensive patterns

Strategy: retry

Validate before calling

const composerReady = await page.evaluate(() => {
  const el = document.querySelector('textarea, [contenteditable=true], [class*=composer], [class*=input]');
  return !!el && !el.disabled && el.getBoundingClientRect().width > 0;
});
if (!composerReady) throw new Error('Trae CN composer not ready — open chat panel and wait for load');

Type guard

function isInjected(r) { return !!r && r.ok === true; }

Try / catch

let injected = await page.evaluate(injectPromptScript(prompt));
if (!isInjected(injected)) {
  await page.wait(1);
  injected = await page.evaluate(injectPromptScript(prompt));
}
if (!isInjected(injected)) throw selectorError('Trae CN chat input');

Prevention

When it happens

Trigger: Calling `trae-cn ask`/result which calls sendTraePrompt; page.evaluate(injectPromptScript(prompt)) returns injected.ok falsy because the composer textarea/input selector matched nothing (panel closed, UI changed, IDE busy or not loaded).

Common situations: Trae CN update renamed composer classes; chat panel not open or focused; page/webview still loading when the script ran; another modal (e.g. update dialog) covers the composer.

Related errors


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