XORE21 commited on
Commit
d07887a
·
verified ·
1 Parent(s): 08b3eb8

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +77 -111
index.js CHANGED
@@ -12,7 +12,7 @@ let activeBrowsers = 0;
12
 
13
  async function createBrowser(proxy = null) {
14
  const options = {
15
- headless: false, // WAJIB 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
- // === 1. RESPONSE SNIFFER (Menangkap Cookie dari Network) ===
60
- page.on("response", async (resp) => {
61
  try {
62
  const headers = resp.headers();
63
- const setCookie = headers["set-cookie"] || headers["Set-Cookie"];
64
- if (!setCookie) return;
65
-
66
- const raw = Array.isArray(setCookie) ? setCookie.join(" ") : setCookie;
67
-
68
- if (raw.toLowerCase().includes("cf_clearance")) {
69
- const m = raw.match(/cf_clearance=([^;]+)/);
70
- if (m && !cfValue) {
71
- cfValue = m[1];
72
- clearanceTime = Date.now();
73
- console.log("[CF] 🔥 cf_clearance captured via Network Listener!");
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
- // Backup: Cek storage browser jika listener terlewat
89
- if (cf && !cfValue) {
90
- cfValue = cf.value;
91
- clearanceTime = Date.now();
92
- console.log("[CF] cf_clearance found in Storage.");
93
  }
94
 
95
- // === 3. THE FIX: PAKSA RELOAD DENGAN COOKIE ===
96
- // Inilah yang hilang sebelumnya. Begitu cookie dapat, kita request ulang main page.
97
- if (cfValue && !usedForRequest) {
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
- // === 4. VALIDASI SUKSES (INTERNAL FETCH) ===
113
- // Kita tidak percaya Title. Kita percaya respons HTTP 200.
114
- if (usedForRequest) {
115
- const check = await page.evaluate(async (targetUrl) => {
116
- try {
117
- const r = await fetch(targetUrl, { method: "GET", credentials: "include" });
118
- return { status: r.status, url: r.url };
119
- } catch { return { status: 0, url: "" }; }
120
- }, url);
121
-
122
- const isChallenge = check.url.includes("challenge") || check.url.includes("turnstile");
123
-
124
- if (check.status === 200 && !isChallenge) {
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
- // === 5. CLICKER (Tetap Simpan untuk IP Kotor/Satoshi) ===
146
- // Kadang cookie belum keluar kalau belum diklik
147
- if (!cfValue) {
148
- const frames = page.frames();
149
- const challengeFrame = frames.find(f => f.url().includes("challenges.cloudflare.com") || f.url().includes("turnstile"));
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
- // === 6. FAILSAFE (Jika stuck lama banget tapi cookie ada) ===
174
- if (cfValue && Date.now() - clearanceTime > 30000) {
175
  clearInterval(loop);
176
  clearTimeout(timeout);
177
- console.log("[CF] ⚠️ Validation timeout, but cookie is present. Returning anyway.");
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
- title: await page.title()
 
 
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);