{"record":{"id":"9db9fb5f5b8d995a","repo":"CloakHQ/CloakBrowser","slug":"element-selector-failed-attached-check-element","errorCode":null,"errorMessage":"Element ${selector} failed attached check: element not found in DOM","messagePattern":"Element (.+?) failed attached check: element not found in DOM","errorType":"exception","errorClass":"ElementNotAttachedError","httpStatus":null,"severity":"error","filePath":"js/src/human/actionability.ts","lineNumber":117,"sourceCode":"  return new Promise(resolve => setTimeout(resolve, BACKOFF_MS[idx]));\n}\n\n// ---------------------------------------------------------------------------\n// Pre-scroll actionability\n// ---------------------------------------------------------------------------\n\nasync function stealthActionable(\n  pageOrFrame: Page | Frame,\n  selector: string,\n  checks: ReadonlySet<CheckName>,\n): Promise<void> {\n  const world = getWorld(pageOrFrame);\n  if (!world) throw new StealthWorldUnavailableError();\n\n  const { status, data } = await evalParsed(world, buildActionableJs(selector));\n  if (status === UNSUPPORTED) throw new UnsupportedHumanizeSelectorError(selector);\n  if (status === EVALUATION_FAILED) throw new StealthEvaluationError(selector);\n  if (status === NOT_FOUND) throw new ElementNotAttachedError(selector);\n  if (status !== OK || !data) throw new StealthEvaluationError(selector);\n  if (checks.has('visible') && !data.visible) throw new ElementNotVisibleError(selector);\n  if (checks.has('enabled') && !data.enabled) throw new ElementNotEnabledError(selector);\n  if (checks.has('editable') && !data.editable) throw new ElementNotEditableError(selector);\n}\n\nasync function readBox(\n  pageOrFrame: Page | Frame,\n  selector: string,\n): Promise<{ x: number; y: number; width: number; height: number } | null> {\n  const world = getWorld(pageOrFrame);\n  if (!world) throw new StealthWorldUnavailableError();\n\n  const { status, data } = await evalParsed(world, buildBoxJs(selector));\n  if (status === OK && data?.box) return data.box;\n  if (status === NOT_FOUND) return null;\n  if (status === UNSUPPORTED) throw new UnsupportedHumanizeSelectorError(selector);\n  throw new StealthEvaluationError(selector);","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/CloakHQ/CloakBrowser/blob/d6bad5de261bedf025280ace1d14e800aee13923/js/src/human/actionability.ts#L99-L135","documentation":"The actionability probe resolved the selector in the isolated world and got status NOT_FOUND: no element matched the selector at check time. This is the humanized equivalent of Playwright's 'element not attached / not found' failure.","triggerScenarios":"ensureActionable with any check set (visible/enabled/editable) on a selector whose resolver returns NOT_FOUND — element removed from DOM, typo'd selector, or SPA re-render that swapped nodes between discovery and the probe.","commonSituations":"Selectors that break after re-renders (data-testid churn), acting before the element mounts, detached nodes after route change, or unsupported selector syntax silently resolving to nothing.","solutions":["Wait for the element to exist before the action (waitForSelector / expect(locator).toBeAttached())","Make the selector resilient: prefer stable data-testid or text= selectors over generated CSS paths","If the element genuinely may be absent, catch ElementNotAttachedError and treat it as an expected branch","Verify you are querying the right frame (iframe content needs the Frame object, not the parent Page)"],"exampleFix":"// before\nawait humanClick(page, '#row-42 .btn');\n// after\nawait page.waitForSelector('[data-testid=\"submit\"]');\nawait humanClick(page, '[data-testid=\"submit\"]');","handlingStrategy":"validation","validationCode":"if ((await page.locator(sel).count()) === 0) await page.waitForSelector(sel, { timeout: 5000 });","typeGuard":"function isElementNotAttachedError(e: unknown): e is ElementNotAttachedError {\n  return e instanceof Error && /failed attached check/.test(e.message);\n}","tryCatchPattern":"try { await humanClick(page, sel); } catch (e) { if (isElementNotAttachedError(e)) return; /* optional flow */ throw e; }","preventionTips":["Always waitForSelector before humanized actions","Prefer stable data-testid selectors","Scope selectors to the correct frame"],"tags":["element-not-found","dom","actionability","selector"],"backgroundTag":"element-not-found","analyzedSha":"d6bad5de261bedf025280ace1d14e800aee13923","analyzedAt":"2026-08-28T14:13:12.918Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}