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:
@@ -64,6 +64,13 @@ def human_scroll_into_view(
|
||||
"""
|
||||
viewport = page.viewport_size
|
||||
if not viewport:
|
||||
# Headed launches default to no_viewport so the page tracks the real OS
|
||||
# window; page.viewport_size is then None. Fall back to the live window
|
||||
# dimensions so humanize works headed (the stealth-relevant mode).
|
||||
viewport = page.evaluate(
|
||||
"() => ({ width: window.innerWidth, height: window.innerHeight })"
|
||||
)
|
||||
if not viewport or not viewport.get("height"):
|
||||
raise RuntimeError("Viewport size not available")
|
||||
|
||||
viewport_height = viewport["height"]
|
||||
|
||||
@@ -60,6 +60,13 @@ async def async_human_scroll_into_view(
|
||||
"""
|
||||
viewport = page.viewport_size
|
||||
if not viewport:
|
||||
# Headed launches default to no_viewport so the page tracks the real OS
|
||||
# window; page.viewport_size is then None. Fall back to the live window
|
||||
# dimensions so humanize works headed (the stealth-relevant mode).
|
||||
viewport = await page.evaluate(
|
||||
"() => ({ width: window.innerWidth, height: window.innerHeight })"
|
||||
)
|
||||
if not viewport or not viewport.get("height"):
|
||||
raise RuntimeError("Viewport size not available")
|
||||
|
||||
viewport_height = viewport["height"]
|
||||
|
||||
Reference in New Issue
Block a user