{"record":{"id":"513d752fc9619461","repo":"CloakHQ/CloakBrowser","slug":"element-not-found-while-scrolling-into-view-513d75","errorCode":null,"errorMessage":"Element not found while scrolling into view","messagePattern":"Element not found while scrolling into view","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/CloakBrowser/Human/HumanScroll.cs","lineNumber":114,"sourceCode":"        Func<Task<BoundingBox?>> getBox,\n        double cursorX, double cursorY,\n        HumanConfig cfg)\n    {\n        var viewport = page.ViewportSize;\n        if (viewport == null)\n            // Headed launches default to no_viewport so the page tracks the real OS\n            // window; ViewportSize is then null. Fall back to the live window\n            // dimensions so humanize works headed (the stealth-relevant mode).\n            viewport = await page.GetLiveWindowSizeAsync().ConfigureAwait(false);\n        if (viewport == null || viewport.Value.Height == 0)\n            throw new InvalidOperationException(\"Viewport size not available\");\n\n        int viewportHeight = viewport.Value.Height;\n        int viewportWidth = viewport.Value.Width;\n\n        var box = await getBox().ConfigureAwait(false);\n        if (box == null)\n            throw new InvalidOperationException(\"Element not found while scrolling into view\");\n\n        if (IsInViewport(box.Value, viewportHeight, cfg))\n            return new ScrollResult(box.Value, cursorX, cursorY, false);\n\n        // Already fully visible but off-center, with the page pinned at the boundary\n        // in the needed direction: scrolling can't help, so don't waste the budget.\n        bool fullyVisible = box.Value.Y >= 0 && box.Value.Y + box.Value.Height <= viewportHeight;\n        if (fullyVisible)\n        {\n            double zoneMid = viewportHeight * (cfg.ScrollTargetZone.Min + cfg.ScrollTargetZone.Max) / 2;\n            bool needUp = box.Value.Y + box.Value.Height / 2 < zoneMid;\n            var scroll = await page.GetScrollStateAsync().ConfigureAwait(false);\n            if (scroll != null && (needUp ? scroll.Value.Y <= 0 : scroll.Value.Y >= scroll.Value.MaxY))\n                return new ScrollResult(box.Value, cursorX, cursorY, false);\n        }\n\n        // Move cursor into scroll area.\n        double scrollAreaX = Math.Round(viewportWidth * HumanRandom.Rand(0.3, 0.7));","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/CloakHQ/CloakBrowser/blob/d6bad5de261bedf025280ace1d14e800aee13923/dotnet/src/CloakBrowser/Human/HumanScroll.cs#L96-L132","documentation":"InvalidOperationException thrown when the element's bounding box (via the getBox delegate) returns null at the start of HumanScrollIntoViewAsync. The element to scroll to does not currently exist in the DOM.","triggerScenarios":"Calling humanized scroll APIs with a selector that matches no attached element, or where the element is detached between the caller's own wait and the internal getBox evaluation.","commonSituations":"Selector typos, elements removed by React/Vue re-renders, lists virtualized so the row isn't in the DOM yet, or scrolling immediately after a click that triggers navigation.","solutions":["Wait for the element (WaitForSelectorAsync, state Attached or Visible) before scrolling","Fix the selector; verify it matches with a quick query","For virtualized lists, scroll the container first so the row is rendered","Retry after navigation settles if a click just caused a page change"],"exampleFix":"// before\nawait page.HumanScrollIntoViewAsync(\"#footer\");\n\n// after\nawait page.WaitForSelectorAsync(\"#footer\");\nawait page.HumanScrollIntoViewAsync(\"#footer\");","handlingStrategy":"try-catch","validationCode":"await page.WaitForSelectorAsync(selector, new() { State = WaitForSelectorState.Attached });","typeGuard":null,"tryCatchPattern":"catch (InvalidOperationException e) when (e.Message.Contains(\"not found while scrolling\")) { await page.WaitForSelectorAsync(selector); retry once; }","preventionTips":["Wait for attachment before scroll-into-view","Use stable selectors that survive re-renders","For virtualized lists scroll the container first"],"tags":["humanize","scroll","element-not-found"],"backgroundTag":"element-not-found","analyzedSha":"d6bad5de261bedf025280ace1d14e800aee13923","analyzedAt":"2026-08-28T14:13:12.918Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}