Skip to content

Commit

Permalink
Added recaptcha v3 to test function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdervisaygan committed Jul 25, 2024
1 parent cbb0260 commit 3d0e622
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppeteer-real-browser",
"version": "1.2.26",
"version": "1.2.27",
"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.",
"type": "module",
"exports": "./src/index.js",
Expand Down
68 changes: 61 additions & 7 deletions src/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { connect } from './index.js'

var dataset = {
success: 0,
failed: 0
}

console.log("Launching the browser...");
const { page, browser } = await connect({
var { page, browser } = await connect({
headless: 'auto',
args: [],
customConfig: {},
Expand All @@ -9,7 +15,7 @@ const { page, browser } = await connect({
turnstile: true,
connectOption: {}
})
setInterval(() => { page.screenshot({ path: 'example.png' }).catch(err => { }); }, 1000);
// setInterval(() => { page.screenshot({ path: 'example.png' }).catch(err => { }); }, 1000);
console.log("The browser is launched...");
async function checkWaf() {
console.log('WAF testing started');
Expand All @@ -22,9 +28,11 @@ async function checkWaf() {
timeout: 60000
})
.then(() => {
dataset.success++
console.log('[SUCCESS] WAF test successful.');
})
.catch(() => {
dataset.failed++
console.log('[ERROR] WAF test failed.');
})

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

page.goto("https://nopecha.com/captcha/turnstile", {
waitUntil: 'load'
})
}).catch(err => { })
await page.waitForSelector('a')
await new Promise((resolve) => { setTimeout(() => { resolve() }, 500) })
console.log('Navigated to page');
const token = await page.evaluate(() => {
setTimeout(() => {
var cl = setTimeout(() => {
resolve(false)
}, 15000);
return new Promise((resolve) => {
const input = document.querySelector('input[name="cf-turnstile-response"]');
if (input) {
const observer = new MutationObserver((mutations) => {
var mutation = mutations.find((mutation) => { return mutation.type === 'attributes' && mutation.attributeName === 'value' });
if (mutation && input.value.length > 3 && !input.value.includes('DUMMY')) return resolve(input.value)
if (mutation && input.value.length > 3 && !input.value.includes('DUMMY')) {
clearInterval(cl)
return resolve(input.value)
}
});
observer.observe(input, { attributes: true, attributeFilter: ['value'] });
}
})
});
if (token === false) {
dataset.failed++
console.log("Failed to receive Turnstile Token. Transaction failed.");
} else {
dataset.success++
console.log("Turnstile Captcha test successful.\n\n" + token);
}
return
}

async function recaptchav3() {
console.log('Starting recaptcha-v3 test...');
page.goto('https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php').catch(err => { })
await page.waitForSelector('#recaptcha-steps')
await new Promise((resolve) => { setTimeout(() => { resolve() }, 2000) })
console.log('Navigated to page');
const score = await page.evaluate(() => {
return new Promise((resolve) => {
var cl = setTimeout(() => {
resolve(false)
}, 8000);
grecaptcha.ready(function () {
document.querySelector('.step1').classList.remove('hidden');
grecaptcha.execute('6LdKlZEpAAAAAAOQjzC2v_d36tWxCl6dWsozdSy9', { action: 'examples/v3scores' }).then(function (token) {
fetch('/recaptcha-v3-verify.php?action=examples/v3scores&token=' + token).then(function (response) {
response.json().then(function (data) {
clearInterval(cl)
resolve(data)
});
});
});
});

})
})
if (score === false) {
dataset.failed++
console.log("Recaptcha-v3 test failed.")
return
}
if (score.score >= 0.7) {
dataset.success++
console.log('Recaptcha-v3 test successful.\n' + "Score: " + score.score + "\n" + JSON.stringify(score));
return
}
dataset.failed++
console.log("Recaptcha-v3 test failed. " + "Score: " + score.score + "\n" + JSON.stringify(score));

return
}

await checkWaf()
await checkCaptcha()



await checkWaf()
await checkCaptcha()
await recaptchav3()

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

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

0 comments on commit 3d0e622

Please sign in to comment.