mirror of
https://github.com/CloakHQ/CloakBrowser.git
synced 2026-06-23 11:41:46 +02:00
fix(humanize): fall back to window dims when viewport is null
Headed launches default to no_viewport, so page.viewport_size is None and human scroll raised "Viewport size not available". Fall back to live window.innerWidth/innerHeight. Covers Playwright (py sync/async, JS) and Puppeteer paths.
This commit is contained in:
+10
-2
@@ -53,8 +53,16 @@ export async function humanScrollIntoView(
|
||||
cursorY: number,
|
||||
cfg: HumanConfig,
|
||||
): Promise<{ box: ElementBounds; cursorX: number; cursorY: number; didScroll: boolean }> {
|
||||
const viewport = page.viewportSize();
|
||||
if (!viewport) throw new Error('Viewport size not available');
|
||||
// Headed launches default to no_viewport so the page tracks the real OS
|
||||
// window; page.viewportSize() is then null. Fall back to the live window
|
||||
// dimensions so humanize works headed (the stealth-relevant mode).
|
||||
let viewport = page.viewportSize();
|
||||
if (!viewport) {
|
||||
viewport = await page.evaluate(
|
||||
() => ({ width: window.innerWidth, height: window.innerHeight }),
|
||||
);
|
||||
}
|
||||
if (!viewport || !viewport.height) throw new Error('Viewport size not available');
|
||||
|
||||
let box = await getBox();
|
||||
if (!box) throw new Error('Element not found while scrolling into view');
|
||||
|
||||
Reference in New Issue
Block a user