{"record":{"id":"275187c5fe987fdf","repo":"jackwener/OpenCLI","slug":"selector","errorCode":"SELECTOR","errorMessage":"Could not find element: Trae CN new task button","messagePattern":"Could not find element: Trae CN new task button","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/new.js","lineNumber":23,"sourceCode":"export const newCommand = cli({\n  site: 'trae-cn',\n  name: 'new',\n  access: 'write',\n  description: 'Start a new Trae CN task in the current workspace, optionally sending the first prompt',\n  example: 'OPENCLI_CDP_ENDPOINT=http://127.0.0.1:39240 OPENCLI_CDP_TARGET=talk opencli trae-cn new \"请执行你的任务\" -f json',\n  domain: 'localhost',\n  strategy: Strategy.UI,\n  browser: true,\n  args: [\n    { name: 'prompt', required: false, positional: true, help: 'Optional first prompt to send after creating the task' },\n    { name: 'timeout', type: 'int', required: false, help: 'Max seconds to wait for a fresh task composer (default: 10)', default: 10 },\n  ],\n  columns: ['Status', 'Action', 'Workspace', 'Model', 'Agent', 'FreshTaskConfirmed', 'TurnsBeforeSubmit', 'Turns', 'ComposerReady', 'SubmitMode'],\n  func: async (page, kwargs) => {\n    const timeout = normalizeTimeout(kwargs.timeout, 10);\n    const clicked = await page.evaluate(clickNewTaskScript());\n    if (!clicked?.ok) {\n      throw selectorError('Trae CN new task button');\n    }\n\n    const started = Date.now();\n    let state = null;\n    while (Date.now() - started < timeout * 1000) {\n      await page.wait(0.5);\n      state = await page.evaluate(currentTaskStateScript());\n      if (state?.composerReady && state.turns === 0) break;\n    }\n\n    if (!state?.composerReady || state.turns !== 0) {\n      throw new CommandExecutionError(\n        `Clicked Trae CN new task via ${clicked.method}; fresh empty composer was not confirmed`,\n        `Observed composerReady=${state?.composerReady ? 'yes' : 'no'}, turns=${state?.turns ?? 'unavailable'}. Verify the current window is a Trae CN chat workspace and retry.`,\n      );\n    }\n\n    const turnsBeforeSubmit = state.turns;","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/new.js#L5-L41","documentation":"A SELECTOR CliError (src/errors.ts:160) thrown by `trae-cn new` when the in-page clickNewTaskScript() cannot find the 'New Task' button in the Trae CN IDE's webview UI. The library throws it rather than clicking blindly, since the rest of the new-task workflow depends on this button.","triggerScenarios":"`trae-cn new` runs page.evaluate(clickNewTaskScript()) and the script returns clicked.ok falsy — the new-task button selector matched nothing in the current Trae CN UI (wrong panel open, UI updated, or IDE not on the expected screen).","commonSituations":"Trae CN version update changed DOM classes/structure; the sidebar or agent panel is collapsed/hidden; the user is on a screen where the new-task button does not exist (e.g. welcome screen); language/locale variant renders different markup.","solutions":["Update Trae CN automation selectors (clickNewTaskScript) to match the current IDE DOM — the hint says the page UI may have changed","Ensure the Trae CN window is showing the chat/agent panel where the new-task button is visible before running the command","Downgrade or align to a Trae CN version known to work with these selectors, or pin the IDE version","Report the issue upstream (per the error hint) with the Trae CN version and a DOM snapshot"],"exampleFix":"// before\nconst clicked = await page.evaluate(clickNewTaskScript());\nif (!clicked?.ok) throw selectorError('Trae CN new task button');\n// after\nconst clicked = await page.evaluate(clickNewTaskScript());\nif (!clicked?.ok) {\n  await openSidebarPanel(page, 'chat'); // make sure panel is visible\n  const retried = await page.evaluate(clickNewTaskScript());\n  if (!retried?.ok) throw selectorError('Trae CN new task button');\n}","handlingStrategy":"retry","validationCode":"const btn = await page.evaluate(() => {\n  const el = document.querySelector('[class*=new-task], [aria-label*=new task i], [title*=新建 i]');\n  return !!el && el.getBoundingClientRect().width > 0;\n});\nif (!btn) throw new Error('New-task button not visible — open the chat panel first');","typeGuard":"function isNewTaskClicked(r) { return !!r && r.ok === true; }","tryCatchPattern":"let clicked = await page.evaluate(clickNewTaskScript());\nfor (let i = 0; !isNewTaskClicked(clicked) && i < 3; i++) {\n  await page.wait(1);\n  clicked = await page.evaluate(clickNewTaskScript());\n}\nif (!isNewTaskClicked(clicked)) throw selectorError('Trae CN new task button');","preventionTips":["Open/verify the Trae CN chat panel before invoking new-task automation","Pin the Trae CN version in your environment to match maintained selectors","Re-check selectors after every Trae CN upgrade","Wait for webview load completion before running evaluate scripts"],"tags":["selector","ui-changed","trae-cn","browser-automation"],"backgroundTag":"selector-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}