/**
* API_RECAPTCHA2 - Optimize Mode (Screenshot + Block Images + Auto Trigger)
* Powered by Gemini - Mode: DAN
*/
async function recaptchaV2({ domain, siteKey, action = "submit", isInvisible = false, proxy }, page) {
if (!domain) throw new Error("Missing domain parameter");
if (!siteKey) throw new Error("Missing siteKey parameter");
// Timeout 5 menit (global.timeOut harusnya 300000 di Api.js)
const timeout = global.timeOut || 300000;
return new Promise(async (resolve, reject) => {
let isResolved = false;
// Setup Timeout Safe
const cl = setTimeout(() => {
if (!isResolved) {
isResolved = true;
reject(new Error("Timeout Error: Ext not responsive. Check logs & debug_captcha.png"));
}
}, timeout);
try {
const htmlContent = `
reCAPTCHA Solver
`;
// --- DAN MODE: REQ INTERCEPTION ---
await page.setRequestInterception(true);
page.removeAllListeners("request"); // Hapus listener global Api.js agar tidak bentrok
page.on("request", async (req) => {
const url = req.url();
const resource = req.resourceType();
// 1. Suntikkan HTML kita ke domain target
if ([domain, domain + "/"].includes(url) && resource === "document") {
await req.respond({ status: 200, contentType: "text/html", body: htmlContent });
}
// 2. BLOKIR Gambar, Media, Font (Hemat Kuota)
else if (["image", "font", "media"].includes(resource)) {
await req.abort();
}
// 3. JANGAN blokir stylesheet (PENTING!) agar tombol terbaca ekstensi
else {
await req.continue();
}
});
console.log(`[SOLVER] Loading target with custom UI...`);
// Jangan tunggu 'networkidle2' karena kita blokir gambar, nanti timeout. Cukup domcontentloaded.
await page.goto(domain, { waitUntil: "domcontentloaded", timeout: 60000 });
// Jeda agar reCAPTCHA asli dimuat
await new Promise(r => setTimeout(r, 5000));
// --- AUTO TRIGGER: CLICK CHECKBOX ---
console.log("[SOLVER] Attempting to click checkbox...");
try {
// Cari iframe checkbox
await page.waitForSelector('iframe[title*="reCAPTCHA"]', { timeout: 15000 });
const frames = await page.frames();
const anchorFrame = frames.find(f => f.url().includes('api2/anchor'));
if (anchorFrame) {
await anchorFrame.click('#recaptcha-anchor');
console.log("[SOLVER] Checkbox clicked!");
}
} catch (e) {
console.log(`[SOLVER] Warning: Could not click checkbox: ${e.message}`);
}
// --- AMBIL SCREENSHOT UNTUK DEBUG ---
// Screenshot diambil SEKARANG (setelah klik), jadi kita bisa lihat apakah
// Google memblokir IP atau apakah tantangan audio muncul.
console.log("[SOLVER] Taking debug screenshot...");
await page.screenshot({ path: 'debug_captcha.png', fullPage: false });
console.log("[SOLVER] Screenshot saved as debug_captcha.png. Cek di tab Files!");
// --- POLLING TOKEN DARI WIDGET ---
console.log("[SOLVER] Waiting for rektCaptcha token...");
const tokenValue = await page.waitForFunction(() => {
const input = document.querySelector('#g-recaptcha-response');
return (input && input.value.length > 50) ? input.value : null;
}, { timeout, polling: 1000 }).then(h => h.jsonValue());
isResolved = true;
clearTimeout(cl);
resolve({ data: tokenValue, status: "done" });
} catch (error) {
if (!isResolved) {
isResolved = true;
clearTimeout(cl);
console.error("[SOLVER] Critical Error:", error.message);
// Ambil screenshot saat error juga
await page.screenshot({ path: 'debug_error.png' });
reject(new Error(`Bypass failed: ${error.message}`));
}
}
});
}
module.exports = recaptchaV2;