Update endpoints/recaptchav3.js
Browse files- endpoints/recaptchav3.js +42 -62
endpoints/recaptchav3.js
CHANGED
|
@@ -1,95 +1,75 @@
|
|
| 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 |
-
|
| 7 |
-
const
|
| 8 |
|
| 9 |
try {
|
| 10 |
-
console.log(`[RV3]
|
| 11 |
-
|
| 12 |
-
// 1.
|
| 13 |
await page.setRequestInterception(false);
|
| 14 |
|
| 15 |
-
// 2.
|
| 16 |
-
|
| 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
|
| 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,
|
| 38 |
-
|
| 39 |
-
} catch (e) {}
|
| 40 |
|
| 41 |
-
// 4. Eksekusi Token
|
| 42 |
-
console.log("[RV3] Executing Captcha...");
|
| 43 |
-
|
| 44 |
const token = await page.evaluate(async (key, act) => {
|
| 45 |
return new Promise((res, rej) => {
|
| 46 |
-
//
|
| 47 |
-
const t = setTimeout(() => rej("Google Execute
|
| 48 |
|
| 49 |
-
const
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
.
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
};
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 65 |
} else {
|
| 66 |
-
|
| 67 |
const script = document.createElement('script');
|
| 68 |
script.src = `https://www.google.com/recaptcha/api.js?render=${key}`;
|
| 69 |
-
script.
|
| 70 |
-
script.
|
| 71 |
-
script.onerror = () => rej("Failed loading Google API");
|
| 72 |
document.head.appendChild(script);
|
| 73 |
}
|
| 74 |
});
|
| 75 |
}, siteKey, action);
|
| 76 |
|
| 77 |
-
clearTimeout(
|
| 78 |
|
| 79 |
if (token) {
|
| 80 |
-
console.log(`[RV3]
|
| 81 |
resolve(token);
|
| 82 |
} else {
|
| 83 |
-
reject(new Error("Token
|
| 84 |
}
|
| 85 |
|
| 86 |
} catch (e) {
|
| 87 |
-
clearTimeout(
|
| 88 |
-
//
|
| 89 |
-
|
| 90 |
-
console.log("[RV3] Google Stuck. IP might be flagged.");
|
| 91 |
-
}
|
| 92 |
-
reject(e);
|
| 93 |
}
|
| 94 |
});
|
| 95 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
module.exports = async function(page, url, siteKey, action = 'submit') {
|
| 2 |
return new Promise(async (resolve, reject) => {
|
| 3 |
+
// Timeout Global 60 Detik
|
| 4 |
+
const timeout = setTimeout(() => reject(new Error("Timeout waiting for reCAPTCHA v3 token (60s)")), 60000);
|
| 5 |
|
| 6 |
try {
|
| 7 |
+
console.log(`[RV3] Processing: ${url} | Action: ${action}`);
|
| 8 |
+
|
| 9 |
+
// 1. Matikan Intercept (Biarkan browser handle resource sendiri)
|
| 10 |
await page.setRequestInterception(false);
|
| 11 |
|
| 12 |
+
// 2. Buka Halaman
|
| 13 |
+
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 45000 });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
// 3. Simulasi Mouse
|
|
|
|
| 16 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
await page.mouse.move(100, 100);
|
| 18 |
+
await page.mouse.move(200, 200, { steps: 10 });
|
| 19 |
+
} catch(e) {}
|
|
|
|
| 20 |
|
| 21 |
+
// 4. Eksekusi Token Generation
|
|
|
|
|
|
|
| 22 |
const token = await page.evaluate(async (key, act) => {
|
| 23 |
return new Promise((res, rej) => {
|
| 24 |
+
// Timeout Internal Browser 15 detik
|
| 25 |
+
const t = setTimeout(() => rej(new Error("Google Execute Timeout (Internal)")), 15000);
|
| 26 |
|
| 27 |
+
const runCaptcha = () => {
|
| 28 |
+
try {
|
| 29 |
+
grecaptcha.ready(() => {
|
| 30 |
+
grecaptcha.execute(key, { action: act })
|
| 31 |
+
.then(token => {
|
| 32 |
+
clearTimeout(t);
|
| 33 |
+
res(token);
|
| 34 |
+
})
|
| 35 |
+
.catch(err => {
|
| 36 |
+
clearTimeout(t);
|
| 37 |
+
rej(new Error("Google Execute Error: " + err));
|
| 38 |
+
});
|
| 39 |
+
});
|
| 40 |
+
} catch (e) {
|
| 41 |
+
clearTimeout(t);
|
| 42 |
+
rej(new Error("Global Context Error: " + e.message));
|
| 43 |
+
}
|
| 44 |
};
|
| 45 |
|
| 46 |
+
// Cek & Inject
|
| 47 |
+
if (typeof grecaptcha !== 'undefined') {
|
| 48 |
+
runCaptcha();
|
| 49 |
} else {
|
| 50 |
+
console.log("Injecting Google Script...");
|
| 51 |
const script = document.createElement('script');
|
| 52 |
script.src = `https://www.google.com/recaptcha/api.js?render=${key}`;
|
| 53 |
+
script.onload = runCaptcha;
|
| 54 |
+
script.onerror = () => rej(new Error("Failed to load Google URL"));
|
|
|
|
| 55 |
document.head.appendChild(script);
|
| 56 |
}
|
| 57 |
});
|
| 58 |
}, siteKey, action);
|
| 59 |
|
| 60 |
+
clearTimeout(timeout);
|
| 61 |
|
| 62 |
if (token) {
|
| 63 |
+
console.log(`[RV3] Success! Token generated.`);
|
| 64 |
resolve(token);
|
| 65 |
} else {
|
| 66 |
+
reject(new Error("Token returned null"));
|
| 67 |
}
|
| 68 |
|
| 69 |
} catch (e) {
|
| 70 |
+
clearTimeout(timeout);
|
| 71 |
+
// Pastikan error selalu berupa Object Error
|
| 72 |
+
reject(e instanceof Error ? e : new Error(e.toString()));
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
| 74 |
});
|
| 75 |
};
|