Skip to content

Commit b88c013

Browse files
committed
Turnstile click error resolved.
1 parent 80206e9 commit b88c013

File tree

4 files changed

+43
-34
lines changed

4 files changed

+43
-34
lines changed

lib/cjs/module/turnstile.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,33 @@ const checkTurnstile = ({ page }) => {
44

55
try {
66
const elements = await page.$$('[name="cf-turnstile-response"]');
7-
8-
if (elements.length <= 0) return resolve(false);
7+
if (elements.length <= 0) {
8+
const coordinates = await page.evaluate(() => {
9+
let coordinates = [];
10+
document.querySelectorAll('div').forEach(item => {
11+
try {
12+
if (item.getAttribute('style').includes('padding') && item.getAttribute('style').includes('border') && item.getAttribute('style').includes('margin')) coordinates.push({ x: item.getBoundingClientRect().x, y: item.getBoundingClientRect().y, w: item.getBoundingClientRect().width, h: item.getBoundingClientRect().height })
13+
} catch (err) { }
14+
});
15+
return coordinates
16+
})
17+
for (const item of coordinates) {
18+
try {
19+
let x = item.x + 30;
20+
let y = item.y + item.h / 2;
21+
await page.mouse.click(x, y);
22+
} catch (err) { }
23+
}
24+
return resolve(true)
25+
}
926

1027
for (const element of elements) {
1128
try {
1229
const parentElement = await element.evaluateHandle(el => el.parentElement);
13-
1430
const box = await parentElement.boundingBox();
15-
1631
let x = box.x + 30;
1732
let y = box.y + box.height / 2;
18-
await page.realCursor.moveTo({ x, y });
1933
await page.mouse.click(x, y);
20-
try {
21-
x += 30
22-
await page.realCursor.moveTo({ x, y });
23-
await page.mouse.click(x, y);
24-
} catch (err) { }
25-
try {
26-
x += 30
27-
await page.realCursor.moveTo({ x, y });
28-
await page.mouse.click(x, y);
29-
} catch (err) { }
3034
} catch (err) { }
3135
}
3236
clearInterval(waitInterval)

lib/esm/module/turnstile.mjs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
export const checkTurnstile = ({ page }) => {
22
return new Promise(async (resolve, reject) => {
33
var waitInterval = setTimeout(() => { clearInterval(waitInterval); resolve(false) }, 5000);
4-
54
try {
65
const elements = await page.$$('[name="cf-turnstile-response"]');
7-
8-
if (elements.length <= 0) return resolve(false);
6+
if (elements.length <= 0) {
7+
const coordinates = await page.evaluate(() => {
8+
let coordinates = [];
9+
document.querySelectorAll('div').forEach(item => {
10+
try {
11+
if (item.getAttribute('style').includes('padding') && item.getAttribute('style').includes('border') && item.getAttribute('style').includes('margin')) coordinates.push({ x: item.getBoundingClientRect().x, y: item.getBoundingClientRect().y, w: item.getBoundingClientRect().width, h: item.getBoundingClientRect().height })
12+
} catch (err) { }
13+
});
14+
return coordinates
15+
})
16+
for (const item of coordinates) {
17+
try {
18+
let x = item.x + 30;
19+
let y = item.y + item.h / 2;
20+
await page.mouse.click(x, y);
21+
} catch (err) { }
22+
}
23+
return resolve(true)
24+
}
925

1026
for (const element of elements) {
1127
try {
1228
const parentElement = await element.evaluateHandle(el => el.parentElement);
13-
1429
const box = await parentElement.boundingBox();
15-
1630
let x = box.x + 30;
1731
let y = box.y + box.height / 2;
18-
await page.realCursor.moveTo({ x, y });
1932
await page.mouse.click(x, y);
20-
try {
21-
x += 30
22-
await page.realCursor.moveTo({ x, y });
23-
await page.mouse.click(x, y);
24-
} catch (err) { }
25-
try {
26-
x += 30
27-
await page.realCursor.moveTo({ x, y });
28-
await page.mouse.click(x, y);
29-
} catch (err) { }
3033
} catch (err) { }
3134
}
3235
clearInterval(waitInterval)
3336
resolve(true)
37+
clearInterval(waitInterval)
38+
resolve(true)
3439
} catch (err) {
3540
clearInterval(waitInterval)
3641
resolve(false)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "puppeteer-real-browser",
3-
"version": "1.3.5",
3+
"version": "1.3.6",
44
"description": "This package is designed to bypass puppeteer's bot-detecting captchas such as Cloudflare. It acts like a real browser and can be managed with puppeteer.",
55
"main": "lib/cjs/index.js",
66
"module": "lib/esm/index.mjs",

0 commit comments

Comments
 (0)