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
+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();