Update index.js
Browse files
index.js
CHANGED
|
@@ -58,7 +58,6 @@ async function handleCloudflare(page, url) {
|
|
| 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')) {
|
|
@@ -109,14 +108,18 @@ async function handleCloudflare(page, url) {
|
|
| 109 |
return;
|
| 110 |
}
|
| 111 |
|
| 112 |
-
if (cookieFoundTime > 0 && (currentTime - cookieFoundTime) >
|
| 113 |
console.log("[Cloudflare] Cookie found but stuck. Performing FORCE NAVIGATION...");
|
| 114 |
hasForcedNavigated = true;
|
| 115 |
-
await page.goto(url, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
return;
|
| 117 |
}
|
| 118 |
|
| 119 |
-
if (hasForcedNavigated && (currentTime - cookieFoundTime) >
|
| 120 |
clearInterval(loop);
|
| 121 |
clearTimeout(timeout);
|
| 122 |
console.log("[Cloudflare] Giving up waiting for title change. Returning valid cookie.");
|
|
@@ -131,27 +134,43 @@ async function handleCloudflare(page, url) {
|
|
| 131 |
return;
|
| 132 |
}
|
| 133 |
|
| 134 |
-
const
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
const
|
| 140 |
-
|
| 141 |
-
const
|
| 142 |
-
if (
|
| 143 |
-
|
| 144 |
-
|
| 145 |
}
|
| 146 |
-
} else {
|
| 147 |
-
await challengeFrame.click('body').catch(()=>{});
|
| 148 |
}
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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) {}
|
|
|
|
| 58 |
try {
|
| 59 |
const headers = resp.headers();
|
| 60 |
const setCookie = headers['set-cookie'] || headers['Set-Cookie'] || headers['set-cookie'.toLowerCase()];
|
|
|
|
| 61 |
if (setCookie) {
|
| 62 |
const cookieStr = Array.isArray(setCookie) ? setCookie.join(' ') : setCookie;
|
| 63 |
if (cookieStr.includes('cf_clearance')) {
|
|
|
|
| 108 |
return;
|
| 109 |
}
|
| 110 |
|
| 111 |
+
if (cookieFoundTime > 0 && (currentTime - cookieFoundTime) > 8000 && !hasForcedNavigated) {
|
| 112 |
console.log("[Cloudflare] Cookie found but stuck. Performing FORCE NAVIGATION...");
|
| 113 |
hasForcedNavigated = true;
|
| 114 |
+
await page.goto(url, {
|
| 115 |
+
waitUntil: "domcontentloaded",
|
| 116 |
+
timeout: 30000,
|
| 117 |
+
referer: url
|
| 118 |
+
}).catch(()=>{});
|
| 119 |
return;
|
| 120 |
}
|
| 121 |
|
| 122 |
+
if (hasForcedNavigated && (currentTime - cookieFoundTime) > 25000) {
|
| 123 |
clearInterval(loop);
|
| 124 |
clearTimeout(timeout);
|
| 125 |
console.log("[Cloudflare] Giving up waiting for title change. Returning valid cookie.");
|
|
|
|
| 134 |
return;
|
| 135 |
}
|
| 136 |
|
| 137 |
+
const clicked = await page.evaluate(async () => {
|
| 138 |
+
function queryShadowDeep(root, selector) {
|
| 139 |
+
if (!root) return null;
|
| 140 |
+
let found = root.querySelector(selector);
|
| 141 |
+
if (found) return found;
|
| 142 |
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, null, false);
|
| 143 |
+
while (walker.nextNode()) {
|
| 144 |
+
const node = walker.currentNode;
|
| 145 |
+
if (node.shadowRoot) {
|
| 146 |
+
found = queryShadowDeep(node.shadowRoot, selector);
|
| 147 |
+
if (found) return found;
|
| 148 |
}
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
+
return null;
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
const checkbox = queryShadowDeep(document.body, "input[type='checkbox']");
|
| 154 |
+
if (checkbox && !checkbox.checked) {
|
| 155 |
+
checkbox.click();
|
| 156 |
+
return "shadow-click";
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
const widget = document.querySelector('.cf-turnstile') || document.querySelector('#turnstile-wrapper');
|
| 160 |
+
if (widget) {
|
| 161 |
+
widget.click();
|
| 162 |
+
return "widget-click";
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
return false;
|
| 166 |
+
});
|
| 167 |
+
|
| 168 |
+
if (clicked) {
|
| 169 |
+
console.log(`[Cloudflare] Interactive Widget Clicked! (${clicked})`);
|
| 170 |
}
|
| 171 |
|
| 172 |
try {
|
| 173 |
await page.mouse.move(Math.floor(Math.random() * 500), Math.floor(Math.random() * 500));
|
|
|
|
| 174 |
} catch (err) {}
|
| 175 |
|
| 176 |
} catch (e) {}
|