mirror of
https://github.com/CloakHQ/CloakBrowser.git
synced 2026-06-23 11:41:46 +02:00
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:
@@ -57,12 +57,12 @@ export async function smoothWheel(
|
||||
|
||||
/**
|
||||
* Poll ``page.$(selector)`` for up to ``timeout`` ms, returning the element's
|
||||
* bounding box when found. ``timeout`` defaults to 2000ms when not specified.
|
||||
* bounding box when found. ``timeout`` defaults to 30000ms when not specified.
|
||||
*/
|
||||
async function getElementBox(
|
||||
page: Page,
|
||||
selector: string,
|
||||
timeout: number = 2000,
|
||||
timeout: number = 30000,
|
||||
): Promise<ElementBounds | null> {
|
||||
const start = Date.now();
|
||||
const pollInterval = 100;
|
||||
@@ -97,11 +97,7 @@ export async function humanScrollIntoView(
|
||||
if (!viewport) throw new Error('Viewport size not available');
|
||||
|
||||
let box = await getBox();
|
||||
if (!box) {
|
||||
await sleep(200);
|
||||
box = await getBox();
|
||||
if (!box) throw new Error('Element not found while scrolling into view');
|
||||
}
|
||||
if (!box) throw new Error('Element not found while scrolling into view');
|
||||
|
||||
if (isInViewport(box, viewport.height, cfg)) {
|
||||
return { box, cursorX, cursorY };
|
||||
@@ -188,7 +184,7 @@ export async function humanScrollIntoView(
|
||||
*
|
||||
* ``timeout`` controls how long we poll ``page.$(selector)`` before giving up,
|
||||
* so callers like ``page.click('#x', { timeout: 5000 })`` can wait longer for
|
||||
* slow-loading elements (#172). Default stays 2000ms when not specified.
|
||||
* slow-loading elements (#172). Default matches Playwright's 30000ms when not specified.
|
||||
*/
|
||||
export async function scrollToElement(
|
||||
page: Page,
|
||||
|
||||
@@ -57,11 +57,7 @@ export async function humanScrollIntoView(
|
||||
if (!viewport) throw new Error('Viewport size not available');
|
||||
|
||||
let box = await getBox();
|
||||
if (!box) {
|
||||
await sleep(200);
|
||||
box = await getBox();
|
||||
if (!box) throw new Error('Element not found while scrolling into view');
|
||||
}
|
||||
if (!box) throw new Error('Element not found while scrolling into view');
|
||||
|
||||
if (isInViewport(box, viewport.height, cfg)) {
|
||||
return { box, cursorX, cursorY };
|
||||
@@ -151,7 +147,7 @@ export async function humanScrollIntoView(
|
||||
*
|
||||
* ``timeout`` is forwarded to Playwright's ``boundingBox({ timeout })`` so
|
||||
* callers like ``page.click('#x', { timeout: 5000 })`` can wait longer for
|
||||
* slow-loading elements (#172). Default stays 2000ms when not specified.
|
||||
* slow-loading elements (#172). Default matches Playwright's 30000ms when not specified.
|
||||
*/
|
||||
export async function scrollToElement(
|
||||
page: Page,
|
||||
@@ -172,7 +168,7 @@ export async function scrollToElement(
|
||||
async function getElementBox(
|
||||
page: Page,
|
||||
selector: string,
|
||||
timeout: number = 2000,
|
||||
timeout: number = 30000,
|
||||
): Promise<ElementBounds | null> {
|
||||
const el = page.locator(selector).first();
|
||||
try {
|
||||
|
||||
@@ -1108,7 +1108,7 @@ describe("page.click(selector, { timeout }) forwards timeout to scroll", () => {
|
||||
expect(boundingBox).toHaveBeenCalledWith({ timeout: 5000 });
|
||||
});
|
||||
|
||||
it("default timeout stays 2000ms when not specified", async () => {
|
||||
it("default timeout matches Playwright's 30000ms when not specified", async () => {
|
||||
const { scrollToElement } = await import("../src/human/scroll.js");
|
||||
const cfg = resolveConfig("default");
|
||||
|
||||
@@ -1125,7 +1125,7 @@ describe("page.click(selector, { timeout }) forwards timeout to scroll", () => {
|
||||
};
|
||||
|
||||
await scrollToElement(page, raw, "#x", 0, 0, cfg);
|
||||
expect(boundingBox).toHaveBeenCalledWith({ timeout: 2000 });
|
||||
expect(boundingBox).toHaveBeenCalledWith({ timeout: 30000 });
|
||||
});
|
||||
|
||||
it("page.click({ timeout }) reaches scrollToElement", async () => {
|
||||
|
||||
@@ -1671,11 +1671,13 @@ describe("Puppeteer: isInputElement stealth integration via patchPage", () => {
|
||||
}),
|
||||
});
|
||||
|
||||
const mockEl = buildMockElementHandle();
|
||||
const page = buildMockPage({
|
||||
evaluate: vi.fn(async (...args: any[]) => {
|
||||
evaluateCalls.push(args);
|
||||
return false;
|
||||
}),
|
||||
$: vi.fn(async () => mockEl),
|
||||
});
|
||||
page.createCDPSession = vi.fn(async () => mockCdp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user