{"record":{"id":"d6809ed05fdc32fe","repo":"CloakHQ/CloakBrowser","slug":"isolated-world-dom-evaluation-failed-for-viewpor","errorCode":null,"errorMessage":"Isolated-world DOM evaluation failed for \"<viewport>\"","messagePattern":"Isolated-world DOM evaluation failed for \"<viewport>\"","errorType":"exception","errorClass":"StealthEvaluationError","httpStatus":null,"severity":"error","filePath":"js/src/human/scroll.ts","lineNumber":92,"sourceCode":"  }\n}\n\nexport async function humanScrollIntoView<T extends ElementBounds>(\n  page: Page,\n  raw: RawMouse,\n  getBox: () => Promise<T | null>,\n  cursorX: number,\n  cursorY: number,\n  cfg: HumanConfig,\n): Promise<{ box: T; cursorX: number; cursorY: number; didScroll: boolean }> {\n  let viewport = page.viewportSize();\n  if (!viewport) {\n    const world = getWorld(page);\n    if (!world) throw new StealthWorldUnavailableError();\n    try {\n      viewport = await world.evaluate(VIEWPORT_JS);\n    } catch {\n      throw new StealthEvaluationError('<viewport>');\n    }\n  }\n  if (!viewport || !viewport.height) throw new Error('Viewport size not available');\n\n  let box = await getBox();\n  if (!box) throw new Error('Element not found while scrolling into view');\n\n  if (isInViewport(box, viewport.height, cfg)) {\n    return { box, cursorX, cursorY, didScroll: false };\n  }\n\n  const fullyVisible = box.y >= 0 && box.y + box.height <= viewport.height;\n  if (fullyVisible) {\n    const zoneMid = viewport.height * (cfg.scroll_target_zone[0] + cfg.scroll_target_zone[1]) / 2;\n    const needUp = box.y + box.height / 2 < zoneMid;\n    const { y, maxY } = await readScrollState(page);\n    if (needUp ? y <= 0 : y >= maxY) {\n      return { box, cursorX, cursorY, didScroll: false };","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/CloakHQ/CloakBrowser/blob/d6bad5de261bedf025280ace1d14e800aee13923/js/src/human/scroll.ts#L74-L110","documentation":"When page.viewportSize() is unavailable, humanScrollIntoView evaluates VIEWPORT_JS inside the isolated world to get {width,height}. If that evaluate call throws (context destroyed, navigation, world teardown), the error is normalized to StealthEvaluationError('<viewport>'). The viewport probe itself failed, not the element lookup.","triggerScenarios":"page.viewportSize() === null AND world.evaluate(VIEWPORT_JS) rejects — typically a headful page that navigates/reloads at the moment of the humanized action, or an isolated world whose execution context was invalidated.","commonSituations":"Headful runs on SPAs that navigate during clicks; humanized clicks fired immediately after page.goto before load completes; concurrent actions tearing down the world; flaky CDP connectivity in grid/docker setups.","solutions":["Set an explicit context viewport (newContext({ viewport: {...} })) so the world-based viewport probe is skipped entirely.","Await a stable state (waitForLoadState / element visible) before the humanized action.","Retry the action once the page settles if it occasionally races navigation.","Ensure the page isn't being closed/navigated by other code while the action runs."],"exampleFix":"// before\nconst context = await browser.newContext(); // headful, no viewport\nawait humanClick(page, 'text=Buy');\n\n// after\nconst context = await browser.newContext({ viewport: { width: 1366, height: 768 } });\nawait humanClick(page, 'text=Buy');","handlingStrategy":"retry","validationCode":"if (!page.viewportSize()) await page.waitForLoadState('domcontentloaded');\nawait scrollToElement(page, raw, selector);\n// strongest prevention: newContext({ viewport: { width: 1280, height: 720 } })","typeGuard":"null","tryCatchPattern":"try {\n  await humanClick(page, selector);\n} catch (e) {\n  if (e instanceof StealthEvaluationError && e.message.includes('<viewport>')) {\n    await page.waitForLoadState('load');\n    await humanClick(page, selector);\n  } else throw e;\n}","preventionTips":["Set an explicit viewport on every context to bypass the world probe.","Avoid actions that coincide with redirects/reloads.","Keep one owner for page interactions; don't close/navigate concurrently."],"tags":["playwright","viewport","race-condition","navigation","isolated-world"],"backgroundTag":"page-evaluation-failed","analyzedSha":"d6bad5de261bedf025280ace1d14e800aee13923","analyzedAt":"2026-08-28T14:13:12.918Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}