mirror of
https://github.com/CloakHQ/CloakBrowser.git
synced 2026-06-23 11:41:46 +02:00
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:
@@ -1039,7 +1039,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
checked = False
|
checked = False
|
||||||
if not checked:
|
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:
|
def _human_uncheck(selector: str, **kwargs: Any) -> None:
|
||||||
force = kwargs.get("force", False)
|
force = kwargs.get("force", False)
|
||||||
@@ -1056,7 +1056,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
checked = True
|
checked = True
|
||||||
if checked:
|
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:
|
def _human_select_option(selector: str, value: Any = None, **kwargs: Any) -> Any:
|
||||||
force = kwargs.get("force", False)
|
force = kwargs.get("force", False)
|
||||||
@@ -1068,7 +1068,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
|
|
||||||
if not force:
|
if not force:
|
||||||
ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=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))
|
sleep_ms(rand(100, 300))
|
||||||
return originals.select_option(selector, value, **kwargs)
|
return originals.select_option(selector, value, **kwargs)
|
||||||
|
|
||||||
@@ -1083,7 +1083,7 @@ def patch_page(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
if not force:
|
if not force:
|
||||||
ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
|
ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
|
||||||
if not _is_selector_focused(page, selector):
|
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))
|
sleep_ms(rand(50, 150))
|
||||||
originals.keyboard_press(key)
|
originals.keyboard_press(key)
|
||||||
|
|
||||||
@@ -1938,7 +1938,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
checked = False
|
checked = False
|
||||||
if not checked:
|
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:
|
async def _human_uncheck(selector: str, **kwargs: Any) -> None:
|
||||||
force = kwargs.get("force", False)
|
force = kwargs.get("force", False)
|
||||||
@@ -1955,7 +1955,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
checked = True
|
checked = True
|
||||||
if checked:
|
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:
|
async def _human_press(selector: str, key: str, **kwargs: Any) -> None:
|
||||||
force = kwargs.get("force", False)
|
force = kwargs.get("force", False)
|
||||||
@@ -1968,7 +1968,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
if not force:
|
if not force:
|
||||||
await async_ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
|
await async_ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=force)
|
||||||
if not await _async_is_selector_focused(page, selector):
|
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 async_sleep_ms(rand(50, 150))
|
||||||
await originals.keyboard_press(key)
|
await originals.keyboard_press(key)
|
||||||
|
|
||||||
@@ -1982,7 +1982,7 @@ def patch_page_async(page: Any, cfg: HumanConfig, cursor: _CursorState) -> None:
|
|||||||
|
|
||||||
if not force:
|
if not force:
|
||||||
await async_ensure_actionable(page, selector, CHECKS_FOCUS, timeout=_remaining_ms(), force=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))
|
await async_sleep_ms(rand(100, 300))
|
||||||
return await originals.select_option(selector, value, **kwargs)
|
return await originals.select_option(selector, value, **kwargs)
|
||||||
|
|
||||||
|
|||||||
@@ -205,6 +205,15 @@ _POINTER_EVENTS_LOCATOR_JS = """(expected, coords) => {
|
|||||||
return { hit: false, reason: 'covered', covering: target.tagName || 'unknown' };
|
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(
|
def check_pointer_events(
|
||||||
page: Any,
|
page: Any,
|
||||||
@@ -313,18 +322,11 @@ def check_pointer_events_handle(
|
|||||||
deadline = time.monotonic() + timeout / 1000.0
|
deadline = time.monotonic() + timeout / 1000.0
|
||||||
attempt = 0
|
attempt = 0
|
||||||
|
|
||||||
js = f"""(expected) => {{
|
coords = {"x": x, "y": y}
|
||||||
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' }};
|
|
||||||
}}"""
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
result = el.evaluate(js)
|
result = el.evaluate(_POINTER_EVENTS_HANDLE_JS, coords)
|
||||||
except Exception:
|
except Exception:
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from .actionability import (
|
|||||||
_BACKOFF_MS,
|
_BACKOFF_MS,
|
||||||
_boxes_differ,
|
_boxes_differ,
|
||||||
_POINTER_EVENTS_LOCATOR_JS,
|
_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
|
deadline = time.monotonic() + timeout / 1000.0
|
||||||
attempt = 0
|
attempt = 0
|
||||||
|
|
||||||
js = f"""(expected) => {{
|
coords = {"x": x, "y": y}
|
||||||
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' }};
|
|
||||||
}}"""
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
result = await el.evaluate(js)
|
result = await el.evaluate(_POINTER_EVENTS_HANDLE_JS, coords)
|
||||||
except Exception:
|
except Exception:
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
|||||||
@@ -206,6 +206,15 @@ const POINTER_EVENTS_LOCATOR_JS = `(expected, coords) => {
|
|||||||
return { hit: false, reason: 'covered', covering: target.tagName || 'unknown' };
|
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(
|
export async function checkPointerEvents(
|
||||||
pageOrFrame: Page | Frame,
|
pageOrFrame: Page | Frame,
|
||||||
selector: string,
|
selector: string,
|
||||||
@@ -308,19 +317,12 @@ export async function checkPointerEventsHandle(
|
|||||||
const deadline = Date.now() + timeout;
|
const deadline = Date.now() + timeout;
|
||||||
let attempt = 0;
|
let attempt = 0;
|
||||||
|
|
||||||
const js = `(expected) => {
|
const coords = { x, y };
|
||||||
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' };
|
|
||||||
}`;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
let result: any;
|
let result: any;
|
||||||
try {
|
try {
|
||||||
result = await el.evaluate(js);
|
result = await el.evaluate(POINTER_EVENTS_HANDLE_JS, coords);
|
||||||
} catch {
|
} catch {
|
||||||
result = null;
|
result = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
|
|||||||
|
|
||||||
if (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
|
if (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
|
||||||
if (!await isSelectorFocused(stealth, page, selector)) {
|
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 sleep(rand(50, 150));
|
||||||
await originals.keyboardPress(SELECT_ALL);
|
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);
|
const checked = await originals.isChecked(selector).catch(() => false);
|
||||||
if (!checked) {
|
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);
|
const checked = await originals.isChecked(selector).catch(() => true);
|
||||||
if (checked) {
|
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());
|
const remainingMs = () => Math.max(0, deadline - Date.now());
|
||||||
|
|
||||||
if (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
|
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));
|
await sleep(rand(100, 300));
|
||||||
return originals.selectOption(selector, values, options);
|
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 (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
|
||||||
if (!await isSelectorFocused(stealth, page, selector)) {
|
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 sleep(rand(50, 150));
|
||||||
await originals.keyboardPress(key);
|
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 (!force) await ensureActionable(page, selector, CHECKS_FOCUS, remainingMs(), force);
|
||||||
if (!await isSelectorFocused(stealth, page, selector)) {
|
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));
|
await sleep(rand(100, 250));
|
||||||
const cdp = await ensureCdp();
|
const cdp = await ensureCdp();
|
||||||
|
|||||||
Reference in New Issue
Block a user