Update endpoints/recaptchav3.js
Browse files- endpoints/recaptchav3.js +67 -46
endpoints/recaptchav3.js
CHANGED
|
@@ -1,73 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
module.exports = async function(page, url, siteKey, action = 'submit') {
|
| 2 |
return new Promise(async (resolve, reject) => {
|
| 3 |
-
const
|
|
|
|
| 4 |
|
| 5 |
try {
|
| 6 |
-
console.log(`[RV3] Target: ${url}`);
|
| 7 |
-
|
| 8 |
-
await page.setRequestInterception(false);
|
| 9 |
|
| 10 |
-
|
| 11 |
-
await page.
|
| 12 |
-
console.log("[RV3] 2. Page loaded.");
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 34 |
|
|
|
|
|
|
|
| 35 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
await page.mouse.move(100, 100);
|
| 37 |
-
await page.mouse.move(200,
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
const token = await page.evaluate(async (key, act) => {
|
| 42 |
return new Promise((res, rej) => {
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
});
|
| 57 |
}, siteKey, action);
|
| 58 |
|
| 59 |
-
clearTimeout(
|
| 60 |
|
| 61 |
if (token) {
|
| 62 |
-
console.log(`[RV3]
|
| 63 |
resolve(token);
|
| 64 |
} else {
|
| 65 |
-
reject(new Error("Token
|
| 66 |
}
|
| 67 |
|
| 68 |
} catch (e) {
|
| 69 |
-
clearTimeout(
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
reject(e);
|
| 72 |
}
|
| 73 |
});
|
|
|
|
| 1 |
+
// Helper: Tunggu sebentar
|
| 2 |
+
const delay = ms => new Promise(res => setTimeout(res, ms));
|
| 3 |
+
|
| 4 |
module.exports = async function(page, url, siteKey, action = 'submit') {
|
| 5 |
return new Promise(async (resolve, reject) => {
|
| 6 |
+
const GLOBAL_TIMEOUT = 60000;
|
| 7 |
+
const timeoutTimer = setTimeout(() => reject(new Error("Timeout Global (60s)")), GLOBAL_TIMEOUT);
|
| 8 |
|
| 9 |
try {
|
| 10 |
+
console.log(`[RV3] Target: ${url} | Key: ${siteKey}`);
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
// 1. Optimasi Halaman (Jangan blokir apapun agar Fingerprint valid)
|
| 13 |
+
await page.setRequestInterception(false);
|
|
|
|
| 14 |
|
| 15 |
+
// 2. Navigasi dengan Retry
|
| 16 |
+
let loaded = false;
|
| 17 |
+
for (let i = 0; i < 2; i++) {
|
| 18 |
+
try {
|
| 19 |
+
console.log(`[RV3] Attempt ${i + 1}: Navigating...`);
|
| 20 |
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 20000 });
|
| 21 |
+
loaded = true;
|
| 22 |
+
break;
|
| 23 |
+
} catch (e) {
|
| 24 |
+
console.log(`[RV3] Navigation failed, retrying... (${e.message})`);
|
| 25 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
+
if (!loaded) throw new Error("Failed to load page after 2 attempts");
|
| 28 |
|
| 29 |
+
// 3. Simulasi Manusia (PENTING BUAT SKOR)
|
| 30 |
+
console.log("[RV3] Simulating human behavior...");
|
| 31 |
try {
|
| 32 |
+
// Scroll random
|
| 33 |
+
await page.evaluate(() => window.scrollBy(0, 300));
|
| 34 |
+
await delay(500);
|
| 35 |
+
// Gerakkan mouse acak
|
| 36 |
await page.mouse.move(100, 100);
|
| 37 |
+
await page.mouse.move(200, 300, { steps: 5 });
|
| 38 |
+
await page.mouse.move(150, 250, { steps: 5 });
|
| 39 |
+
} catch (e) {}
|
| 40 |
|
| 41 |
+
// 4. Eksekusi Token (Dengan Timeout Internal)
|
| 42 |
+
console.log("[RV3] Executing Captcha...");
|
| 43 |
+
|
| 44 |
const token = await page.evaluate(async (key, act) => {
|
| 45 |
return new Promise((res, rej) => {
|
| 46 |
+
// Paksa error jika Google hang lebih dari 10 detik
|
| 47 |
+
const t = setTimeout(() => rej("Google Execute Stuck"), 10000);
|
| 48 |
+
|
| 49 |
+
const run = () => {
|
| 50 |
+
window.grecaptcha.ready(() => {
|
| 51 |
+
window.grecaptcha.execute(key, { action: act })
|
| 52 |
+
.then(token => {
|
| 53 |
+
clearTimeout(t);
|
| 54 |
+
res(token);
|
| 55 |
+
})
|
| 56 |
+
.catch(err => {
|
| 57 |
+
clearTimeout(t);
|
| 58 |
+
rej(err.message || err);
|
| 59 |
+
});
|
| 60 |
+
});
|
| 61 |
+
};
|
| 62 |
+
|
| 63 |
+
if (typeof window.grecaptcha !== 'undefined' && window.grecaptcha.execute) {
|
| 64 |
+
run();
|
| 65 |
+
} else {
|
| 66 |
+
// Inject Script Asli Google
|
| 67 |
+
const script = document.createElement('script');
|
| 68 |
+
script.src = `https://www.google.com/recaptcha/api.js?render=${key}`;
|
| 69 |
+
script.async = true;
|
| 70 |
+
script.onload = () => setTimeout(run, 1000); // Tunggu inisialisasi
|
| 71 |
+
script.onerror = () => rej("Failed loading Google API");
|
| 72 |
+
document.head.appendChild(script);
|
| 73 |
+
}
|
| 74 |
});
|
| 75 |
}, siteKey, action);
|
| 76 |
|
| 77 |
+
clearTimeout(timeoutTimer);
|
| 78 |
|
| 79 |
if (token) {
|
| 80 |
+
console.log(`[RV3] SUCCESS. Token length: ${token.length}`);
|
| 81 |
resolve(token);
|
| 82 |
} else {
|
| 83 |
+
reject(new Error("Token empty"));
|
| 84 |
}
|
| 85 |
|
| 86 |
} catch (e) {
|
| 87 |
+
clearTimeout(timeoutTimer);
|
| 88 |
+
// Cek apakah error karena hang
|
| 89 |
+
if (e.message && e.message.includes("Stuck")) {
|
| 90 |
+
console.log("[RV3] Google Stuck. IP might be flagged.");
|
| 91 |
+
}
|
| 92 |
reject(e);
|
| 93 |
}
|
| 94 |
});
|