brave-real-browser-mcp-server 2.19.19 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/navigation-handlers.js +30 -1
- package/dist/index.js +2 -6
- package/dist/patch-console.js +30 -0
- package/package.json +2 -2
|
@@ -22,7 +22,9 @@ export async function handleNavigate(args) {
|
|
|
22
22
|
waitUntil: waitUntil,
|
|
23
23
|
timeout: 60000
|
|
24
24
|
});
|
|
25
|
-
|
|
25
|
+
// Auto-handle Cloudflare challenges if detected
|
|
26
|
+
await waitForCloudflareBypass(pageInstance);
|
|
27
|
+
}, 90000, 'page-navigation');
|
|
26
28
|
// console.(`✅ Navigation successful to: ${url}`);
|
|
27
29
|
success = true;
|
|
28
30
|
break;
|
|
@@ -143,3 +145,30 @@ async function withWorkflowValidation(toolName, args, operation) {
|
|
|
143
145
|
throw error;
|
|
144
146
|
}
|
|
145
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Helper to wait for Cloudflare/Turnstile challenges to resolve
|
|
150
|
+
*/
|
|
151
|
+
async function waitForCloudflareBypass(pageInstance) {
|
|
152
|
+
try {
|
|
153
|
+
// Initial stable wait
|
|
154
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
155
|
+
const maxWait = 40000;
|
|
156
|
+
const startTime = Date.now();
|
|
157
|
+
while (Date.now() - startTime < maxWait) {
|
|
158
|
+
const isChallenge = await pageInstance.evaluate(() => {
|
|
159
|
+
const bodyText = (document.body?.innerText || '').toLowerCase();
|
|
160
|
+
// Strict checks to avoid false positives on normal sites
|
|
161
|
+
return bodyText.includes('verifying you are human') ||
|
|
162
|
+
bodyText.includes('checking your browser before accessing');
|
|
163
|
+
});
|
|
164
|
+
if (!isChallenge) {
|
|
165
|
+
return; // Not a challenge page, or passed
|
|
166
|
+
}
|
|
167
|
+
// Still blocked, wait
|
|
168
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
// Ignore bypass errors, continue to result
|
|
173
|
+
}
|
|
174
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* CRITICAL: Patch console.log to redirect to stderr
|
|
3
|
+
* CRITICAL: Patch console.log and stdout to redirect to stderr
|
|
4
4
|
* This ensures MCP stdio transport only receives valid JSON-RPC messages on stdout.
|
|
5
|
-
* All other logs (startup info, debug logs) should go to stderr.
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
console.log = function (...args) {
|
|
9
|
-
console.error(...args);
|
|
10
|
-
};
|
|
6
|
+
import './patch-console.js';
|
|
11
7
|
// Debug logging - only enabled if DEBUG=true environment variable is set
|
|
12
8
|
const DEBUG_ENABLED = process.env.DEBUG === 'true';
|
|
13
9
|
const debug = (...args) => {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// CRITICAL: This file must be imported BEFORE any other imports in index.ts
|
|
2
|
+
// to ensure we patch console and stdout before other modules capture them.
|
|
3
|
+
const originalConsoleLog = console.log;
|
|
4
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
5
|
+
// Redirect console.log to stderr
|
|
6
|
+
console.log = function (...args) {
|
|
7
|
+
console.error(...args);
|
|
8
|
+
};
|
|
9
|
+
// Patch process.stdout.write to filter non-JSON content
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
process.stdout.write = function (chunk, encoding, callback) {
|
|
12
|
+
// If arguments match the signature (chunk, encoding, cb) or (chunk, cb)
|
|
13
|
+
if (typeof encoding === 'function') {
|
|
14
|
+
callback = encoding;
|
|
15
|
+
encoding = undefined;
|
|
16
|
+
}
|
|
17
|
+
const str = String(chunk);
|
|
18
|
+
// Heuristic: valid MCP messages are JSON objects starting with '{'
|
|
19
|
+
// Logs usually start with text, brackets like [INFO], dates, etc.
|
|
20
|
+
if (str.trim().startsWith('{')) {
|
|
21
|
+
return originalStdoutWrite(chunk, encoding, callback);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// Redirect everything else to stderr
|
|
25
|
+
process.stderr.write(chunk, encoding, callback);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
console.error('✅ Console and Stdout patched successfully');
|
|
30
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-browser-mcp-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"description": "🦁 MCP server for Brave Real Browser - NPM Workspaces Monorepo with anti-detection features",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@modelcontextprotocol/sdk": "latest",
|
|
41
41
|
"@types/turndown": "latest",
|
|
42
|
-
"brave-real-browser": "^2.
|
|
42
|
+
"brave-real-browser": "^2.2.0",
|
|
43
43
|
"turndown": "latest"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|