fiptcha 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -160,6 +160,9 @@ async function solveImageGrid(page, { captchaType, deadline, waitForToken, logs
|
|
|
160
160
|
const count = await cells.count();
|
|
161
161
|
if (![9, 16].includes(count)) throw new Error(`Unsupported ${captchaType} grid size (${count} cells)`);
|
|
162
162
|
const selected = await classifyGrid(frame, adapter, cells, prompt, seenTiles);
|
|
163
|
+
// Grid cells live inside a provider iframe. Let Playwright target the
|
|
164
|
+
// element in that frame instead of sending a page-level mouse click:
|
|
165
|
+
// the latter can miss the cell when iframe coordinates change.
|
|
163
166
|
for (const index of selected) await cells.nth(index).click({ timeout: 2000 });
|
|
164
167
|
totalSelections += selected.length;
|
|
165
168
|
if (!selected.length) break;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { captchaModelManager } = require('./captcha-model-manager');
|
|
2
2
|
const { solveImageGrid, PROVIDERS } = require('./captcha-grid-solver');
|
|
3
|
+
const { clickVisibleTarget } = require('./captcha-pointer');
|
|
3
4
|
|
|
4
5
|
const TOKEN_SELECTORS = Object.freeze({
|
|
5
6
|
recaptcha_v2: ['#g-recaptcha-response', 'textarea[name="g-recaptcha-response"]'],
|
|
@@ -95,8 +96,7 @@ async function clickCheckbox(page, captchaType, timeout = 10_000) {
|
|
|
95
96
|
}).catch(() => true);
|
|
96
97
|
if (!pointerReady) continue;
|
|
97
98
|
|
|
98
|
-
const
|
|
99
|
-
const clicked = await checkbox.click({ timeout: clickTimeout }).then(() => true, () => false);
|
|
99
|
+
const clicked = await clickVisibleTarget(page, checkbox).catch(() => false);
|
|
100
100
|
if (clicked) return true;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
async function viewportSize(page) {
|
|
2
|
+
const configured = page.viewportSize?.();
|
|
3
|
+
if (configured?.width && configured?.height) return configured;
|
|
4
|
+
return page.evaluate(() => ({ width: window.innerWidth, height: window.innerHeight })).catch(() => null);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isInsideViewport(box, viewport) {
|
|
8
|
+
if (!box || !viewport) return false;
|
|
9
|
+
const x = box.x + (box.width / 2);
|
|
10
|
+
const y = box.y + (box.height / 2);
|
|
11
|
+
return Number.isFinite(x) && Number.isFinite(y)
|
|
12
|
+
&& x >= 0 && y >= 0 && x <= viewport.width && y <= viewport.height;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Dispatch a trusted pointer click without Playwright's scroll-into-view step.
|
|
17
|
+
* CAPTCHA widgets should already be visible to a human; scrolling the page to
|
|
18
|
+
* satisfy a locator can move or invalidate the challenge between tile clicks.
|
|
19
|
+
*/
|
|
20
|
+
async function clickVisibleTarget(page, locator) {
|
|
21
|
+
if (!page?.mouse?.click) return false;
|
|
22
|
+
const [box, viewport] = await Promise.all([
|
|
23
|
+
locator.boundingBox().catch(() => null),
|
|
24
|
+
viewportSize(page)
|
|
25
|
+
]);
|
|
26
|
+
if (!isInsideViewport(box, viewport)) return false;
|
|
27
|
+
await page.mouse.click(box.x + (box.width / 2), box.y + (box.height / 2));
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { clickVisibleTarget, isInsideViewport };
|