fix(humanize): forward human_config in all chained methods, use evaluate args in handle pointer checks

- Add human_config=kwargs.get("human_config") to check/uncheck/select_option/press inner calls (sync+async+JS)
- Convert check_pointer_events_handle from f-string interpolation to evaluate args pattern (sync+async+JS)
This commit is contained in:
CloakHQ
2026-05-15 19:17:11 +02:00
parent 39f807f246
commit f4f6a3f8fd
5 changed files with 39 additions and 41 deletions
+8 -8
View File
@@ -1039,7 +1039,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
except Exception:
checked = False
if not checked:
_human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
_human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
def _human_uncheck(selector: str, **kwargs: Any) -> None:
force = kwargs.get("force", False)
@@ -1056,7 +1056,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
except Exception:
checked = True
if checked:
_human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
_human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
def _human_select_option(selector: str, value: Any = None, **kwargs: Any) -> Any:
force = kwargs.get("force", False)
@@ -1068,7 +1068,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
if not force:
ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
_human_hover(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
_human_hover(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
sleep_ms(rand(100, 300))
return originals.select_option(selector, value, **kwargs)
@@ -1083,7 +1083,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
if not force:
ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
if not _is_selector_focused(page, selector):
_human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
_human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
sleep_ms(rand(50, 150))
originals.keyboard_press(key)
@@ -1938,7 +1938,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
except Exception:
checked = False
if not checked:
await _human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
await _human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
async def _human_uncheck(selector: str, **kwargs: Any) -> None:
force = kwargs.get("force", False)
@@ -1955,7 +1955,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
except Exception:
checked = True
if checked:
await _human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
await _human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
async def _human_press(selector: str, key: str, **kwargs: Any) -> None:
force = kwargs.get("force", False)
@@ -1968,7 +1968,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
if not force:
await async_ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
if not await _async_is_selector_focused(page, selector):
await _human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
await _human_click(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
await async_sleep_ms(rand(50, 150))
await originals.keyboard_press(key)
@@ -1982,7 +1982,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
if not force:
await async_ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
await _human_hover(selector, _skip_checks=True, timeout=_remaining_ms(), force=force)
await _human_hover(selector, _skip_checks=True, timeout=_remaining_ms(), force=force, human_config=kwargs.get("human_config"))
await async_sleep_ms(rand(100, 300))
return await originals.select_option(selector, value, **kwargs)
+11 -9
View File
@@ -205,6 +205,15 @@ _POINTER_EVENTS_LOCATOR_JS = """(expected, coords) => {
return { hit: false, reason: 'covered', covering: target.tagName || 'unknown' };
}"""
_POINTER_EVENTS_HANDLE_JS = """(expected, coords) => {
const target = document.elementFromPoint(coords.x, coords.y);
if (!target) return { hit: false, reason: 'no_element_at_point', covering: 'none' };
let node = target;
while (node) { if (node === expected) return { hit: true }; node = node.parentNode; }
if (expected.contains(target)) return { hit: true };
return { hit: false, reason: 'covered', covering: target.tagName || 'unknown' };
}"""
def check_pointer_events(
page: Any,
@@ -313,18 +322,11 @@ def check_pointer_events_handle(
deadline = time.monotonic() + timeout / 1000.0
attempt = 0
js = f"""(expected) => {{
const target = document.elementFromPoint({x}, {y});
if (!target) return {{ hit: false, reason: 'no_element_at_point', covering: 'none' }};
let node = target;
while (node) {{ if (node === expected) return {{ hit: true }}; node = node.parentNode; }}
if (expected.contains(target)) return {{ hit: true }};
return {{ hit: false, reason: 'covered', covering: target.tagName || 'unknown' }};
}}"""
coords = {"x": x, "y": y}
while True:
try:
result = el.evaluate(js)
result = el.evaluate(_POINTER_EVENTS_HANDLE_JS, coords)
except Exception:
result = None
+3 -9
View File
@@ -23,6 +23,7 @@ from .actionability import (
_BACKOFF_MS,
_boxes_differ,
_POINTER_EVENTS_LOCATOR_JS,
_POINTER_EVENTS_HANDLE_JS,
)
@@ -226,18 +227,11 @@ async def async_check_pointer_events_handle(
deadline = time.monotonic() + timeout / 1000.0
attempt = 0
js = f"""(expected) => {{
const target = document.elementFromPoint({x}, {y});
if (!target) return {{ hit: false, reason: 'no_element_at_point', covering: 'none' }};
let node = target;
while (node) {{ if (node === expected) return {{ hit: true }}; node = node.parentNode; }}
if (expected.contains(target)) return {{ hit: true }};
return {{ hit: false, reason: 'covered', covering: target.tagName || 'unknown' }};
}}"""
coords = {"x": x, "y": y}
while True:
try:
result = await el.evaluate(js)
result = await el.evaluate(_POINTER_EVENTS_HANDLE_JS, coords)
except Exception:
result = None
+11 -9
View File
@@ -206,6 +206,15 @@ const POINTER_EVENTS_LOCATOR_JS = `(expected, coords) => {
return { hit: false, reason: 'covered', covering: target.tagName || 'unknown' };
}`;
const POINTER_EVENTS_HANDLE_JS = `(expected, coords) => {
const target = document.elementFromPoint(coords.x, coords.y);
if (!target) return { hit: false, reason: 'no_element_at_point', covering: 'none' };
let node = target;
while (node) { if (node === expected) return { hit: true }; node = node.parentNode; }
if (expected.contains(target)) return { hit: true };
return { hit: false, reason: 'covered', covering: target.tagName || 'unknown' };
}`;
export async function checkPointerEvents(
pageOrFrame: Page | Frame,
selector: string,
@@ -308,19 +317,12 @@ export async function checkPointerEventsHandle(
const deadline = Date.now() + timeout;
let attempt = 0;
const js = `(expected) => {
const target = document.elementFromPoint(${x}, ${y});
if (!target) return { hit: false, reason: 'no_element_at_point', covering: 'none' };
let node = target;
while (node) { if (node === expected) return { hit: true }; node = node.parentNode; }
if (expected.contains(target)) return { hit: true };
return { hit: false, reason: 'covered', covering: target.tagName || 'unknown' };
}`;
const coords = { x, y };
while (true) {
let result: any;
try {
result = await el.evaluate(js);
result = await el.evaluate(POINTER_EVENTS_HANDLE_JS, coords);
} catch {
result = null;
}
+6 -6
View File
@@ -456,7 +456,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
if (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
if (!await isSelectorFocused(stealth, page, selector)) {
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force } as any);
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force, human_config: options?.human_config } as any);
}
await sleep(rand(50, 150));
await originals.keyboardPress(SELECT_ALL);
@@ -478,7 +478,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
}
const checked = await originals.isChecked(selector).catch(() => false);
if (!checked) {
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force } as any);
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force, human_config: options?.human_config } as any);
}
};
@@ -496,7 +496,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
}
const checked = await originals.isChecked(selector).catch(() => true);
if (checked) {
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force } as any);
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force, human_config: options?.human_config } as any);
}
};
@@ -508,7 +508,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
const remainingMs = () => Math.max(0, deadline - Date.now());
if (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
await humanHoverFn(selector, { _skipChecks: true, timeout: remainingMs(), force } as any);
await humanHoverFn(selector, { _skipChecks: true, timeout: remainingMs(), force, human_config: options?.human_config } as any);
await sleep(rand(100, 300));
return originals.selectOption(selector, values, options);
};
@@ -522,7 +522,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
if (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
if (!await isSelectorFocused(stealth, page, selector)) {
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force } as any);
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force, human_config: options?.human_config } as any);
}
await sleep(rand(50, 150));
await originals.keyboardPress(key);
@@ -538,7 +538,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
if (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
if (!await isSelectorFocused(stealth, page, selector)) {
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force } as any);
await humanClickFn(selector, { _skipChecks: true, timeout: remainingMs(), force, human_config: options?.human_config } as any);
}
await sleep(rand(100, 250));
const cdp = await ensureCdp();