Update index.js
Browse files
index.js
CHANGED
|
@@ -94,7 +94,7 @@ async function handleCloudflare(page, url) {
|
|
| 94 |
content.includes("challenge-platform") ||
|
| 95 |
title.includes("Cloudflare");
|
| 96 |
|
| 97 |
-
if (!isChallengePage) {
|
| 98 |
clearInterval(loop);
|
| 99 |
clearTimeout(timeout);
|
| 100 |
const ua = await page.evaluate(() => navigator.userAgent);
|
|
@@ -110,18 +110,16 @@ async function handleCloudflare(page, url) {
|
|
| 110 |
}
|
| 111 |
|
| 112 |
if (cookieFoundTime > 0 && (currentTime - cookieFoundTime) > 5000 && !hasForcedNavigated) {
|
| 113 |
-
console.log("[Cloudflare] Cookie found but stuck
|
| 114 |
hasForcedNavigated = true;
|
| 115 |
-
|
| 116 |
-
await page.goto(url, { waitUntil: "networkidle0", timeout: 30000 }).catch(e => console.log("Nav error (ignored):", e.message));
|
| 117 |
return;
|
| 118 |
}
|
| 119 |
|
| 120 |
if (hasForcedNavigated && (currentTime - cookieFoundTime) > 20000) {
|
| 121 |
clearInterval(loop);
|
| 122 |
clearTimeout(timeout);
|
| 123 |
-
console.log("[Cloudflare] Giving up waiting for title change. Returning valid cookie
|
| 124 |
-
|
| 125 |
const ua = await page.evaluate(() => navigator.userAgent);
|
| 126 |
resolve({
|
| 127 |
status: "success",
|
|
@@ -133,8 +131,27 @@ async function handleCloudflare(page, url) {
|
|
| 133 |
return;
|
| 134 |
}
|
| 135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
try {
|
| 137 |
await page.mouse.move(Math.floor(Math.random() * 500), Math.floor(Math.random() * 500));
|
|
|
|
| 138 |
} catch (err) {}
|
| 139 |
|
| 140 |
} catch (e) {}
|
|
|
|
| 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);
|
|
|
|
| 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",
|
|
|
|
| 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) {}
|