Apalah / Api /interstitial.js
Forgets's picture
Update Api/interstitial.js
787e9f9 verified
/**
* /Api/interstitial.js
* Geus disinkronkeun jeung Api.js (puppeteer-real-browser)
*/
async function interstitial({ domain, proxy }, page) {
return new Promise(async (resolve, reject) => {
if (!domain) return reject(new Error("Missing domain parameter"));
let isResolved = false;
let cf_clearance = null;
// Timeout 60 detik sangkan teu ngagantung
const timeout = setTimeout(() => {
if (!isResolved) {
isResolved = true;
resolve({ success: false, error: "Timeout nungguan Cloudflare" });
}
}, 60000);
try {
// 1. Ngintip sési clearance tina response jaringan
page.on('response', async (response) => {
try {
const cookies = await page.cookies();
const found = cookies.find(c => c.name === 'cf_clearance');
if (found && !isResolved) {
cf_clearance = found.value;
const userAgent = await page.evaluate(() => navigator.userAgent);
const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
isResolved = true;
clearTimeout(timeout);
resolve({
success: true,
cf_clearance: cf_clearance,
user_agent: userAgent,
full_cookies: cookieString
});
}
} catch (_) {}
});
// 2. Buka domain target
// Paké networkidle2 sangkan mastikeun script Cloudflare geus jalan
await page.goto(domain, { waitUntil: 'networkidle2', timeout: 60000 });
// 3. Akalan: Simulasi gerakan mouse saeutik sangkan dianggap manusa
await page.mouse.move(100, 100);
await page.mouse.move(200, 300, { steps: 5 });
// 4. Tungguan sakedap bisi aya Turnstile iframe
const turnstileIframe = await page.$('iframe[src*="challenges"]');
if (turnstileIframe) {
console.log("[*] Turnstile detected, waiting 10s...");
await new Promise(r => setTimeout(r, 10000));
}
// 5. Mun geus nunggu tapi can meunang cookie, coba cek sakali deui méméh kaluar
if (!isResolved) {
const cookies = await page.cookies();
const found = cookies.find(c => c.name === 'cf_clearance');
if (found) {
const userAgent = await page.evaluate(() => navigator.userAgent);
isResolved = true;
clearTimeout(timeout);
resolve({
success: true,
cf_clearance: found.value,
user_agent: userAgent,
full_cookies: cookies.map(c => `${c.name}=${c.value}`).join('; ')
});
}
}
} catch (err) {
if (!isResolved) {
isResolved = true;
clearTimeout(timeout);
reject(err);
}
}
});
}
// IEU WAJIB AYA SANGKAN BISA DIPANGGIL DI API.JS
module.exports = interstitial;