{"record":{"id":"74c14d7740450a49","repo":"can1357/oh-my-pi","slug":"tab-ariasnapshot-selector-sel-matched-no-ele","errorCode":null,"errorMessage":"tab.ariaSnapshot: selector ${__sel} matched no element","messagePattern":"tab\\.ariaSnapshot: selector (.+?) matched no element","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/browser/aria/aria-snapshot.ts","lineNumber":130,"sourceCode":"\t\t\treturn /^e\\d+$/.test(id) ? id : null;\n\t\t}\n\t}\n\tconst bare = /^@?(e\\d+)$/.exec(trimmed);\n\treturn bare ? bare[1]! : null;\n}\n\n/**\n * Build a self-contained expression script that runs the vendored bundle in the\n * page and returns the ARIA snapshot YAML. Used by the cmux backend, whose\n * `browser.eval` RPC takes a script string and returns the completion value (it\n * has no ElementHandle to pass in). The script resolves `selector` via\n * `document.querySelector` in-page (CSS selectors only) or falls back to the\n * whole document. Like the puppeteer path it installs nothing on `window`.\n */\nexport function buildAriaSnapshotScript(selector: string | undefined, options: AriaSnapshotOptions = {}): string {\n\tconst request = { depth: options.depth, boxes: options.boxes };\n\tconst sel = selector ? JSON.stringify(selector) : \"null\";\n\treturn `(function(){var module={exports:{}};\\n${ariaBundle}\\nvar __sel=${sel};var __root=__sel?document.querySelector(__sel):null;if(__sel&&!__root)throw new Error(\"tab.ariaSnapshot: selector \"+__sel+\" matched no element\");return module.exports.ariaSnapshot(__root,${JSON.stringify(request)});})()`;\n}\n","sourceCodeStart":112,"sourceCodeEnd":132,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/browser/aria/aria-snapshot.ts#L112-L132","documentation":"buildAriaSnapshotScript generates an in-page script for tab.ariaSnapshot. When a selector is provided, the script resolves it with document.querySelector (CSS only) and throws \"tab.ariaSnapshot: selector <sel> matched no element\" inside the page if nothing matches. The error surfaces through the tool as a ToolError/evaluation failure.","triggerScenarios":"Calling tab.ariaSnapshot({ selector: \"#foo\" }) when no element matching the CSS selector exists in the document at evaluation time; passing an aria-ref string (\"aria-ref=eN\") as the selector — querySelector only understands CSS.","commonSituations":"Typos in CSS selectors; element not yet rendered (page still loading or SPA not mounted); element inside a different frame/document; passing an aria-ref where a CSS selector is required.","solutions":["Verify the CSS selector matches in the current DOM (document.querySelector in console)","Wait for the element to render (waitFor selector or navigation settle) before snapshotting","Omit the selector to snapshot the whole document","Use the aria-ref handle path for element-scoped work instead of querySelector","Check for iframes — the selector runs in the main frame document only"],"exampleFix":"// before\nawait tab.ariaSnapshot({ selector: \"aria-ref=e5\" }); // querySelector fails\n// after\nawait tab.waitFor(\".results\");\nawait tab.ariaSnapshot({ selector: \".results\" });","handlingStrategy":"validation","validationCode":"const el = await tab.evaluate(`!!document.querySelector(${JSON.stringify(sel)})`);\nif (!el) throw new Error(`selector ${sel} not in DOM yet — wait first`);\nawait tab.ariaSnapshot({ selector: sel });","typeGuard":null,"tryCatchPattern":"try {\n  await tab.ariaSnapshot({ selector });\n} catch (e) {\n  if (e instanceof ToolError && e.message.includes(\"matched no element\")) {\n    await tab.waitFor(selector); // wait then retry\n    return await tab.ariaSnapshot({ selector });\n  }\n  throw e;\n}","preventionTips":["Test the CSS selector with document.querySelector before snapshotting","Use waitFor to ensure the element exists first","Remember the selector path is CSS-only — never pass aria-ref strings here","Omit the selector for whole-document snapshots"],"tags":["browser","dom","selector","css"],"backgroundTag":"selector-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}