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',
|
|
@@ -51,36 +51,19 @@ async function handleTurnstile(page, url, siteKey) {
|
|
| 51 |
const htmlContent = `
|
| 52 |
<!DOCTYPE html>
|
| 53 |
<html lang="en">
|
| 54 |
-
<head>
|
| 55 |
-
<meta charset="UTF-8">
|
| 56 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 57 |
-
<title>Turnstile Solver</title>
|
| 58 |
-
</head>
|
| 59 |
<body>
|
| 60 |
<div class="cf-turnstile" data-sitekey="${siteKey}" data-callback="turnstileCallback"></div>
|
| 61 |
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
| 62 |
-
<script>
|
| 63 |
-
function turnstileCallback(token) {
|
| 64 |
-
window.cf_token = token;
|
| 65 |
-
}
|
| 66 |
-
</script>
|
| 67 |
</body>
|
| 68 |
</html>
|
| 69 |
`;
|
| 70 |
|
| 71 |
await page.setRequestInterception(true);
|
| 72 |
page.once('request', request => {
|
| 73 |
-
request.respond({
|
| 74 |
-
status: 200,
|
| 75 |
-
contentType: 'text/html',
|
| 76 |
-
body: htmlContent
|
| 77 |
-
});
|
| 78 |
-
});
|
| 79 |
-
|
| 80 |
-
page.on('request', req => {
|
| 81 |
-
if (req.isInterceptResolutionHandled()) return;
|
| 82 |
-
req.continue();
|
| 83 |
});
|
|
|
|
| 84 |
|
| 85 |
console.log(`[Turnstile] Navigating to ${url}`);
|
| 86 |
await page.goto(url, { waitUntil: "domcontentloaded" });
|
|
@@ -103,13 +86,53 @@ async function handleTurnstile(page, url, siteKey) {
|
|
| 103 |
});
|
| 104 |
}
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
app.post('/bypass', async (req, res) => {
|
| 107 |
const { url, mode, siteKey, proxy } = req.body;
|
| 108 |
|
| 109 |
if (!url || !mode) return res.status(400).json({ status: "error", message: "Missing url or mode" });
|
| 110 |
-
if (mode === 'turnstile' && !siteKey) {
|
| 111 |
-
return res.status(400).json({ status: "error", message: "siteKey required for turnstile" });
|
| 112 |
-
}
|
| 113 |
|
| 114 |
if (activeBrowsers >= MAX_CONCURRENT_BROWSERS) {
|
| 115 |
return res.status(429).json({ status: "busy", message: "Server busy, try again later" });
|
|
@@ -119,13 +142,20 @@ app.post('/bypass', async (req, res) => {
|
|
| 119 |
let browserInstance = null;
|
| 120 |
|
| 121 |
try {
|
| 122 |
-
console.log(`[REQ] Processing: ${url}`);
|
| 123 |
const { browser, page } = await createBrowser(proxy);
|
| 124 |
browserInstance = browser;
|
| 125 |
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
console.log(`[SUCCESS]
|
| 129 |
res.json({ status: "success", ...result });
|
| 130 |
|
| 131 |
} catch (error) {
|
|
|
|
| 12 |
|
| 13 |
async function createBrowser(proxy = null) {
|
| 14 |
const options = {
|
| 15 |
+
headless: false,
|
| 16 |
turnstile: true,
|
| 17 |
args: [
|
| 18 |
'--no-sandbox',
|
|
|
|
| 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" });
|
|
|
|
| 86 |
});
|
| 87 |
}
|
| 88 |
|
| 89 |
+
async function handleCloudflare(page, url) {
|
| 90 |
+
return new Promise(async (resolve, reject) => {
|
| 91 |
+
const timeout = setTimeout(() => reject(new Error("Timeout waiting for Cloudflare clearance")), 60000);
|
| 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 checkSuccess = setInterval(async () => {
|
| 100 |
+
try {
|
| 101 |
+
const title = await page.title();
|
| 102 |
+
const content = await page.content();
|
| 103 |
+
|
| 104 |
+
if (!title.includes("Just a moment") && !content.includes("challenge-platform")) {
|
| 105 |
+
|
| 106 |
+
clearInterval(checkSuccess);
|
| 107 |
+
clearTimeout(timeout);
|
| 108 |
+
|
| 109 |
+
const cookies = await page.cookies();
|
| 110 |
+
const cfCookie = cookies.find(c => c.name === 'cf_clearance');
|
| 111 |
+
const userAgent = await page.evaluate(() => navigator.userAgent);
|
| 112 |
+
|
| 113 |
+
resolve({
|
| 114 |
+
status_code: httpCode,
|
| 115 |
+
cookie: cfCookie ? cfCookie.value : "",
|
| 116 |
+
userAgent: userAgent,
|
| 117 |
+
html: content,
|
| 118 |
+
title: title
|
| 119 |
+
});
|
| 120 |
+
}
|
| 121 |
+
} catch (e) {}
|
| 122 |
+
}, 1000);
|
| 123 |
+
|
| 124 |
+
} catch (e) {
|
| 125 |
+
clearTimeout(timeout);
|
| 126 |
+
reject(e);
|
| 127 |
+
}
|
| 128 |
+
});
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
app.post('/bypass', async (req, res) => {
|
| 132 |
const { url, mode, siteKey, proxy } = req.body;
|
| 133 |
|
| 134 |
if (!url || !mode) return res.status(400).json({ status: "error", message: "Missing url or mode" });
|
| 135 |
+
if (mode === 'turnstile' && !siteKey) return res.status(400).json({ status: "error", message: "siteKey required for turnstile" });
|
|
|
|
|
|
|
| 136 |
|
| 137 |
if (activeBrowsers >= MAX_CONCURRENT_BROWSERS) {
|
| 138 |
return res.status(429).json({ status: "busy", message: "Server busy, try again later" });
|
|
|
|
| 142 |
let browserInstance = null;
|
| 143 |
|
| 144 |
try {
|
| 145 |
+
console.log(`[REQ] Processing: ${url} | Mode: ${mode}`);
|
| 146 |
const { browser, page } = await createBrowser(proxy);
|
| 147 |
browserInstance = browser;
|
| 148 |
|
| 149 |
+
let result;
|
| 150 |
+
if (mode === 'turnstile') {
|
| 151 |
+
result = await handleTurnstile(page, url, siteKey);
|
| 152 |
+
} else if (mode === 'cloudflare') {
|
| 153 |
+
result = await handleCloudflare(page, url);
|
| 154 |
+
} else {
|
| 155 |
+
throw new Error("Invalid mode. Use 'turnstile' or 'cloudflare'");
|
| 156 |
+
}
|
| 157 |
|
| 158 |
+
console.log(`[SUCCESS] Operation completed for ${mode}`);
|
| 159 |
res.json({ status: "success", ...result });
|
| 160 |
|
| 161 |
} catch (error) {
|