Update index.js
Browse files
index.js
CHANGED
|
@@ -12,7 +12,7 @@ let activeBrowsers = 0;
|
|
| 12 |
|
| 13 |
async function createBrowser(proxy = null) {
|
| 14 |
const options = {
|
| 15 |
-
headless: false,
|
| 16 |
turnstile: true,
|
| 17 |
args: [
|
| 18 |
'--no-sandbox',
|
|
@@ -43,152 +43,119 @@ async function createBrowser(proxy = null) {
|
|
| 43 |
return { browser, page };
|
| 44 |
}
|
| 45 |
|
| 46 |
-
// HANDLER CLOUDFLARE FINAL (HAR-PROVEN FIX)
|
| 47 |
async function handleCloudflare(page, url) {
|
| 48 |
return new Promise(async (resolve, reject) => {
|
| 49 |
-
// Timeout 120 Detik
|
| 50 |
const timeout = setTimeout(() => reject(new Error("Timeout Cloudflare Bypass")), 120000);
|
| 51 |
|
| 52 |
-
let cfValue = "";
|
| 53 |
-
let clearanceTime = 0;
|
| 54 |
-
let usedForRequest = false;
|
| 55 |
-
|
| 56 |
try {
|
| 57 |
console.log(`[Cloudflare] Navigating to ${url}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
page.on("response", async (resp) => {
|
| 61 |
try {
|
| 62 |
const headers = resp.headers();
|
| 63 |
-
const setCookie = headers[
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
}
|
| 75 |
}
|
| 76 |
-
} catch
|
| 77 |
});
|
| 78 |
|
| 79 |
await page.bringToFront();
|
| 80 |
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 81 |
|
| 82 |
-
// === 2. LOOP VERIFIER ===
|
| 83 |
const loop = setInterval(async () => {
|
| 84 |
try {
|
|
|
|
|
|
|
|
|
|
| 85 |
const cookies = await page.cookies();
|
| 86 |
-
const cf = cookies.find(c => c.name === "cf_clearance");
|
| 87 |
|
| 88 |
-
|
| 89 |
-
if (
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
}
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
usedForRequest = true;
|
| 99 |
-
const timeSinceCookie = Date.now() - clearanceTime;
|
| 100 |
-
|
| 101 |
-
// Beri jeda sedikit (2 detik) agar cookie tersimpan benar
|
| 102 |
-
if (timeSinceCookie > 2000) {
|
| 103 |
-
console.log("[CF] 🔄 Cookie detected. Forcing re-request to main document...");
|
| 104 |
-
await page.goto(url, {
|
| 105 |
-
waitUntil: "domcontentloaded", // Pakai domcontentloaded biar lebih cepat dari networkidle
|
| 106 |
-
timeout: 60000
|
| 107 |
-
}).catch(()=>{});
|
| 108 |
-
}
|
| 109 |
-
return;
|
| 110 |
-
}
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
const
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
clearInterval(loop);
|
| 126 |
-
clearTimeout(timeout);
|
| 127 |
-
|
| 128 |
-
const ua = await page.evaluate(() => navigator.userAgent);
|
| 129 |
-
const finalTitle = await page.title();
|
| 130 |
-
|
| 131 |
-
console.log(`[CF] ✅ CLEAN PASS! Server responded 200 OK.`);
|
| 132 |
-
|
| 133 |
-
resolve({
|
| 134 |
-
status: "success",
|
| 135 |
-
verified: true, // Tanda sukses mutlak
|
| 136 |
-
cookie: cfValue,
|
| 137 |
-
cookies_full: cookies,
|
| 138 |
-
userAgent: ua,
|
| 139 |
-
title: finalTitle
|
| 140 |
-
});
|
| 141 |
-
return;
|
| 142 |
-
}
|
| 143 |
}
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
if (challengeFrame) {
|
| 151 |
-
const checkbox = await challengeFrame.$("input[type='checkbox']");
|
| 152 |
-
if (checkbox) {
|
| 153 |
-
const box = await checkbox.boundingBox();
|
| 154 |
-
if (box) {
|
| 155 |
-
// Klik Fisik
|
| 156 |
-
const x = box.x + box.width / 2 + (Math.random() - 0.5) * 5;
|
| 157 |
-
const y = box.y + box.height / 2 + (Math.random() - 0.5) * 5;
|
| 158 |
-
await page.mouse.move(x, y);
|
| 159 |
-
await page.mouse.down();
|
| 160 |
-
await page.waitForTimeout(50);
|
| 161 |
-
await page.mouse.up();
|
| 162 |
-
}
|
| 163 |
-
} else {
|
| 164 |
-
// Klik Body Frame (Fallback)
|
| 165 |
-
await challengeFrame.click('body').catch(()=>{});
|
| 166 |
-
}
|
| 167 |
-
} else {
|
| 168 |
-
// Gerakan mouse random
|
| 169 |
-
try { await page.mouse.move(Math.random()*500, Math.random()*500); } catch(e){}
|
| 170 |
-
}
|
| 171 |
}
|
| 172 |
|
| 173 |
-
|
| 174 |
-
if (cfValue && Date.now() - clearanceTime > 30000) {
|
| 175 |
clearInterval(loop);
|
| 176 |
clearTimeout(timeout);
|
| 177 |
-
console.log("[
|
| 178 |
-
|
| 179 |
const ua = await page.evaluate(() => navigator.userAgent);
|
| 180 |
resolve({
|
| 181 |
status: "success",
|
| 182 |
-
verified: false, // Cookie ada, tapi halaman mungkin masih stuck
|
| 183 |
-
cookie: cfValue,
|
| 184 |
-
cookies_full: cookies,
|
| 185 |
userAgent: ua,
|
| 186 |
-
|
|
|
|
|
|
|
| 187 |
});
|
|
|
|
| 188 |
}
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
} catch (e) {}
|
| 191 |
-
}, 1000);
|
| 192 |
|
| 193 |
} catch (e) {
|
| 194 |
clearTimeout(timeout);
|
|
@@ -197,7 +164,6 @@ async function handleCloudflare(page, url) {
|
|
| 197 |
});
|
| 198 |
}
|
| 199 |
|
| 200 |
-
// ... Handle Turnstile Manual & Server Setup TETAP SAMA ...
|
| 201 |
async function handleTurnstile(page, url, siteKey) {
|
| 202 |
return new Promise(async (resolve, reject) => {
|
| 203 |
const timeout = setTimeout(() => reject(new Error("Timeout Turnstile")), 60000);
|
|
|
|
| 12 |
|
| 13 |
async function createBrowser(proxy = null) {
|
| 14 |
const options = {
|
| 15 |
+
headless: false,
|
| 16 |
turnstile: true,
|
| 17 |
args: [
|
| 18 |
'--no-sandbox',
|
|
|
|
| 43 |
return { browser, page };
|
| 44 |
}
|
| 45 |
|
|
|
|
| 46 |
async function handleCloudflare(page, url) {
|
| 47 |
return new Promise(async (resolve, reject) => {
|
|
|
|
| 48 |
const timeout = setTimeout(() => reject(new Error("Timeout Cloudflare Bypass")), 120000);
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
try {
|
| 51 |
console.log(`[Cloudflare] Navigating to ${url}`);
|
| 52 |
+
|
| 53 |
+
let cookieFoundTime = 0;
|
| 54 |
+
let finalCookieValue = "";
|
| 55 |
+
let hasForcedNavigated = false;
|
| 56 |
|
| 57 |
+
page.on('response', async resp => {
|
|
|
|
| 58 |
try {
|
| 59 |
const headers = resp.headers();
|
| 60 |
+
const setCookie = headers['set-cookie'] || headers['Set-Cookie'] || headers['set-cookie'.toLowerCase()];
|
| 61 |
+
|
| 62 |
+
if (setCookie) {
|
| 63 |
+
const cookieStr = Array.isArray(setCookie) ? setCookie.join(' ') : setCookie;
|
| 64 |
+
if (cookieStr.includes('cf_clearance')) {
|
| 65 |
+
if (cookieFoundTime === 0) {
|
| 66 |
+
cookieFoundTime = Date.now();
|
| 67 |
+
console.log(`[Cloudflare] 🔥 FAST DETECT: cf_clearance found via Listener!`);
|
| 68 |
+
const match = cookieStr.match(/cf_clearance=([^;]+)/);
|
| 69 |
+
if (match) finalCookieValue = match[1];
|
| 70 |
+
}
|
| 71 |
}
|
| 72 |
}
|
| 73 |
+
} catch(e){}
|
| 74 |
});
|
| 75 |
|
| 76 |
await page.bringToFront();
|
| 77 |
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 78 |
|
|
|
|
| 79 |
const loop = setInterval(async () => {
|
| 80 |
try {
|
| 81 |
+
const title = await page.title();
|
| 82 |
+
const content = await page.content();
|
| 83 |
+
const currentTime = Date.now();
|
| 84 |
const cookies = await page.cookies();
|
|
|
|
| 85 |
|
| 86 |
+
const cfCookie = cookies.find(c => c.name === 'cf_clearance');
|
| 87 |
+
if (cfCookie) {
|
| 88 |
+
if (cookieFoundTime === 0) console.log(`[Cloudflare] Cookie found in storage.`);
|
| 89 |
+
cookieFoundTime = cookieFoundTime || Date.now();
|
| 90 |
+
finalCookieValue = cfCookie.value;
|
| 91 |
}
|
| 92 |
|
| 93 |
+
const isChallengePage = title.includes("Just a moment") ||
|
| 94 |
+
content.includes("challenge-platform") ||
|
| 95 |
+
title.includes("Cloudflare");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
if (!isChallengePage && title.trim().length > 0) {
|
| 98 |
+
clearInterval(loop);
|
| 99 |
+
clearTimeout(timeout);
|
| 100 |
+
const ua = await page.evaluate(() => navigator.userAgent);
|
| 101 |
+
console.log(`[Cloudflare] Success! Page Title: ${title}`);
|
| 102 |
+
resolve({
|
| 103 |
+
status: "success",
|
| 104 |
+
userAgent: ua,
|
| 105 |
+
cookies_full: cookies,
|
| 106 |
+
cookie: finalCookieValue,
|
| 107 |
+
title: title
|
| 108 |
+
});
|
| 109 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
}
|
| 111 |
|
| 112 |
+
if (cookieFoundTime > 0 && (currentTime - cookieFoundTime) > 5000 && !hasForcedNavigated) {
|
| 113 |
+
console.log("[Cloudflare] Cookie found but stuck. Performing FORCE NAVIGATION...");
|
| 114 |
+
hasForcedNavigated = true;
|
| 115 |
+
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 }).catch(()=>{});
|
| 116 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
}
|
| 118 |
|
| 119 |
+
if (hasForcedNavigated && (currentTime - cookieFoundTime) > 20000) {
|
|
|
|
| 120 |
clearInterval(loop);
|
| 121 |
clearTimeout(timeout);
|
| 122 |
+
console.log("[Cloudflare] Giving up waiting for title change. Returning valid cookie.");
|
|
|
|
| 123 |
const ua = await page.evaluate(() => navigator.userAgent);
|
| 124 |
resolve({
|
| 125 |
status: "success",
|
|
|
|
|
|
|
|
|
|
| 126 |
userAgent: ua,
|
| 127 |
+
cookies_full: cookies,
|
| 128 |
+
cookie: finalCookieValue,
|
| 129 |
+
title: title
|
| 130 |
});
|
| 131 |
+
return;
|
| 132 |
}
|
| 133 |
|
| 134 |
+
const frames = page.frames();
|
| 135 |
+
const challengeFrame = frames.find(f => f.url().includes("challenges.cloudflare.com") || f.url().includes("turnstile"));
|
| 136 |
+
|
| 137 |
+
if (challengeFrame) {
|
| 138 |
+
try {
|
| 139 |
+
const checkbox = await challengeFrame.$("input[type='checkbox']");
|
| 140 |
+
if (checkbox) {
|
| 141 |
+
const isChecked = await challengeFrame.evaluate(el => el.checked, checkbox);
|
| 142 |
+
if (!isChecked) {
|
| 143 |
+
console.log("[Cloudflare] Checkbox found & clicked!");
|
| 144 |
+
await checkbox.click();
|
| 145 |
+
}
|
| 146 |
+
} else {
|
| 147 |
+
await challengeFrame.click('body').catch(()=>{});
|
| 148 |
+
}
|
| 149 |
+
} catch(e) {}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
try {
|
| 153 |
+
await page.mouse.move(Math.floor(Math.random() * 500), Math.floor(Math.random() * 500));
|
| 154 |
+
if (Math.random() > 0.95) await page.click('body').catch(()=>{});
|
| 155 |
+
} catch (err) {}
|
| 156 |
+
|
| 157 |
} catch (e) {}
|
| 158 |
+
}, 1000);
|
| 159 |
|
| 160 |
} catch (e) {
|
| 161 |
clearTimeout(timeout);
|
|
|
|
| 164 |
});
|
| 165 |
}
|
| 166 |
|
|
|
|
| 167 |
async function handleTurnstile(page, url, siteKey) {
|
| 168 |
return new Promise(async (resolve, reject) => {
|
| 169 |
const timeout = setTimeout(() => reject(new Error("Timeout Turnstile")), 60000);
|