XORE21 commited on
Commit
bc15be9
·
verified ·
1 Parent(s): 85a0066

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +27 -32
index.js CHANGED
@@ -1,8 +1,6 @@
1
  const express = require('express');
2
  const cors = require('cors');
3
  const { connect } = require("puppeteer-real-browser");
4
- const path = require('path');
5
- const fs = require('fs');
6
 
7
  const app = express();
8
  app.use(cors());
@@ -24,7 +22,8 @@ async function createBrowser(proxy = null) {
24
  '--no-first-run',
25
  '--no-zygote',
26
  '--disable-gpu',
27
- '--window-size=1280,720'
 
28
  ],
29
  executablePath: process.env.CHROME_PATH || "/usr/bin/google-chrome-stable",
30
  customConfig: {},
@@ -46,19 +45,22 @@ async function createBrowser(proxy = null) {
46
 
47
  async function handleTurnstile(page, url, siteKey) {
48
  return new Promise(async (resolve, reject) => {
49
- const timeout = setTimeout(() => reject(new Error("Timeout waiting for Turnstile token")), 45000);
50
 
51
  try {
52
  const htmlContent = `
53
  <!DOCTYPE html>
54
- <html>
55
- <head><title>Turnstile</title></head>
 
 
 
 
56
  <body>
57
  <div class="cf-turnstile" data-sitekey="${siteKey}" data-callback="turnstileCallback"></div>
58
  <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
59
  <script>
60
  function turnstileCallback(token) {
61
- console.log("Token received");
62
  window.cf_token = token;
63
  }
64
  </script>
@@ -75,6 +77,11 @@ async function handleTurnstile(page, url, siteKey) {
75
  });
76
  });
77
 
 
 
 
 
 
78
  console.log(`[Turnstile] Navigating to ${url}`);
79
  await page.goto(url, { waitUntil: "domcontentloaded" });
80
 
@@ -86,9 +93,8 @@ async function handleTurnstile(page, url, siteKey) {
86
  clearTimeout(timeout);
87
  resolve({ token: token });
88
  }
89
- } catch (e) {
90
- }
91
- }, 500);
92
 
93
  } catch (e) {
94
  clearTimeout(timeout);
@@ -101,40 +107,30 @@ app.post('/bypass', async (req, res) => {
101
  const { url, mode, siteKey, proxy } = req.body;
102
 
103
  if (!url || !mode) return res.status(400).json({ status: "error", message: "Missing url or mode" });
 
 
 
104
 
105
  if (activeBrowsers >= MAX_CONCURRENT_BROWSERS) {
106
- return res.status(429).json({ status: "busy", message: "Server busy, try again in 5 seconds" });
107
  }
108
 
109
  activeBrowsers++;
110
  let browserInstance = null;
111
 
112
  try {
113
- console.log(`[REQ] Processing: ${url} | Mode: ${mode}`);
114
-
115
  const { browser, page } = await createBrowser(proxy);
116
  browserInstance = browser;
117
 
118
- let result;
119
- if (mode === 'turnstile') {
120
- if (!siteKey) throw new Error("siteKey required for turnstile");
121
- result = await handleTurnstile(page, url, siteKey);
122
- } else {
123
- throw new Error("Only 'turnstile' mode supported in this fix version");
124
- }
125
-
126
- console.log(`[SUCCESS] Token obtained for ${url}`);
127
  res.json({ status: "success", ...result });
128
 
129
  } catch (error) {
130
- console.error(`[CRITICAL ERROR]`, error);
131
-
132
- res.status(500).json({
133
- status: "error",
134
- message: error.message,
135
- stack: error.stack
136
- });
137
-
138
  } finally {
139
  if (browserInstance) {
140
  try { await browserInstance.close(); } catch {}
@@ -143,6 +139,5 @@ app.post('/bypass', async (req, res) => {
143
  }
144
  });
145
 
146
- app.get('/', (req, res) => res.send("M3M3K3 Server Running. Use POST /bypass"));
147
-
148
  app.listen(PORT, () => console.log(`Server listening on port ${PORT}`));
 
1
  const express = require('express');
2
  const cors = require('cors');
3
  const { connect } = require("puppeteer-real-browser");
 
 
4
 
5
  const app = express();
6
  app.use(cors());
 
22
  '--no-first-run',
23
  '--no-zygote',
24
  '--disable-gpu',
25
+ '--window-size=1920,1080',
26
+ '--disable-blink-features=AutomationControlled'
27
  ],
28
  executablePath: process.env.CHROME_PATH || "/usr/bin/google-chrome-stable",
29
  customConfig: {},
 
45
 
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
+ <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>
 
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" });
87
 
 
93
  clearTimeout(timeout);
94
  resolve({ token: token });
95
  }
96
+ } catch (e) {}
97
+ }, 1000);
 
98
 
99
  } catch (e) {
100
  clearTimeout(timeout);
 
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" });
116
  }
117
 
118
  activeBrowsers++;
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) {
132
+ console.error(`[ERROR] ${error.message}`);
133
+ res.status(500).json({ status: "error", message: error.message });
 
 
 
 
 
 
134
  } finally {
135
  if (browserInstance) {
136
  try { await browserInstance.close(); } catch {}
 
139
  }
140
  });
141
 
142
+ app.get('/', (req, res) => res.send("Server Running"));
 
143
  app.listen(PORT, () => console.log(`Server listening on port ${PORT}`));