fiptcha 0.1.2 → 0.1.3
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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { captchaModelManager, checksumBuffer } = require('./captcha-model-manager');
|
|
2
|
+
const { clickVisibleTarget } = require('./captcha-pointer');
|
|
2
3
|
|
|
3
4
|
const PROVIDERS = Object.freeze({
|
|
4
5
|
recaptcha_v2: Object.freeze({
|
|
@@ -160,13 +161,17 @@ async function solveImageGrid(page, { captchaType, deadline, waitForToken, logs
|
|
|
160
161
|
const count = await cells.count();
|
|
161
162
|
if (![9, 16].includes(count)) throw new Error(`Unsupported ${captchaType} grid size (${count} cells)`);
|
|
162
163
|
const selected = await classifyGrid(frame, adapter, cells, prompt, seenTiles);
|
|
163
|
-
for (const index of selected)
|
|
164
|
+
for (const index of selected) {
|
|
165
|
+
const clicked = await clickVisibleTarget(page, cells.nth(index));
|
|
166
|
+
if (!clicked) throw new Error(`${captchaType} grid tile was outside the viewport`);
|
|
167
|
+
}
|
|
164
168
|
totalSelections += selected.length;
|
|
165
169
|
if (!selected.length) break;
|
|
166
170
|
await page.waitForTimeout(600);
|
|
167
171
|
}
|
|
168
172
|
logs.push(`Local ${captchaType} grid round ${round + 1}: selected ${totalSelections} cells for "${prompt}"`);
|
|
169
|
-
await frame.locator(totalSelections ? adapter.submit : adapter.noMatch).first()
|
|
173
|
+
const submitted = await clickVisibleTarget(page, frame.locator(totalSelections ? adapter.submit : adapter.noMatch).first());
|
|
174
|
+
if (!submitted) throw new Error(`${captchaType} verification button was outside the viewport`);
|
|
170
175
|
const token = await waitForToken(page, captchaType, Math.min(2500, Math.max(0, deadline - Date.now())));
|
|
171
176
|
if (token) return token;
|
|
172
177
|
await page.waitForTimeout(350);
|
|
@@ -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 };
|