Update endpoints/recaptchav3.js
Browse files- endpoints/recaptchav3.js +46 -39
endpoints/recaptchav3.js
CHANGED
|
@@ -3,64 +3,71 @@ module.exports = async function(page, url, siteKey, action = 'submit') {
|
|
| 3 |
const timeout = setTimeout(() => reject(new Error("Timeout waiting for reCAPTCHA v3 token (60s)")), 60000);
|
| 4 |
|
| 5 |
try {
|
| 6 |
-
console.log(`[RV3]
|
| 7 |
|
| 8 |
await page.setRequestInterception(false);
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
const token = await page.evaluate(async (key, act) => {
|
| 20 |
return new Promise((res, rej) => {
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
};
|
| 34 |
-
|
| 35 |
-
if (typeof window.grecaptcha !== 'undefined' && window.grecaptcha.execute) {
|
| 36 |
-
console.log("Browser: Native script found.");
|
| 37 |
-
runCaptcha();
|
| 38 |
-
} else {
|
| 39 |
-
console.log("Browser: Injecting script manual...");
|
| 40 |
-
const script = document.createElement('script');
|
| 41 |
-
script.src = `https://www.google.com/recaptcha/api.js?render=${key}`;
|
| 42 |
-
script.async = true;
|
| 43 |
-
script.onload = () => {
|
| 44 |
-
console.log("Browser: Script loaded.");
|
| 45 |
-
setTimeout(runCaptcha, 1000);
|
| 46 |
-
};
|
| 47 |
-
script.onerror = () => rej("Failed to load Google Script from Google Server");
|
| 48 |
-
document.head.appendChild(script);
|
| 49 |
-
}
|
| 50 |
});
|
| 51 |
}, siteKey, action);
|
| 52 |
|
| 53 |
clearTimeout(timeout);
|
| 54 |
|
| 55 |
if (token) {
|
| 56 |
-
console.log(`[RV3]
|
| 57 |
resolve(token);
|
| 58 |
} else {
|
| 59 |
-
reject(new Error("
|
| 60 |
}
|
| 61 |
|
| 62 |
} catch (e) {
|
| 63 |
clearTimeout(timeout);
|
|
|
|
| 64 |
reject(e);
|
| 65 |
}
|
| 66 |
});
|
|
|
|
| 3 |
const timeout = setTimeout(() => reject(new Error("Timeout waiting for reCAPTCHA v3 token (60s)")), 60000);
|
| 4 |
|
| 5 |
try {
|
| 6 |
+
console.log(`[RV3] Target: ${url}`);
|
| 7 |
|
| 8 |
await page.setRequestInterception(false);
|
| 9 |
|
| 10 |
+
console.log("[RV3] 1. Navigating...");
|
| 11 |
+
await page.goto(url, { waitUntil: 'networkidle2', timeout: 30000 });
|
| 12 |
+
console.log("[RV3] 2. Page loaded.");
|
| 13 |
+
|
| 14 |
+
console.log("[RV3] 3. Checking for grecaptcha...");
|
| 15 |
+
const isCaptchaReady = await page.evaluate(async (key) => {
|
| 16 |
+
if (typeof window.grecaptcha !== 'undefined' && window.grecaptcha.execute) {
|
| 17 |
+
return true;
|
| 18 |
+
}
|
| 19 |
+
return new Promise((res) => {
|
| 20 |
+
const script = document.createElement('script');
|
| 21 |
+
script.src = `https://www.google.com/recaptcha/api.js?render=${key}`;
|
| 22 |
+
script.onload = () => res(true);
|
| 23 |
+
script.onerror = () => res(false);
|
| 24 |
+
document.head.appendChild(script);
|
| 25 |
+
});
|
| 26 |
+
}, siteKey);
|
| 27 |
+
|
| 28 |
+
if (!isCaptchaReady) {
|
| 29 |
+
clearTimeout(timeout);
|
| 30 |
+
reject(new Error("Failed to load Google reCAPTCHA Library"));
|
| 31 |
+
return;
|
| 32 |
}
|
| 33 |
+
console.log("[RV3] 4. grecaptcha Library is READY.");
|
| 34 |
|
| 35 |
+
try {
|
| 36 |
+
await page.mouse.move(100, 100);
|
| 37 |
+
await page.mouse.move(200, 200);
|
| 38 |
+
} catch(e) {}
|
| 39 |
+
|
| 40 |
+
console.log(`[RV3] 5. Executing action: '${action}'...`);
|
| 41 |
const token = await page.evaluate(async (key, act) => {
|
| 42 |
return new Promise((res, rej) => {
|
| 43 |
+
const t = setTimeout(() => rej("Google internal execution timed out"), 10000);
|
| 44 |
+
|
| 45 |
+
window.grecaptcha.ready(() => {
|
| 46 |
+
window.grecaptcha.execute(key, { action: act })
|
| 47 |
+
.then(token => {
|
| 48 |
+
clearTimeout(t);
|
| 49 |
+
res(token);
|
| 50 |
+
})
|
| 51 |
+
.catch(err => {
|
| 52 |
+
clearTimeout(t);
|
| 53 |
+
rej(err.message || err);
|
| 54 |
+
});
|
| 55 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
});
|
| 57 |
}, siteKey, action);
|
| 58 |
|
| 59 |
clearTimeout(timeout);
|
| 60 |
|
| 61 |
if (token) {
|
| 62 |
+
console.log(`[RV3] 6. SUCCESS! Token: ${token.substring(0, 15)}...`);
|
| 63 |
resolve(token);
|
| 64 |
} else {
|
| 65 |
+
reject(new Error("Token was null/empty"));
|
| 66 |
}
|
| 67 |
|
| 68 |
} catch (e) {
|
| 69 |
clearTimeout(timeout);
|
| 70 |
+
console.error(`[RV3] ERROR DETAIL: ${e.message}`);
|
| 71 |
reject(e);
|
| 72 |
}
|
| 73 |
});
|