brave-real-browser-mcp-server 2.37.4 → 2.37.7
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/.github/workflows/monorepo-publish.yml +5 -4
- package/package.json +2 -2
- package/packages/brave-real-blocker/package.json +2 -2
- package/packages/brave-real-launcher/package.json +2 -2
- package/packages/brave-real-launcher/src/chrome-version.ts +1 -1
- package/packages/brave-real-puppeteer-core/README.md +113 -20
- package/packages/brave-real-puppeteer-core/index.d.ts +122 -1
- package/packages/brave-real-puppeteer-core/index.es5.js +96 -0
- package/packages/brave-real-puppeteer-core/index.js +170 -0
- package/packages/brave-real-puppeteer-core/package.json +18 -16
- package/packages/brave-real-puppeteer-core/scripts/ai-agent.js +2 -2
- package/packages/brave-real-puppeteer-core/scripts/create-brave-package.js +1 -3
- package/packages/brave-real-puppeteer-core/scripts/manual-refresh-persistence.js +274 -0
- package/packages/brave-real-puppeteer-core/scripts/patcher.js +334 -206
- package/packages/brave-real-puppeteer-core/scripts/stealth-injector.js +250 -9
- package/packages/brave-real-puppeteer-core/scripts/test-bot-detector.js +1036 -0
- package/packages/brave-real-puppeteer-core/tsup.config.ts +28 -0
- package/packages/cache/filter-cache.json +15 -0
- package/scripts/version-bump.js +75 -12
- package/packages/brave-real-puppeteer-core/scripts/brave-package.js +0 -454
- package/packages/brave-real-puppeteer-core/scripts/enhanced-patcher.js +0 -442
|
@@ -67,18 +67,19 @@ jobs:
|
|
|
67
67
|
- name: 🔍 Detect Changes
|
|
68
68
|
id: changes
|
|
69
69
|
run: |
|
|
70
|
-
# For manual trigger
|
|
71
|
-
|
|
70
|
+
# For manual trigger, schedule, or push - publish all packages
|
|
71
|
+
# Push events already filtered by paths-ignore, so any push that reaches here has real changes
|
|
72
|
+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] || [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event_name }}" = "push" ]; then
|
|
72
73
|
echo "launcher=true" >> $GITHUB_OUTPUT
|
|
73
74
|
echo "puppeteer=true" >> $GITHUB_OUTPUT
|
|
74
75
|
echo "blocker=true" >> $GITHUB_OUTPUT
|
|
75
76
|
echo "mcp=true" >> $GITHUB_OUTPUT
|
|
76
77
|
echo "any=true" >> $GITHUB_OUTPUT
|
|
77
|
-
echo "📦
|
|
78
|
+
echo "📦 ${{ github.event_name }} trigger - all packages will be processed"
|
|
78
79
|
exit 0
|
|
79
80
|
fi
|
|
80
81
|
|
|
81
|
-
# For
|
|
82
|
+
# For PR only, detect actual changes
|
|
82
83
|
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
83
84
|
BASE_SHA=${{ github.event.pull_request.base.sha }}
|
|
84
85
|
else
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-browser-mcp-server",
|
|
3
|
-
"version": "2.37.
|
|
3
|
+
"version": "2.37.7",
|
|
4
4
|
"description": "MCP Server for Brave Real Browser - Puppeteer with Brave Browser, Stealth Mode, Ad Blocker, and Turnstile Auto-Solver for undetectable web automation.",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/esm/index.mjs",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"license": "ISC",
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
74
|
-
"brave-real-puppeteer-core": "^24.52.
|
|
74
|
+
"brave-real-puppeteer-core": "^24.52.9",
|
|
75
75
|
"ghost-cursor": "^1.4.2",
|
|
76
76
|
"puppeteer-extra": "^3.3.6",
|
|
77
77
|
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-blocker",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.9",
|
|
4
4
|
"description": "Advanced uBlock Origin management and stealth features for Brave Real Browser",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@types/adm-zip": "^0.5.5",
|
|
65
65
|
"@types/fs-extra": "^11.0.4",
|
|
66
66
|
"@types/node": "^20.0.0",
|
|
67
|
-
"brave-real-puppeteer-core": "^24.52.
|
|
67
|
+
"brave-real-puppeteer-core": "^24.52.9",
|
|
68
68
|
"mocha": "^10.4.0",
|
|
69
69
|
"puppeteer-core": "^24.35.0",
|
|
70
70
|
"sinon": "^17.0.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-launcher",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.9",
|
|
4
4
|
"description": "Launch Brave Browser with ease from node. Based on chrome-launcher with Brave-specific support.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"typescript": "^5.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"brave-real-blocker": "^1.13.
|
|
57
|
+
"brave-real-blocker": "^1.13.9",
|
|
58
58
|
"escape-string-regexp": "^5.0.0",
|
|
59
59
|
"is-wsl": "^3.1.0",
|
|
60
60
|
"which": "^6.0.0"
|
|
@@ -13,7 +13,7 @@ let cacheTimestamp: number = 0;
|
|
|
13
13
|
const CACHE_DURATION_MS = 60 * 60 * 1000; // 1 hour
|
|
14
14
|
|
|
15
15
|
// Fallback version if all APIs fail (updated to latest known stable)
|
|
16
|
-
export const FALLBACK_VERSION = '144.0.7559.
|
|
16
|
+
export const FALLBACK_VERSION = '144.0.7559.133';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Fetches the latest stable Chrome version from Chromium Dashboard API
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
- ⚡ **1-5ms Ultra-Fast Timing** - Optimized performance
|
|
9
9
|
- 🦁 **Brave Browser Integration** - Auto-detection on all platforms
|
|
10
10
|
- 🤖 **AI-Powered Testing** - Intelligent validation
|
|
11
|
-
- 🔄 **
|
|
12
|
-
- 🎭 **CAPTCHA Handling** - Built-in solver support
|
|
11
|
+
- 🔄 **Version Sync** - Check for latest Puppeteer/Playwright releases
|
|
13
12
|
- 📱 **Device Emulation** - Mobile and tablet emulation
|
|
14
13
|
- 🌍 **Geo Spoofing** - Location spoofing
|
|
15
14
|
- 🖱️ **Human Mouse** - Realistic mouse movements
|
|
@@ -37,11 +36,6 @@ npm test # Run 8 unit tests
|
|
|
37
36
|
npm run test-bot-detector # GUI bot detection test
|
|
38
37
|
npm run test-bot-detector-headless # Headless bot detection test
|
|
39
38
|
npm run test-bot-detector-mobile # Mobile bot detection test
|
|
40
|
-
npm run test-puppeteer # Puppeteer tests
|
|
41
|
-
npm run test-playwright # Playwright tests
|
|
42
|
-
npm run test-cloudflare # Cloudflare bypass test
|
|
43
|
-
npm run test-recaptcha # reCAPTCHA test
|
|
44
|
-
npm run test-features # All features test
|
|
45
39
|
npm run ai-agent # AI-powered testing
|
|
46
40
|
```
|
|
47
41
|
|
|
@@ -79,8 +73,7 @@ brave-real-puppeteer-core/
|
|
|
79
73
|
│ ├── playwright-core/ # Playwright patches
|
|
80
74
|
│ └── stealth-core/ # Core stealth patches
|
|
81
75
|
├── scripts/
|
|
82
|
-
│ ├── patcher.js # Main patcher (CLI)
|
|
83
|
-
│ ├── enhanced-patcher.js # Comprehensive patching
|
|
76
|
+
│ ├── patcher.js # Main patcher with stealth (CLI)
|
|
84
77
|
│ ├── stealth-injector.js # 131KB stealth code
|
|
85
78
|
│ ├── ai-agent.js # AI testing assistant
|
|
86
79
|
│ ├── test-bot-detector.js # Bot detection tests
|
|
@@ -90,7 +83,7 @@ brave-real-puppeteer-core/
|
|
|
90
83
|
│ ├── human_mouse.js # Human-like mouse
|
|
91
84
|
│ ├── session-manager.js # Session management
|
|
92
85
|
│ ├── proxy-manager.js # Proxy rotation
|
|
93
|
-
│ └── ...
|
|
86
|
+
│ └── ...21 total scripts
|
|
94
87
|
└── test/
|
|
95
88
|
└── test.cjs # Unit tests (8 tests)
|
|
96
89
|
```
|
|
@@ -112,31 +105,44 @@ brave-real-puppeteer-core/
|
|
|
112
105
|
|
|
113
106
|
| Category | Features |
|
|
114
107
|
|----------|----------|
|
|
108
|
+
| **CDP Bypasses** | Runtime.Enable, sourceURL masking, Console.enable, exposeFunction |
|
|
115
109
|
| Navigator | webdriver, plugins, languages, userAgentData |
|
|
116
110
|
| Canvas | Fingerprint noise, toDataURL spoofing |
|
|
117
111
|
| WebGL | GPU profiles, renderer spoofing |
|
|
118
112
|
| Performance | 1-5ms timing, instant responses |
|
|
119
113
|
| Automation | All bot signatures removed |
|
|
120
114
|
| Mouse | Human-like movements (ghost-cursor) |
|
|
121
|
-
| CAPTCHA | Auto-solving support |
|
|
122
115
|
| Geolocation | Location spoofing |
|
|
123
116
|
|
|
124
117
|
## 💡 Usage
|
|
125
118
|
|
|
126
|
-
###
|
|
119
|
+
### Easy Integration (Recommended)
|
|
120
|
+
|
|
121
|
+
#### Puppeteer - One-Liner
|
|
127
122
|
```javascript
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
import puppeteer from 'puppeteer-core';
|
|
124
|
+
import { applyStealthToPuppeteer } from 'brave-real-puppeteer-core';
|
|
130
125
|
|
|
131
|
-
const browser = await puppeteer.launch({
|
|
132
|
-
executablePath: '/path/to/brave',
|
|
133
|
-
headless: false
|
|
134
|
-
});
|
|
126
|
+
const browser = await puppeteer.launch({ executablePath: '/path/to/brave' });
|
|
135
127
|
const page = await browser.newPage();
|
|
136
|
-
await page
|
|
128
|
+
await applyStealthToPuppeteer(page); // That's it!
|
|
129
|
+
|
|
130
|
+
await page.goto('https://bot-detector.rebrowser.net/');
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Playwright - One-Liner
|
|
134
|
+
```javascript
|
|
135
|
+
import { chromium } from 'playwright-core';
|
|
136
|
+
import { applyStealthToPlaywright } from 'brave-real-puppeteer-core';
|
|
137
|
+
|
|
138
|
+
const browser = await chromium.launch({ executablePath: '/path/to/brave' });
|
|
139
|
+
const page = await browser.newPage();
|
|
140
|
+
await applyStealthToPlaywright(page); // That's it!
|
|
141
|
+
|
|
142
|
+
await page.goto('https://bot-detector.rebrowser.net/');
|
|
137
143
|
```
|
|
138
144
|
|
|
139
|
-
### With brave-real-browser (
|
|
145
|
+
### With brave-real-browser (Full Integration)
|
|
140
146
|
```javascript
|
|
141
147
|
const { connect } = require('brave-real-browser');
|
|
142
148
|
|
|
@@ -148,6 +154,19 @@ const { browser, page } = await connect({
|
|
|
148
154
|
await page.goto('https://example.com');
|
|
149
155
|
```
|
|
150
156
|
|
|
157
|
+
### Manual Puppeteer
|
|
158
|
+
```javascript
|
|
159
|
+
const puppeteer = require('puppeteer-core');
|
|
160
|
+
// Patches are auto-applied at npm install time
|
|
161
|
+
|
|
162
|
+
const browser = await puppeteer.launch({
|
|
163
|
+
executablePath: '/path/to/brave',
|
|
164
|
+
headless: false
|
|
165
|
+
});
|
|
166
|
+
const page = await browser.newPage();
|
|
167
|
+
await page.goto('https://bot.sannysoft.com');
|
|
168
|
+
```
|
|
169
|
+
|
|
151
170
|
## 🔧 Environment Variables
|
|
152
171
|
|
|
153
172
|
```bash
|
|
@@ -163,6 +182,80 @@ REBROWSER_ULTRA_FAST_PERFORMANCE=1
|
|
|
163
182
|
- **Datadome**: 100% pass
|
|
164
183
|
- **Cloudflare Turnstile**: ✅ Auto-solved
|
|
165
184
|
- **reCAPTCHA v3**: High score
|
|
185
|
+
- **Bot Detector**: 80% pass (8/10 tests) - All critical tests pass
|
|
186
|
+
|
|
187
|
+
## 📦 Module Support
|
|
188
|
+
|
|
189
|
+
This package supports multiple module formats for maximum compatibility:
|
|
190
|
+
|
|
191
|
+
| Format | File | Usage | Node.js Version |
|
|
192
|
+
|--------|------|-------|-----------------|
|
|
193
|
+
| **ESM** | `index.js` | Modern JavaScript (ES6+) | 18+ (Recommended) |
|
|
194
|
+
| **CJS** | `index.cjs` | CommonJS | 12+ |
|
|
195
|
+
| **ES5** | N/A | Legacy JavaScript | 10+ (Requires build) |
|
|
196
|
+
|
|
197
|
+
### Usage Examples
|
|
198
|
+
|
|
199
|
+
#### ESM (Recommended for Node.js 18+)
|
|
200
|
+
```javascript
|
|
201
|
+
import puppeteer from 'brave-real-puppeteer-core';
|
|
202
|
+
const browser = await puppeteer.launch();
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### CJS (For Node.js 12-17)
|
|
206
|
+
```javascript
|
|
207
|
+
const puppeteer = require('brave-real-puppeteer-core');
|
|
208
|
+
const browser = await puppeteer.launch();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### ES5 Support
|
|
212
|
+
|
|
213
|
+
ES5 support requires additional transpilation setup. The package targets Node.js 18+ which natively supports ES6+ features, so ES5 transpilation is not required for the default use case.
|
|
214
|
+
|
|
215
|
+
**To add ES5 support:**
|
|
216
|
+
1. Install Babel: `npm install --save-dev @babel/core @babel/preset-env`
|
|
217
|
+
2. Create `.babelrc`:
|
|
218
|
+
```json
|
|
219
|
+
{
|
|
220
|
+
"presets": [["@babel/preset-env", {
|
|
221
|
+
"targets": {
|
|
222
|
+
"node": "10"
|
|
223
|
+
}
|
|
224
|
+
}]]
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
3. Add build script to package.json:
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"scripts": {
|
|
231
|
+
"build:es5": "babel index.js --out-file index.es5.js"
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## 🔄 Refresh Persistence
|
|
237
|
+
|
|
238
|
+
The package includes robust refresh persistence to ensure stealth scripts survive page refreshes:
|
|
239
|
+
|
|
240
|
+
- **CDP Scripts**: Automatically injected on every new document
|
|
241
|
+
- **Manual Refresh Handler**: Re-injects scripts after F5 refresh
|
|
242
|
+
- **Lifecycle Monitoring**: Monitors page visibility and load events
|
|
243
|
+
- **Error Stack Sanitization**: Persists across refreshes for sourceUrlLeak test
|
|
244
|
+
- **Continuous Monitoring**: Active monitoring for 60 seconds after page load
|
|
245
|
+
|
|
246
|
+
### Testing Refresh Persistence
|
|
247
|
+
|
|
248
|
+
Run the bot detector test to verify refresh persistence:
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
npm run test-bot-detector
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
The test will:
|
|
255
|
+
1. Navigate to https://bot-detector.rebrowser.net/
|
|
256
|
+
2. Wait for all tests to pass (initial load)
|
|
257
|
+
3. Refresh the page (F5)
|
|
258
|
+
4. Verify all critical tests still pass after refresh
|
|
166
259
|
|
|
167
260
|
## 📄 License
|
|
168
261
|
|
|
@@ -1,4 +1,125 @@
|
|
|
1
|
+
// Re-export everything from puppeteer-core
|
|
1
2
|
export * from 'puppeteer-core';
|
|
2
|
-
import { PuppeteerNode } from 'puppeteer-core';
|
|
3
|
+
import { PuppeteerNode, Page as PuppeteerPage } from 'puppeteer-core';
|
|
3
4
|
declare const puppeteer: PuppeteerNode;
|
|
4
5
|
export default puppeteer;
|
|
6
|
+
|
|
7
|
+
// Stealth Options
|
|
8
|
+
export interface StealthOptions {
|
|
9
|
+
/** Enable CDP-level bypasses (Runtime.Enable, sourceURL, etc.) Default: true */
|
|
10
|
+
cdpBypasses?: boolean;
|
|
11
|
+
/** Enable comprehensive JS-level stealth. Default: true */
|
|
12
|
+
comprehensiveStealth?: boolean;
|
|
13
|
+
/** Custom user agent string. Default: auto-generated */
|
|
14
|
+
userAgent?: string | null;
|
|
15
|
+
/** Enable mobile simulation. Default: false */
|
|
16
|
+
mobile?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Easy Integration APIs
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Apply stealth to a Puppeteer page - One-liner API
|
|
23
|
+
* @param page - Puppeteer page instance
|
|
24
|
+
* @param options - Stealth options
|
|
25
|
+
* @returns Promise resolving to true on success
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* import { applyStealthToPuppeteer } from 'brave-real-puppeteer-core';
|
|
29
|
+
* const browser = await puppeteer.launch();
|
|
30
|
+
* const page = await browser.newPage();
|
|
31
|
+
* await applyStealthToPuppeteer(page);
|
|
32
|
+
*/
|
|
33
|
+
export function applyStealthToPuppeteer(page: PuppeteerPage, options?: StealthOptions): Promise<boolean>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Apply stealth to a Playwright page - One-liner API
|
|
37
|
+
* @param page - Playwright page instance
|
|
38
|
+
* @param options - Stealth options
|
|
39
|
+
* @returns Promise resolving to true on success
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* import { applyStealthToPlaywright } from 'brave-real-puppeteer-core';
|
|
43
|
+
* const browser = await chromium.launch();
|
|
44
|
+
* const page = await browser.newPage();
|
|
45
|
+
* await applyStealthToPlaywright(page);
|
|
46
|
+
*/
|
|
47
|
+
export function applyStealthToPlaywright(page: any, options?: StealthOptions): Promise<boolean>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Apply stealth to a Playwright browser context - For all pages
|
|
51
|
+
* @param context - Playwright browser context
|
|
52
|
+
* @param options - Stealth options
|
|
53
|
+
*/
|
|
54
|
+
export function applyStealthToPlaywrightContext(context: any, options?: StealthOptions): Promise<boolean>;
|
|
55
|
+
|
|
56
|
+
// Stealth Script Generators
|
|
57
|
+
|
|
58
|
+
/** Get comprehensive stealth script */
|
|
59
|
+
export function getComprehensiveStealthScript(): string;
|
|
60
|
+
|
|
61
|
+
/** Get Puppeteer-optimized stealth script */
|
|
62
|
+
export function getPuppeteerOptimizedScript(options?: StealthOptions): string;
|
|
63
|
+
|
|
64
|
+
/** Get Playwright-optimized stealth script */
|
|
65
|
+
export function getPlaywrightOptimizedScript(options?: StealthOptions): string;
|
|
66
|
+
|
|
67
|
+
/** Get all CDP bypass scripts combined */
|
|
68
|
+
export function getCDPBypassScripts(): string;
|
|
69
|
+
|
|
70
|
+
// Individual CDP Bypass Functions
|
|
71
|
+
|
|
72
|
+
/** Runtime.Enable bypass - Prevents CDP Runtime.Enable detection */
|
|
73
|
+
export function injectRuntimeEnableBypass(): string;
|
|
74
|
+
|
|
75
|
+
/** Source URL masking - Hides pptr:/playwright: sourceURL comments */
|
|
76
|
+
export function injectSourceURLMasking(): string;
|
|
77
|
+
|
|
78
|
+
/** Console.enable bypass - Masks Console.enable CDP command detection */
|
|
79
|
+
export function injectConsoleEnableBypass(): string;
|
|
80
|
+
|
|
81
|
+
/** ExposeFunction masking - Hides page.exposeFunction bindings */
|
|
82
|
+
export function injectExposeFunctionMasking(): string;
|
|
83
|
+
|
|
84
|
+
/** Utility World Name masking - Hides __puppeteer_utility_world__ */
|
|
85
|
+
export function injectUtilityWorldMasking(): string;
|
|
86
|
+
|
|
87
|
+
// Dynamic Chrome Version
|
|
88
|
+
|
|
89
|
+
/** Get current Chrome version (auto-synced with Google APIs) */
|
|
90
|
+
export function getCurrentChromeVersion(): string;
|
|
91
|
+
|
|
92
|
+
/** Generate dynamic User-Agent string */
|
|
93
|
+
export function getDynamicUserAgent(mobile?: boolean): string;
|
|
94
|
+
|
|
95
|
+
/** Generate dynamic User-Agent metadata for Client Hints */
|
|
96
|
+
export function getDynamicUserAgentMetadata(mobile?: boolean): {
|
|
97
|
+
brands: Array<{ brand: string; version: string }>;
|
|
98
|
+
fullVersionList: Array<{ brand: string; version: string }>;
|
|
99
|
+
platform: string;
|
|
100
|
+
platformVersion: string;
|
|
101
|
+
architecture: string;
|
|
102
|
+
model: string;
|
|
103
|
+
mobile: boolean;
|
|
104
|
+
bitness: string;
|
|
105
|
+
wow64: boolean;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Blocker Integration (from brave-real-launcher)
|
|
109
|
+
export function initBlocker(): Promise<any>;
|
|
110
|
+
export function getBlocker(): any;
|
|
111
|
+
export function createBlockerFactory(): any;
|
|
112
|
+
export function autoEnableOnPage(page: any): Promise<void>;
|
|
113
|
+
export function createEcosystemChain(browser: any): any;
|
|
114
|
+
export const BraveBlocker: any;
|
|
115
|
+
export function launch(options?: any): Promise<any>;
|
|
116
|
+
export const DEFAULT_FLAGS: string[];
|
|
117
|
+
export const BraveLauncher: any;
|
|
118
|
+
export function getStealthFlags(): string[];
|
|
119
|
+
export function getDynamicUserAgents(): any;
|
|
120
|
+
|
|
121
|
+
// Connect with Blocker
|
|
122
|
+
export function connectWithBlocker(options?: any, launchedBrave?: any): Promise<{
|
|
123
|
+
browser: any;
|
|
124
|
+
blocker: any | null;
|
|
125
|
+
}>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* brave-real-puppeteer-core (ES5 Compatible)
|
|
3
|
+
* Re-exports puppeteer-core with stealth patches applied at install time
|
|
4
|
+
* Compatible with older Node.js environments and bundlers
|
|
5
|
+
*
|
|
6
|
+
* Ecosystem Chain:
|
|
7
|
+
* brave-real-browser-mcp-server (top level)
|
|
8
|
+
* --> brave-real-puppeteer-core (you are here)
|
|
9
|
+
* --> brave-real-launcher
|
|
10
|
+
* --> brave-real-blocker (singleton)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
// Re-export everything from puppeteer-core
|
|
16
|
+
var puppeteerCore = require('puppeteer-core');
|
|
17
|
+
|
|
18
|
+
// Re-export blocker integration from brave-real-launcher for ecosystem chain
|
|
19
|
+
var braveLauncher = require('brave-real-launcher');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Connect to browser with auto-enabled blocker on all pages
|
|
23
|
+
* @param {Object} options - Connection options
|
|
24
|
+
* @param {Object} launchedBrave - LaunchedBrave instance from brave-real-launcher
|
|
25
|
+
* @returns {Promise<{browser: Browser, blocker: BlockerInstance}>}
|
|
26
|
+
*/
|
|
27
|
+
function connectWithBlocker(options, launchedBrave) {
|
|
28
|
+
options = options || {};
|
|
29
|
+
launchedBrave = launchedBrave || null;
|
|
30
|
+
|
|
31
|
+
return puppeteerCore.connect(options).then(function(browser) {
|
|
32
|
+
// If launchedBrave has blocker, setup ecosystem chain
|
|
33
|
+
if (launchedBrave && launchedBrave.blocker) {
|
|
34
|
+
if (typeof launchedBrave.setupEcosystemChain === 'function') {
|
|
35
|
+
launchedBrave.setupEcosystemChain(browser);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Enable blocker on existing pages
|
|
39
|
+
return browser.pages().then(function(pages) {
|
|
40
|
+
var enablePromises = pages.map(function(page) {
|
|
41
|
+
if (typeof launchedBrave.enableBlockerOnPage === 'function') {
|
|
42
|
+
return launchedBrave.enableBlockerOnPage(page);
|
|
43
|
+
}
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return Promise.all(enablePromises).then(function() {
|
|
48
|
+
return {
|
|
49
|
+
browser: browser,
|
|
50
|
+
blocker: launchedBrave.blocker
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
browser: browser,
|
|
58
|
+
blocker: null
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Launch browser using brave-real-launcher (ES5 compatible wrapper)
|
|
65
|
+
* @param {Object} options - Launch options
|
|
66
|
+
* @returns {Promise<LaunchedBrave>}
|
|
67
|
+
*/
|
|
68
|
+
function launch(options) {
|
|
69
|
+
options = options || {};
|
|
70
|
+
return braveLauncher.launch(options);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Export all functions from puppeteer-core
|
|
74
|
+
var exports = Object.keys(puppeteerCore).reduce(function(acc, key) {
|
|
75
|
+
acc[key] = puppeteerCore[key];
|
|
76
|
+
return acc;
|
|
77
|
+
}, {});
|
|
78
|
+
|
|
79
|
+
// Add ecosystem chain exports
|
|
80
|
+
exports.initBlocker = braveLauncher.initBlocker;
|
|
81
|
+
exports.getBlocker = braveLauncher.getBlocker;
|
|
82
|
+
exports.createBlockerFactory = braveLauncher.createBlockerFactory;
|
|
83
|
+
exports.autoEnableOnPage = braveLauncher.autoEnableOnPage;
|
|
84
|
+
exports.createEcosystemChain = braveLauncher.createEcosystemChain;
|
|
85
|
+
exports.BraveBlocker = braveLauncher.BraveBlocker;
|
|
86
|
+
exports.launch = launch;
|
|
87
|
+
exports.DEFAULT_FLAGS = braveLauncher.DEFAULT_FLAGS;
|
|
88
|
+
exports.BraveLauncher = braveLauncher.BraveLauncher;
|
|
89
|
+
exports.getStealthFlags = braveLauncher.getStealthFlags;
|
|
90
|
+
exports.getDynamicUserAgents = braveLauncher.getDynamicUserAgents;
|
|
91
|
+
exports.connectWithBlocker = connectWithBlocker;
|
|
92
|
+
|
|
93
|
+
// Default export for ES5
|
|
94
|
+
exports.default = puppeteerCore;
|
|
95
|
+
|
|
96
|
+
module.exports = exports;
|
|
@@ -31,6 +31,176 @@ export {
|
|
|
31
31
|
getDynamicUserAgents
|
|
32
32
|
} from 'brave-real-launcher';
|
|
33
33
|
|
|
34
|
+
// Import stealth functions for easy integration
|
|
35
|
+
import {
|
|
36
|
+
getComprehensiveStealthScript,
|
|
37
|
+
getPuppeteerOptimizedScript,
|
|
38
|
+
getPlaywrightOptimizedScript,
|
|
39
|
+
getCDPBypassScripts,
|
|
40
|
+
injectRuntimeEnableBypass,
|
|
41
|
+
injectSourceURLMasking,
|
|
42
|
+
injectConsoleEnableBypass,
|
|
43
|
+
injectExposeFunctionMasking,
|
|
44
|
+
injectUtilityWorldMasking,
|
|
45
|
+
getCurrentChromeVersion,
|
|
46
|
+
getDynamicUserAgent,
|
|
47
|
+
getDynamicUserAgentMetadata
|
|
48
|
+
} from './scripts/stealth-injector.js';
|
|
49
|
+
|
|
50
|
+
// Re-export stealth functions
|
|
51
|
+
export {
|
|
52
|
+
getComprehensiveStealthScript,
|
|
53
|
+
getPuppeteerOptimizedScript,
|
|
54
|
+
getPlaywrightOptimizedScript,
|
|
55
|
+
getCDPBypassScripts,
|
|
56
|
+
injectRuntimeEnableBypass,
|
|
57
|
+
injectSourceURLMasking,
|
|
58
|
+
injectConsoleEnableBypass,
|
|
59
|
+
injectExposeFunctionMasking,
|
|
60
|
+
injectUtilityWorldMasking,
|
|
61
|
+
getCurrentChromeVersion,
|
|
62
|
+
getDynamicUserAgent,
|
|
63
|
+
getDynamicUserAgentMetadata
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Apply stealth to a Puppeteer page - One-liner API
|
|
68
|
+
* @param {Page} page - Puppeteer page instance
|
|
69
|
+
* @param {Object} options - Stealth options
|
|
70
|
+
* @returns {Promise<void>}
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* import { applyStealthToPuppeteer } from 'brave-real-puppeteer-core';
|
|
74
|
+
* const browser = await puppeteer.launch();
|
|
75
|
+
* const page = await browser.newPage();
|
|
76
|
+
* await applyStealthToPuppeteer(page);
|
|
77
|
+
*/
|
|
78
|
+
export async function applyStealthToPuppeteer(page, options = {}) {
|
|
79
|
+
const {
|
|
80
|
+
cdpBypasses = true,
|
|
81
|
+
comprehensiveStealth = true,
|
|
82
|
+
userAgent = null
|
|
83
|
+
} = options;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
// Get CDP session
|
|
87
|
+
const client = await page.target().createCDPSession();
|
|
88
|
+
|
|
89
|
+
// Apply CDP bypasses first (before any other scripts)
|
|
90
|
+
if (cdpBypasses) {
|
|
91
|
+
const cdpScript = getCDPBypassScripts();
|
|
92
|
+
await client.send('Page.addScriptToEvaluateOnNewDocument', {
|
|
93
|
+
source: cdpScript,
|
|
94
|
+
runImmediately: true
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Apply comprehensive stealth
|
|
99
|
+
if (comprehensiveStealth) {
|
|
100
|
+
const stealthScript = getPuppeteerOptimizedScript(options);
|
|
101
|
+
await client.send('Page.addScriptToEvaluateOnNewDocument', {
|
|
102
|
+
source: stealthScript,
|
|
103
|
+
runImmediately: true
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Set user agent if provided or use dynamic
|
|
108
|
+
const ua = userAgent || getDynamicUserAgent(false);
|
|
109
|
+
const uaMetadata = getDynamicUserAgentMetadata(false);
|
|
110
|
+
|
|
111
|
+
await client.send('Emulation.setUserAgentOverride', {
|
|
112
|
+
userAgent: ua,
|
|
113
|
+
userAgentMetadata: {
|
|
114
|
+
brands: uaMetadata.brands,
|
|
115
|
+
fullVersionList: uaMetadata.fullVersionList,
|
|
116
|
+
platform: uaMetadata.platform,
|
|
117
|
+
platformVersion: uaMetadata.platformVersion,
|
|
118
|
+
architecture: uaMetadata.architecture,
|
|
119
|
+
model: uaMetadata.model,
|
|
120
|
+
mobile: uaMetadata.mobile,
|
|
121
|
+
bitness: uaMetadata.bitness,
|
|
122
|
+
wow64: uaMetadata.wow64
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
console.log('[brave-real-puppeteer-core] Stealth applied to Puppeteer page');
|
|
127
|
+
return true;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error('[brave-real-puppeteer-core] Failed to apply stealth:', error.message);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Apply stealth to a Playwright page - One-liner API
|
|
136
|
+
* @param {Page} page - Playwright page instance
|
|
137
|
+
* @param {Object} options - Stealth options
|
|
138
|
+
* @returns {Promise<void>}
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* import { applyStealthToPlaywright } from 'brave-real-puppeteer-core';
|
|
142
|
+
* const browser = await chromium.launch();
|
|
143
|
+
* const page = await browser.newPage();
|
|
144
|
+
* await applyStealthToPlaywright(page);
|
|
145
|
+
*/
|
|
146
|
+
export async function applyStealthToPlaywright(page, options = {}) {
|
|
147
|
+
const {
|
|
148
|
+
cdpBypasses = true,
|
|
149
|
+
comprehensiveStealth = true,
|
|
150
|
+
userAgent = null
|
|
151
|
+
} = options;
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
// For Playwright, use addInitScript
|
|
155
|
+
if (cdpBypasses) {
|
|
156
|
+
const cdpScript = getCDPBypassScripts();
|
|
157
|
+
await page.addInitScript(cdpScript);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (comprehensiveStealth) {
|
|
161
|
+
const stealthScript = getPlaywrightOptimizedScript(options);
|
|
162
|
+
await page.addInitScript(stealthScript);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log('[brave-real-puppeteer-core] Stealth applied to Playwright page');
|
|
166
|
+
return true;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error('[brave-real-puppeteer-core] Failed to apply stealth:', error.message);
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Apply stealth to a Playwright context - For all pages in context
|
|
175
|
+
* @param {BrowserContext} context - Playwright browser context
|
|
176
|
+
* @param {Object} options - Stealth options
|
|
177
|
+
* @returns {Promise<void>}
|
|
178
|
+
*/
|
|
179
|
+
export async function applyStealthToPlaywrightContext(context, options = {}) {
|
|
180
|
+
const {
|
|
181
|
+
cdpBypasses = true,
|
|
182
|
+
comprehensiveStealth = true
|
|
183
|
+
} = options;
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
if (cdpBypasses) {
|
|
187
|
+
const cdpScript = getCDPBypassScripts();
|
|
188
|
+
await context.addInitScript(cdpScript);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (comprehensiveStealth) {
|
|
192
|
+
const stealthScript = getPlaywrightOptimizedScript(options);
|
|
193
|
+
await context.addInitScript(stealthScript);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
console.log('[brave-real-puppeteer-core] Stealth applied to Playwright context');
|
|
197
|
+
return true;
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error('[brave-real-puppeteer-core] Failed to apply stealth:', error.message);
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
34
204
|
/**
|
|
35
205
|
* Connect to browser with auto-enabled blocker on all pages
|
|
36
206
|
* @param {Object} options - Connection options
|