fix: align humanize timeout default with Playwright's 30s auto-retry (#172)

The humanize layer hardcoded timeout=2000ms for element lookups, causing
locator.click() and page.click() to fail instantly instead of retrying
for 30s like standard Playwright. Aligned all defaults to 30000ms across
Python sync/async, JS Playwright, and JS Puppeteer paths. Bumped the
outer retry sleep from 200ms to 500ms for DOM mutation settle time.
This commit is contained in:
CloakHQ
2026-05-01 20:48:06 +02:00
parent 2df8c7e2d1
commit f01902025a
8 changed files with 30 additions and 42 deletions
+8 -8
View File
@@ -421,7 +421,7 @@ def _patch_locator_class_sync():
native_kwargs = {k: v for k, v in kwargs.items() if k != "human_config"}
return _orig_scroll_into_view(self, **native_kwargs)
return
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
try:
_, nx, ny = human_scroll_into_view(
page, raw,
@@ -648,7 +648,7 @@ def _patch_locator_class_async():
native_kwargs = {k: v for k, v in kwargs.items() if k != "human_config"}
await _orig_scroll_into_view(self, **native_kwargs)
return
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
async def _get_box():
return await self.bounding_box(timeout=timeout)
@@ -868,7 +868,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
def _human_click(selector: str, **kwargs: Any) -> None:
_ensure_cursor_init()
call_cfg = merge_config(cfg, kwargs.get("human_config"))
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
if call_cfg.idle_between_actions:
human_idle(raw_mouse, rand(call_cfg.idle_between_duration[0], call_cfg.idle_between_duration[1]), cursor.x, cursor.y, call_cfg)
box, cx, cy = scroll_to_element(
@@ -886,7 +886,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
def _human_dblclick(selector: str, **kwargs: Any) -> None:
_ensure_cursor_init()
call_cfg = merge_config(cfg, kwargs.get("human_config"))
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
if call_cfg.idle_between_actions:
human_idle(raw_mouse, rand(call_cfg.idle_between_duration[0], call_cfg.idle_between_duration[1]), cursor.x, cursor.y, call_cfg)
box, cx, cy = scroll_to_element(
@@ -906,7 +906,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
def _human_hover(selector: str, **kwargs: Any) -> None:
_ensure_cursor_init()
call_cfg = merge_config(cfg, kwargs.get("human_config"))
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
if call_cfg.idle_between_actions:
human_idle(raw_mouse, rand(call_cfg.idle_between_duration[0], call_cfg.idle_between_duration[1]), cursor.x, cursor.y, call_cfg)
box, cx, cy = scroll_to_element(
@@ -1621,7 +1621,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
async def _human_click(selector: str, **kwargs: Any) -> None:
await _ensure_cursor_init()
call_cfg = merge_config(cfg, kwargs.get("human_config"))
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
if call_cfg.idle_between_actions:
await async_human_idle(raw_mouse, rand(call_cfg.idle_between_duration[0], call_cfg.idle_between_duration[1]), cursor.x, cursor.y, call_cfg)
box, cx, cy = await async_scroll_to_element(
@@ -1639,7 +1639,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
async def _human_dblclick(selector: str, **kwargs: Any) -> None:
await _ensure_cursor_init()
call_cfg = merge_config(cfg, kwargs.get("human_config"))
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
if call_cfg.idle_between_actions:
await async_human_idle(raw_mouse, rand(call_cfg.idle_between_duration[0], call_cfg.idle_between_duration[1]), cursor.x, cursor.y, call_cfg)
box, cx, cy = await async_scroll_to_element(
@@ -1659,7 +1659,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
async def _human_hover(selector: str, **kwargs: Any) -> None:
await _ensure_cursor_init()
call_cfg = merge_config(cfg, kwargs.get("human_config"))
timeout = kwargs.get("timeout", 2000)
timeout = kwargs.get("timeout", 30000)
if call_cfg.idle_between_actions:
await async_human_idle(raw_mouse, rand(call_cfg.idle_between_duration[0], call_cfg.idle_between_duration[1]), cursor.x, cursor.y, call_cfg)
box, cx, cy = await async_scroll_to_element(
+4 -7
View File
@@ -18,7 +18,7 @@ def _is_in_viewport(bounds: dict, viewport_height: int, cfg: HumanConfig) -> boo
return top_edge >= zone_top and bottom_edge <= zone_bottom
def _get_element_box(page: Any, selector: str, timeout: float = 2000) -> Optional[dict]:
def _get_element_box(page: Any, selector: str, timeout: float = 30000) -> Optional[dict]:
"""Locate ``selector`` and return its bounding box.
The ``timeout`` is forwarded to Playwright's ``boundingBox(timeout=...)``
@@ -68,10 +68,7 @@ def human_scroll_into_view(
box = get_box()
if box is None:
sleep_ms(200)
box = get_box()
if box is None:
raise RuntimeError("Element not found while scrolling into view")
raise RuntimeError("Element not found while scrolling into view")
if _is_in_viewport(box, viewport_height, cfg):
return box, cursor_x, cursor_y
@@ -151,13 +148,13 @@ def scroll_to_element(
selector: str,
cursor_x: float, cursor_y: float,
cfg: HumanConfig,
timeout: float = 2000,
timeout: float = 30000,
) -> Tuple[dict, float, float]:
"""Selector-based humanized scroll.
``timeout`` is forwarded to ``locator.bounding_box(timeout=...)`` so callers
such as ``page.click('#x', timeout=5000)`` can wait longer for slow elements
(#172). Default stays at 2000ms when not specified.
(#172). Default matches Playwright's 30000ms when not specified.
"""
return human_scroll_into_view(
page, raw,
+4 -7
View File
@@ -16,7 +16,7 @@ from .scroll import _is_in_viewport
async def _get_element_box_async(
page: Any, selector: str, timeout: float = 2000,
page: Any, selector: str, timeout: float = 30000,
) -> Optional[dict]:
"""Async variant. ``timeout`` is forwarded to Playwright's
``boundingBox(timeout=...)`` so callers can extend it for slow-loading
@@ -64,10 +64,7 @@ async def async_human_scroll_into_view(
box = await get_box()
if box is None:
await async_sleep_ms(200)
box = await get_box()
if box is None:
raise RuntimeError("Element not found while scrolling into view")
raise RuntimeError("Element not found while scrolling into view")
if _is_in_viewport(box, viewport_height, cfg):
return box, cursor_x, cursor_y
@@ -147,13 +144,13 @@ async def async_scroll_to_element(
selector: str,
cursor_x: float, cursor_y: float,
cfg: HumanConfig,
timeout: float = 2000,
timeout: float = 30000,
) -> Tuple[dict, float, float]:
"""Selector-based humanized scroll (async).
``timeout`` is forwarded to ``locator.bounding_box(timeout=...)`` so callers
such as ``page.click('#x', timeout=5000)`` can wait longer for slow elements
(#172). Default stays at 2000ms when not specified.
(#172). Default matches Playwright's 30000ms when not specified.
"""
async def _get():
return await _get_element_box_async(page, selector, timeout)