Skip to content

Commit 3d0e622

Browse files
committed
Added recaptcha v3 to test function.
1 parent cbb0260 commit 3d0e622

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

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.2.26",
3+
"version": "1.2.27",
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
"type": "module",
66
"exports": "./src/index.js",

src/test.js

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { connect } from './index.js'
2+
3+
var dataset = {
4+
success: 0,
5+
failed: 0
6+
}
7+
28
console.log("Launching the browser...");
3-
const { page, browser } = await connect({
9+
var { page, browser } = await connect({
410
headless: 'auto',
511
args: [],
612
customConfig: {},
@@ -9,7 +15,7 @@ const { page, browser } = await connect({
915
turnstile: true,
1016
connectOption: {}
1117
})
12-
setInterval(() => { page.screenshot({ path: 'example.png' }).catch(err => { }); }, 1000);
18+
// setInterval(() => { page.screenshot({ path: 'example.png' }).catch(err => { }); }, 1000);
1319
console.log("The browser is launched...");
1420
async function checkWaf() {
1521
console.log('WAF testing started');
@@ -22,9 +28,11 @@ async function checkWaf() {
2228
timeout: 60000
2329
})
2430
.then(() => {
31+
dataset.success++
2532
console.log('[SUCCESS] WAF test successful.');
2633
})
2734
.catch(() => {
35+
dataset.failed++
2836
console.log('[ERROR] WAF test failed.');
2937
})
3038

@@ -36,40 +44,86 @@ async function checkCaptcha() {
3644

3745
page.goto("https://nopecha.com/captcha/turnstile", {
3846
waitUntil: 'load'
39-
})
47+
}).catch(err => { })
4048
await page.waitForSelector('a')
4149
await new Promise((resolve) => { setTimeout(() => { resolve() }, 500) })
4250
console.log('Navigated to page');
4351
const token = await page.evaluate(() => {
44-
setTimeout(() => {
52+
var cl = setTimeout(() => {
4553
resolve(false)
4654
}, 15000);
4755
return new Promise((resolve) => {
4856
const input = document.querySelector('input[name="cf-turnstile-response"]');
4957
if (input) {
5058
const observer = new MutationObserver((mutations) => {
5159
var mutation = mutations.find((mutation) => { return mutation.type === 'attributes' && mutation.attributeName === 'value' });
52-
if (mutation && input.value.length > 3 && !input.value.includes('DUMMY')) return resolve(input.value)
60+
if (mutation && input.value.length > 3 && !input.value.includes('DUMMY')) {
61+
clearInterval(cl)
62+
return resolve(input.value)
63+
}
5364
});
5465
observer.observe(input, { attributes: true, attributeFilter: ['value'] });
5566
}
5667
})
5768
});
5869
if (token === false) {
70+
dataset.failed++
5971
console.log("Failed to receive Turnstile Token. Transaction failed.");
6072
} else {
73+
dataset.success++
6174
console.log("Turnstile Captcha test successful.\n\n" + token);
6275
}
6376
return
6477
}
6578

79+
async function recaptchav3() {
80+
console.log('Starting recaptcha-v3 test...');
81+
page.goto('https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php').catch(err => { })
82+
await page.waitForSelector('#recaptcha-steps')
83+
await new Promise((resolve) => { setTimeout(() => { resolve() }, 2000) })
84+
console.log('Navigated to page');
85+
const score = await page.evaluate(() => {
86+
return new Promise((resolve) => {
87+
var cl = setTimeout(() => {
88+
resolve(false)
89+
}, 8000);
90+
grecaptcha.ready(function () {
91+
document.querySelector('.step1').classList.remove('hidden');
92+
grecaptcha.execute('6LdKlZEpAAAAAAOQjzC2v_d36tWxCl6dWsozdSy9', { action: 'examples/v3scores' }).then(function (token) {
93+
fetch('/recaptcha-v3-verify.php?action=examples/v3scores&token=' + token).then(function (response) {
94+
response.json().then(function (data) {
95+
clearInterval(cl)
96+
resolve(data)
97+
});
98+
});
99+
});
100+
});
66101

102+
})
103+
})
104+
if (score === false) {
105+
dataset.failed++
106+
console.log("Recaptcha-v3 test failed.")
107+
return
108+
}
109+
if (score.score >= 0.7) {
110+
dataset.success++
111+
console.log('Recaptcha-v3 test successful.\n' + "Score: " + score.score + "\n" + JSON.stringify(score));
112+
return
113+
}
114+
dataset.failed++
115+
console.log("Recaptcha-v3 test failed. " + "Score: " + score.score + "\n" + JSON.stringify(score));
67116

117+
return
118+
}
68119

69-
await checkWaf()
70-
await checkCaptcha()
71120

72121

73122

123+
await checkWaf()
124+
await checkCaptcha()
125+
await recaptchav3()
74126

127+
console.log(`Test completed.\nSuccess: ${dataset.success}\nFailed: ${dataset.failed}`);
75128

129+
await browser.close().catch(err => { })

0 commit comments

Comments
 (0)