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',
|
|
@@ -46,78 +46,69 @@ async function createBrowser(proxy = null) {
|
|
| 46 |
async function handleTurnstile(page, url, siteKey) {
|
| 47 |
return new Promise(async (resolve, reject) => {
|
| 48 |
const timeout = setTimeout(() => reject(new Error("Timeout waiting for Turnstile token")), 60000);
|
| 49 |
-
|
| 50 |
try {
|
| 51 |
-
const htmlContent =
|
| 52 |
-
<!DOCTYPE html>
|
| 53 |
-
<html lang="en">
|
| 54 |
-
<body>
|
| 55 |
-
<div class="cf-turnstile" data-sitekey="${siteKey}" data-callback="turnstileCallback"></div>
|
| 56 |
-
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
| 57 |
-
<script>function turnstileCallback(token) { window.cf_token = token; }</script>
|
| 58 |
-
</body>
|
| 59 |
-
</html>
|
| 60 |
-
`;
|
| 61 |
-
|
| 62 |
await page.setRequestInterception(true);
|
| 63 |
-
page.once('request', request => {
|
| 64 |
-
request.respond({ status: 200, contentType: 'text/html', body: htmlContent });
|
| 65 |
-
});
|
| 66 |
page.on('request', req => { if (req.isInterceptResolutionHandled()) return; req.continue(); });
|
| 67 |
-
|
| 68 |
console.log(`[Turnstile] Navigating to ${url}`);
|
| 69 |
await page.goto(url, { waitUntil: "domcontentloaded" });
|
| 70 |
|
| 71 |
const checkToken = setInterval(async () => {
|
| 72 |
try {
|
| 73 |
const token = await page.evaluate(() => window.cf_token);
|
| 74 |
-
if (token) {
|
| 75 |
-
clearInterval(checkToken);
|
| 76 |
-
clearTimeout(timeout);
|
| 77 |
-
resolve({ token: token });
|
| 78 |
-
}
|
| 79 |
} catch (e) {}
|
| 80 |
}, 1000);
|
| 81 |
-
|
| 82 |
-
} catch (e) {
|
| 83 |
-
clearTimeout(timeout);
|
| 84 |
-
reject(e);
|
| 85 |
-
}
|
| 86 |
});
|
| 87 |
}
|
| 88 |
|
| 89 |
async function handleCloudflare(page, url) {
|
| 90 |
return new Promise(async (resolve, reject) => {
|
| 91 |
-
const timeout = setTimeout(() => reject(new Error("Timeout
|
| 92 |
|
| 93 |
try {
|
| 94 |
console.log(`[Cloudflare] Navigating to ${url}`);
|
| 95 |
-
|
| 96 |
-
const response = await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 97 |
-
const httpCode = response ? response.status() : 0;
|
| 98 |
|
| 99 |
-
const
|
| 100 |
try {
|
| 101 |
const title = await page.title();
|
| 102 |
const content = await page.content();
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
| 107 |
clearTimeout(timeout);
|
| 108 |
|
| 109 |
const cookies = await page.cookies();
|
| 110 |
-
const
|
| 111 |
-
const
|
|
|
|
|
|
|
| 112 |
|
| 113 |
resolve({
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
title: title
|
| 119 |
});
|
|
|
|
| 120 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
} catch (e) {}
|
| 122 |
}, 1000);
|
| 123 |
|
|
|
|
| 12 |
|
| 13 |
async function createBrowser(proxy = null) {
|
| 14 |
const options = {
|
| 15 |
+
headless: false,
|
| 16 |
turnstile: true,
|
| 17 |
args: [
|
| 18 |
'--no-sandbox',
|
|
|
|
| 46 |
async function handleTurnstile(page, url, siteKey) {
|
| 47 |
return new Promise(async (resolve, reject) => {
|
| 48 |
const timeout = setTimeout(() => reject(new Error("Timeout waiting for Turnstile token")), 60000);
|
|
|
|
| 49 |
try {
|
| 50 |
+
const htmlContent = `<!DOCTYPE html><html lang="en"><body><div class="cf-turnstile" data-sitekey="${siteKey}" data-callback="turnstileCallback"></div><script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script><script>function turnstileCallback(token) { window.cf_token = token; }</script></body></html>`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
await page.setRequestInterception(true);
|
| 52 |
+
page.once('request', request => request.respond({ status: 200, contentType: 'text/html', body: htmlContent }));
|
|
|
|
|
|
|
| 53 |
page.on('request', req => { if (req.isInterceptResolutionHandled()) return; req.continue(); });
|
| 54 |
+
|
| 55 |
console.log(`[Turnstile] Navigating to ${url}`);
|
| 56 |
await page.goto(url, { waitUntil: "domcontentloaded" });
|
| 57 |
|
| 58 |
const checkToken = setInterval(async () => {
|
| 59 |
try {
|
| 60 |
const token = await page.evaluate(() => window.cf_token);
|
| 61 |
+
if (token) { clearInterval(checkToken); clearTimeout(timeout); resolve({ token: token }); }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
} catch (e) {}
|
| 63 |
}, 1000);
|
| 64 |
+
} catch (e) { clearTimeout(timeout); reject(e); }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
});
|
| 66 |
}
|
| 67 |
|
| 68 |
async function handleCloudflare(page, url) {
|
| 69 |
return new Promise(async (resolve, reject) => {
|
| 70 |
+
const timeout = setTimeout(() => reject(new Error("Timeout Cloudflare Bypass")), 60000);
|
| 71 |
|
| 72 |
try {
|
| 73 |
console.log(`[Cloudflare] Navigating to ${url}`);
|
| 74 |
+
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
const loop = setInterval(async () => {
|
| 77 |
try {
|
| 78 |
const title = await page.title();
|
| 79 |
const content = await page.content();
|
| 80 |
+
|
| 81 |
+
const isChallengePage = title.includes("Just a moment") ||
|
| 82 |
+
content.includes("challenge-platform") ||
|
| 83 |
+
title.includes("Cloudflare");
|
| 84 |
+
|
| 85 |
+
if (!isChallengePage) {
|
| 86 |
+
clearInterval(loop);
|
| 87 |
clearTimeout(timeout);
|
| 88 |
|
| 89 |
const cookies = await page.cookies();
|
| 90 |
+
const ua = await page.evaluate(() => navigator.userAgent);
|
| 91 |
+
const cfClearance = cookies.find(c => c.name === 'cf_clearance');
|
| 92 |
+
|
| 93 |
+
console.log(`[Cloudflare] Success! (Clearance: ${cfClearance ? "Yes" : "Session"})`);
|
| 94 |
|
| 95 |
resolve({
|
| 96 |
+
status: "success",
|
| 97 |
+
userAgent: ua,
|
| 98 |
+
cookies_full: cookies,
|
| 99 |
+
cookie: cfClearance ? cfClearance.value : "",
|
| 100 |
title: title
|
| 101 |
});
|
| 102 |
+
return;
|
| 103 |
}
|
| 104 |
+
|
| 105 |
+
try {
|
| 106 |
+
await page.mouse.move(
|
| 107 |
+
Math.floor(Math.random() * 500),
|
| 108 |
+
Math.floor(Math.random() * 500)
|
| 109 |
+
);
|
| 110 |
+
} catch (err) {}
|
| 111 |
+
|
| 112 |
} catch (e) {}
|
| 113 |
}, 1000);
|
| 114 |
|