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,19 +51,36 @@ async function handleTurnstile(page, url, siteKey) {
|
|
| 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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
</body>
|
| 59 |
</html>
|
| 60 |
`;
|
| 61 |
|
| 62 |
await page.setRequestInterception(true);
|
| 63 |
page.once('request', request => {
|
| 64 |
-
request.respond({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,86 +103,13 @@ async function handleTurnstile(page, url, siteKey) {
|
|
| 86 |
});
|
| 87 |
}
|
| 88 |
|
| 89 |
-
async function handleCloudflare(page, url) {
|
| 90 |
-
return new Promise(async (resolve, reject) => {
|
| 91 |
-
const timeout = setTimeout(() => {
|
| 92 |
-
reject(new Error("Timeout waiting for Cloudflare clearance"));
|
| 93 |
-
}, 60000);
|
| 94 |
-
|
| 95 |
-
try {
|
| 96 |
-
console.log(`[Cloudflare] Navigating to ${url}`);
|
| 97 |
-
|
| 98 |
-
const response = await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
|
| 99 |
-
const httpCode = response ? response.status() : 0;
|
| 100 |
-
|
| 101 |
-
const checkLoop = setInterval(async () => {
|
| 102 |
-
try {
|
| 103 |
-
const title = await page.title();
|
| 104 |
-
const content = await page.content();
|
| 105 |
-
|
| 106 |
-
if (title.includes("Attention Required") || title.includes("Just a moment") || content.includes("challenge-platform")) {
|
| 107 |
-
console.log("Stuck Cloudflare. Mencoba klik tengah & iframe...");
|
| 108 |
-
|
| 109 |
-
try {
|
| 110 |
-
const viewport = page.viewport();
|
| 111 |
-
const centerX = viewport.width / 2;
|
| 112 |
-
const centerY = viewport.height / 2;
|
| 113 |
-
|
| 114 |
-
await page.mouse.move(centerX, centerY);
|
| 115 |
-
await page.mouse.down();
|
| 116 |
-
await new Promise(r => setTimeout(r, 100));
|
| 117 |
-
await page.mouse.up();
|
| 118 |
-
|
| 119 |
-
const frames = page.frames();
|
| 120 |
-
for (const frame of frames) {
|
| 121 |
-
if (frame.url().includes("cloudflare") || frame.url().includes("turnstile")) {
|
| 122 |
-
try {
|
| 123 |
-
const box = await frame.boundingBox();
|
| 124 |
-
if (box) {
|
| 125 |
-
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
| 126 |
-
console.log(">> Klik Iframe Cloudflare berhasil!");
|
| 127 |
-
}
|
| 128 |
-
} catch(e) {}
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
} catch(e) {}
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
if (!title.includes("Just a moment") && !title.includes("Attention Required") && !content.includes("challenge-platform")) {
|
| 135 |
-
|
| 136 |
-
const cookies = await page.cookies();
|
| 137 |
-
const cfCookie = cookies.find(c => c.name === 'cf_clearance');
|
| 138 |
-
|
| 139 |
-
if (cfCookie) {
|
| 140 |
-
clearInterval(checkLoop);
|
| 141 |
-
clearTimeout(timeout);
|
| 142 |
-
|
| 143 |
-
const userAgent = await page.evaluate(() => navigator.userAgent);
|
| 144 |
-
resolve({
|
| 145 |
-
status: "success",
|
| 146 |
-
status_code: httpCode,
|
| 147 |
-
cookie: cfCookie.value,
|
| 148 |
-
userAgent: userAgent,
|
| 149 |
-
html: content,
|
| 150 |
-
title: title
|
| 151 |
-
});
|
| 152 |
-
}
|
| 153 |
-
}
|
| 154 |
-
} catch (e) {}
|
| 155 |
-
}, 2000);
|
| 156 |
-
|
| 157 |
-
} catch (e) {
|
| 158 |
-
clearTimeout(timeout);
|
| 159 |
-
reject(e);
|
| 160 |
-
}
|
| 161 |
-
});
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
app.post('/bypass', async (req, res) => {
|
| 165 |
const { url, mode, siteKey, proxy } = req.body;
|
| 166 |
|
| 167 |
if (!url || !mode) return res.status(400).json({ status: "error", message: "Missing url or mode" });
|
| 168 |
-
if (mode === 'turnstile' && !siteKey)
|
|
|
|
|
|
|
| 169 |
|
| 170 |
if (activeBrowsers >= MAX_CONCURRENT_BROWSERS) {
|
| 171 |
return res.status(429).json({ status: "busy", message: "Server busy, try again later" });
|
|
@@ -175,20 +119,13 @@ app.post('/bypass', async (req, res) => {
|
|
| 175 |
let browserInstance = null;
|
| 176 |
|
| 177 |
try {
|
| 178 |
-
console.log(`[REQ] Processing: ${url}
|
| 179 |
const { browser, page } = await createBrowser(proxy);
|
| 180 |
browserInstance = browser;
|
| 181 |
|
| 182 |
-
|
| 183 |
-
if (mode === 'turnstile') {
|
| 184 |
-
result = await handleTurnstile(page, url, siteKey);
|
| 185 |
-
} else if (mode === 'cloudflare') {
|
| 186 |
-
result = await handleCloudflare(page, url);
|
| 187 |
-
} else {
|
| 188 |
-
throw new Error("Invalid mode. Use 'turnstile' or 'cloudflare'");
|
| 189 |
-
}
|
| 190 |
|
| 191 |
-
console.log(`[SUCCESS]
|
| 192 |
res.json({ status: "success", ...result });
|
| 193 |
|
| 194 |
} 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 |
+
<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 |
});
|
| 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 |
let browserInstance = null;
|
| 120 |
|
| 121 |
try {
|
| 122 |
+
console.log(`[REQ] Processing: ${url}`);
|
| 123 |
const { browser, page } = await createBrowser(proxy);
|
| 124 |
browserInstance = browser;
|
| 125 |
|
| 126 |
+
const result = await handleTurnstile(page, url, siteKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
console.log(`[SUCCESS] Token obtained!`);
|
| 129 |
res.json({ status: "success", ...result });
|
| 130 |
|
| 131 |
} catch (error) {
|