{"record":{"id":"c87d22a443d3901e","repo":"jackwener/OpenCLI","slug":"selector-c87d22","errorCode":"SELECTOR","errorMessage":"Could not find element: Trae CN chat input","messagePattern":"Could not find element: Trae CN chat input","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/utils.js","lineNumber":682,"sourceCode":"      const last = rows[rows.length - 1];\n      return last && last.Role === 'Assistant' ? last : null;\n    })()\n  `;\n}\n\nexport async function readTraeMessages(page, limit = 20, maxChars = 0) {\n  const messages = await page.evaluate(readMessagesScript(limit, maxChars));\n  if (!messages || messages.length === 0) {\n    throw new EmptyResultError('trae-cn read', 'No conversation history found in Trae CN.');\n  }\n  return messages;\n}\n\nexport async function sendTraePrompt(page, text) {\n  const prompt = ensurePrompt(text);\n  const beforeCount = await page.evaluate(countTurnsScript());\n  const injected = await page.evaluate(injectPromptScript(prompt));\n  if (!injected?.ok) throw selectorError('Trae CN chat input');\n  await page.wait(0.3);\n  const submitted = await page.evaluate(submitPromptScript());\n  let mode = submitted?.mode || 'unknown';\n  if (!submitted?.ok) {\n    if (submitted?.reason === 'send_button_disabled' && typeof page.pressKey === 'function') {\n      await page.pressKey('Enter');\n      await page.wait(0.8);\n      mode = 'keyboard';\n    } else {\n      throw selectorError('Trae CN send button');\n    }\n  } else {\n    await page.wait(0.8);\n  }\n  const deadline = Date.now() + 2500;\n  while (Date.now() < deadline) {\n    if (await page.evaluate(submittedPromptScript(beforeCount, prompt))) {\n      return { prompt, mode };","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/utils.js#L664-L700","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Update the composer selector inside injectPromptScript to match the current Trae CN DOM","Ensure the chat panel is open and the IDE finished loading before calling sendTraePrompt (add an explicit wait/retry on the composer selector)","Dismiss any blocking dialogs (update prompts, onboarding) in the Trae CN window first","Pin/align the Trae CN version with the selectors and report the mismatch upstream if it persists"],"exampleFix":"// before\nconst injected = await page.evaluate(injectPromptScript(prompt));\nif (!injected?.ok) throw selectorError('Trae CN chat input');\n// after\nlet injected = await page.evaluate(injectPromptScript(prompt));\nfor (let i = 0; !injected?.ok && i < 5; i++) {\n  await page.wait(1); // let webview finish loading\n  injected = await page.evaluate(injectPromptScript(prompt));\n}\nif (!injected?.ok) throw selectorError('Trae CN chat input');","handlingStrategy":"retry","validationCode":"const composerReady = await page.evaluate(() => {\n  const el = document.querySelector('textarea, [contenteditable=true], [class*=composer], [class*=input]');\n  return !!el && !el.disabled && el.getBoundingClientRect().width > 0;\n});\nif (!composerReady) throw new Error('Trae CN composer not ready — open chat panel and wait for load');","typeGuard":"function isInjected(r) { return !!r && r.ok === true; }","tryCatchPattern":"let injected = await page.evaluate(injectPromptScript(prompt));\nif (!isInjected(injected)) {\n  await page.wait(1);\n  injected = await page.evaluate(injectPromptScript(prompt));\n}\nif (!isInjected(injected)) throw selectorError('Trae CN chat input');","preventionTips":["Ensure the chat panel is open and the IDE finished loading before sending","Dismiss modal dialogs (updates, onboarding) that hide the composer","Re-verify composer selectors after Trae CN updates","Use text/attr-stable selectors instead of hashed CSS-module classes where possible"],"tags":["selector","ui-changed","trae-cn","composer"],"backgroundTag":"selector-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}