From 8709f40fd677bbef23b32d9443d272b4cab277cd Mon Sep 17 00:00:00 2001 From: javis-bot Date: Wed, 10 Jun 2026 14:18:43 +0900 Subject: [PATCH] fix(stream-test): refuse final box when element stays off-screen bringIntoView returned the last boundingBox() unconditionally after the scroll loop exhausted, so an element still outside the viewport would be clicked anyway. Validate the final box against the actual viewport bounds on both axes (innerWidth/innerHeight) and return null otherwise, so humanClick fails instead of clicking an off-screen coordinate. --- bot/scripts/stream-test/human.mjs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot/scripts/stream-test/human.mjs b/bot/scripts/stream-test/human.mjs index 90b534a..9cc40bd 100644 --- a/bot/scripts/stream-test/human.mjs +++ b/bot/scripts/stream-test/human.mjs @@ -61,7 +61,7 @@ export async function humanClickXY(sx, sy) { // Bring an element into view using a REAL wheel scroll (not a DOM // scrollIntoView). Returns its viewport box, or null if it can't be revealed. async function bringIntoView(page, locator) { - const ih = await page.evaluate(() => window.innerHeight); + const { iw, ih } = await page.evaluate(() => ({ iw: window.innerWidth, ih: window.innerHeight })); for (let i = 0; i < 14; i++) { const box = await locator.boundingBox().catch(() => null); if (box && box.y >= 70 && box.y + box.height <= ih - 70) return box; @@ -69,7 +69,13 @@ async function bringIntoView(page, locator) { await xdo(['click', button]); await xdo(['click', button]); await xdo(['click', button]); await sleep(rand(120, 240)); } - return await locator.boundingBox().catch(() => null); + // Loop exhausted: only accept the final box if it actually lies inside the + // viewport on BOTH axes. Otherwise refuse, so the caller fails instead of + // clicking a coordinate that is still off-screen. + const box = await locator.boundingBox().catch(() => null); + if (!box) return null; + const onScreen = box.x >= 0 && box.y >= 0 && box.x + box.width <= iw && box.y + box.height <= ih; + return onScreen ? box : null; } // Locate a Playwright element, real-wheel it into view, move the real cursor