brave-real-browser-mcp-server 2.41.6 → 2.41.8
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/lib/ocr-captcha-solver.js +31 -31
- package/package.json +2 -2
- package/packages/brave-real-blocker/package.json +2 -2
- package/packages/brave-real-blocker/src/brave-blocker.ts +20 -20
- package/packages/brave-real-blocker/src/filter-updater.ts +26 -26
- package/packages/brave-real-blocker/src/singleton.ts +8 -8
- package/packages/brave-real-launcher/package.json +2 -2
- package/packages/brave-real-playwright-core/package.json +1 -1
- package/packages/brave-real-puppeteer-core/index.js +19 -19
- package/packages/brave-real-puppeteer-core/package.json +2 -2
|
@@ -27,11 +27,11 @@ const colors = {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const log = {
|
|
30
|
-
info: (msg) => console.
|
|
31
|
-
success: (msg) => console.
|
|
32
|
-
warn: (msg) => console.
|
|
33
|
-
error: (msg) => console.
|
|
34
|
-
debug: (msg) => console.
|
|
30
|
+
info: (msg) => console.error(`${colors.blue}[ocr-captcha]${colors.reset} ${msg}`),
|
|
31
|
+
success: (msg) => console.error(`${colors.green}[ocr-captcha]${colors.reset} ✅ ${msg}`),
|
|
32
|
+
warn: (msg) => console.error(`${colors.yellow}[ocr-captcha]${colors.reset} ⚠️ ${msg}`),
|
|
33
|
+
error: (msg) => console.error(`${colors.red}[ocr-captcha]${colors.reset} ❌ ${msg}`),
|
|
34
|
+
debug: (msg) => console.error(`${colors.cyan}[ocr-captcha]${colors.reset} 🔍 ${msg}`)
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
// Common captcha character substitutions for correction
|
|
@@ -81,28 +81,28 @@ const PREPROCESS_CONFIGS = [
|
|
|
81
81
|
*/
|
|
82
82
|
async function preprocessImageAdvanced(page, selector, config = {}) {
|
|
83
83
|
const { threshold = 128, invert = false, removeLines = true } = config;
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
return await page.evaluate(({ sel, threshold, invert, removeLines }) => {
|
|
86
86
|
const img = document.querySelector(sel);
|
|
87
87
|
if (!img) return null;
|
|
88
88
|
|
|
89
89
|
const canvas = document.createElement('canvas');
|
|
90
90
|
const ctx = canvas.getContext('2d');
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
// Use natural dimensions for better quality
|
|
93
93
|
const width = img.naturalWidth || img.width || 200;
|
|
94
94
|
const height = img.naturalHeight || img.height || 50;
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
canvas.width = width;
|
|
97
97
|
canvas.height = height;
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
// Draw original image
|
|
100
100
|
ctx.drawImage(img, 0, 0, width, height);
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
// Get image data
|
|
103
103
|
const imageData = ctx.getImageData(0, 0, width, height);
|
|
104
104
|
const data = imageData.data;
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
// Step 1: Convert to grayscale
|
|
107
107
|
for (let i = 0; i < data.length; i += 4) {
|
|
108
108
|
const gray = 0.299 * data[i] + 0.587 * data[i + 1] + 0.114 * data[i + 2];
|
|
@@ -110,7 +110,7 @@ async function preprocessImageAdvanced(page, selector, config = {}) {
|
|
|
110
110
|
data[i + 1] = gray;
|
|
111
111
|
data[i + 2] = gray;
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
// Step 2: Remove diagonal lines (common in captchas)
|
|
115
115
|
if (removeLines) {
|
|
116
116
|
// Detect and remove thin lines
|
|
@@ -118,7 +118,7 @@ async function preprocessImageAdvanced(page, selector, config = {}) {
|
|
|
118
118
|
for (let x = 1; x < width - 1; x++) {
|
|
119
119
|
const idx = (y * width + x) * 4;
|
|
120
120
|
const pixel = data[idx];
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
// Check if this is a dark pixel
|
|
123
123
|
if (pixel < threshold) {
|
|
124
124
|
// Get surrounding pixels
|
|
@@ -126,14 +126,14 @@ async function preprocessImageAdvanced(page, selector, config = {}) {
|
|
|
126
126
|
const bottom = data[((y + 1) * width + x) * 4];
|
|
127
127
|
const left = data[(y * width + (x - 1)) * 4];
|
|
128
128
|
const right = data[(y * width + (x + 1)) * 4];
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
// Count dark neighbors
|
|
131
131
|
let darkNeighbors = 0;
|
|
132
132
|
if (top < threshold) darkNeighbors++;
|
|
133
133
|
if (bottom < threshold) darkNeighbors++;
|
|
134
134
|
if (left < threshold) darkNeighbors++;
|
|
135
135
|
if (right < threshold) darkNeighbors++;
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
// If isolated or thin line (≤2 dark neighbors), might be noise
|
|
138
138
|
if (darkNeighbors <= 1) {
|
|
139
139
|
// Make it white (remove noise)
|
|
@@ -145,22 +145,22 @@ async function preprocessImageAdvanced(page, selector, config = {}) {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
// Step 3: Apply threshold (binarization)
|
|
150
150
|
for (let i = 0; i < data.length; i += 4) {
|
|
151
151
|
const gray = data[i];
|
|
152
152
|
let bw = gray > threshold ? 255 : 0;
|
|
153
|
-
|
|
153
|
+
|
|
154
154
|
// Invert if needed
|
|
155
155
|
if (invert) bw = 255 - bw;
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
data[i] = bw;
|
|
158
158
|
data[i + 1] = bw;
|
|
159
159
|
data[i + 2] = bw;
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
ctx.putImageData(imageData, 0, 0);
|
|
163
|
-
|
|
163
|
+
|
|
164
164
|
return canvas.toDataURL('image/png');
|
|
165
165
|
}, { sel: selector, threshold, invert, removeLines });
|
|
166
166
|
}
|
|
@@ -178,7 +178,7 @@ async function getCaptchaImage(page, selector, preprocess = true, preprocessConf
|
|
|
178
178
|
return processed;
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
// Fallback: Screenshot of element
|
|
183
183
|
const element = await page.$(selector);
|
|
184
184
|
if (element) {
|
|
@@ -211,7 +211,7 @@ async function getCaptchaImage(page, selector, preprocess = true, preprocessConf
|
|
|
211
211
|
*/
|
|
212
212
|
async function recognizeText(imageData, config = {}) {
|
|
213
213
|
const worker = await Tesseract.createWorker(config.lang || 'eng');
|
|
214
|
-
|
|
214
|
+
|
|
215
215
|
try {
|
|
216
216
|
await worker.setParameters({
|
|
217
217
|
tessedit_char_whitelist: config.tessedit_char_whitelist || DEFAULT_OCR_CONFIG.tessedit_char_whitelist,
|
|
@@ -219,12 +219,12 @@ async function recognizeText(imageData, config = {}) {
|
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
const { data } = await worker.recognize(imageData);
|
|
222
|
-
|
|
222
|
+
|
|
223
223
|
// Clean up recognized text
|
|
224
224
|
let text = data.text
|
|
225
225
|
.replace(/\s+/g, '') // Remove whitespace
|
|
226
226
|
.replace(/[^a-zA-Z0-9]/g, ''); // Keep only alphanumeric
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
return {
|
|
229
229
|
text,
|
|
230
230
|
confidence: data.confidence,
|
|
@@ -259,17 +259,17 @@ async function solveTextCaptcha(page, selector, options = {}) {
|
|
|
259
259
|
|
|
260
260
|
for (const preprocessConfig of configsToTry) {
|
|
261
261
|
log.debug(`Trying preprocess config: ${preprocessConfig.name}`);
|
|
262
|
-
|
|
262
|
+
|
|
263
263
|
// Get preprocessed image
|
|
264
264
|
const imageData = await getCaptchaImage(page, selector, true, preprocessConfig);
|
|
265
|
-
|
|
265
|
+
|
|
266
266
|
if (!imageData) {
|
|
267
267
|
continue;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
// Try different PSM modes
|
|
271
271
|
const psmModes = ['7', '8', '13', '6']; // 7=single line, 8=word, 13=raw, 6=block
|
|
272
|
-
|
|
272
|
+
|
|
273
273
|
for (let i = 0; i < Math.min(retries, psmModes.length); i++) {
|
|
274
274
|
const config = {
|
|
275
275
|
...DEFAULT_OCR_CONFIG,
|
|
@@ -373,7 +373,7 @@ async function solveCaptchaAndFill(page, captchaSelector, inputSelector, options
|
|
|
373
373
|
|
|
374
374
|
let attempts = 0;
|
|
375
375
|
let lastResult = null;
|
|
376
|
-
|
|
376
|
+
|
|
377
377
|
log.info(`Starting captcha solve with ${maxRefreshAttempts} max attempts`);
|
|
378
378
|
|
|
379
379
|
while (attempts < maxRefreshAttempts) {
|
|
@@ -391,7 +391,7 @@ async function solveCaptchaAndFill(page, captchaSelector, inputSelector, options
|
|
|
391
391
|
confidence: minConfidence,
|
|
392
392
|
tryAllPreprocess: attempts <= 2, // Only try all configs on first 2 attempts
|
|
393
393
|
});
|
|
394
|
-
|
|
394
|
+
|
|
395
395
|
lastResult = result;
|
|
396
396
|
|
|
397
397
|
// Check if we got a usable result
|
|
@@ -448,7 +448,7 @@ async function solveCaptchaAndFill(page, captchaSelector, inputSelector, options
|
|
|
448
448
|
try {
|
|
449
449
|
await page.click(submitSelector);
|
|
450
450
|
await new Promise(r => setTimeout(r, 2000));
|
|
451
|
-
|
|
451
|
+
|
|
452
452
|
// Check if captcha was wrong
|
|
453
453
|
const stillOnPage = await page.$(captchaSelector);
|
|
454
454
|
const errorVisible = await page.evaluate(() => {
|
|
@@ -491,7 +491,7 @@ async function solveCaptchaAndFill(page, captchaSelector, inputSelector, options
|
|
|
491
491
|
*/
|
|
492
492
|
async function solveCaptchaFromUrl(imageUrl, options = {}) {
|
|
493
493
|
log.info(`Solving captcha from URL: ${imageUrl}`);
|
|
494
|
-
|
|
494
|
+
|
|
495
495
|
try {
|
|
496
496
|
const result = await recognizeText(imageUrl, {
|
|
497
497
|
...DEFAULT_OCR_CONFIG,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-browser-mcp-server",
|
|
3
|
-
"version": "2.41.
|
|
3
|
+
"version": "2.41.8",
|
|
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",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"license": "ISC",
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
77
|
-
"brave-real-puppeteer-core": "^24.37.1-brave.
|
|
77
|
+
"brave-real-puppeteer-core": "^24.37.1-brave.7",
|
|
78
78
|
"ghost-cursor": "^1.4.2",
|
|
79
79
|
"puppeteer-extra": "^3.3.6",
|
|
80
80
|
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-blocker",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.8",
|
|
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.37.1-brave.
|
|
67
|
+
"brave-real-puppeteer-core": "^24.37.1-brave.7",
|
|
68
68
|
"mocha": "^10.4.0",
|
|
69
69
|
"puppeteer-core": ">=24.0.0",
|
|
70
70
|
"sinon": "^17.0.1",
|
|
@@ -104,7 +104,7 @@ export class BraveBlocker {
|
|
|
104
104
|
|
|
105
105
|
constructor(options: BraveBlockerOptions = {}) {
|
|
106
106
|
this.options = options;
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
// Initialize filter updater if auto-update is enabled (default: true)
|
|
109
109
|
if (this.options.enableFilterAutoUpdate !== false) {
|
|
110
110
|
this.filterUpdater = getFilterUpdater({
|
|
@@ -119,26 +119,26 @@ export class BraveBlocker {
|
|
|
119
119
|
*/
|
|
120
120
|
async init() {
|
|
121
121
|
if (this.initialized) return;
|
|
122
|
-
|
|
122
|
+
|
|
123
123
|
try {
|
|
124
124
|
// Start with prebuilt lists as base
|
|
125
125
|
this.blocker = await PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch);
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
// Collect additional filter strings
|
|
128
128
|
let additionalFilters = BUILTIN_CUSTOM_FILTERS;
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
// Try to fetch latest filters using FilterUpdater (auto-update from uBlock Origin)
|
|
131
131
|
if (this.filterUpdater) {
|
|
132
132
|
try {
|
|
133
|
-
console.
|
|
133
|
+
console.error('[BraveBlocker] Fetching latest uBlock Origin filters...');
|
|
134
134
|
const latestFilters = await this.filterUpdater.getFilters();
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
if (latestFilters && latestFilters.length > 0) {
|
|
137
137
|
additionalFilters += '\n' + latestFilters;
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
const cacheInfo = this.filterUpdater.getCacheInfo();
|
|
140
|
-
console.
|
|
141
|
-
console.
|
|
140
|
+
console.error('[BraveBlocker] Loaded latest uBlock Origin filters');
|
|
141
|
+
console.error('[BraveBlocker] Cache expires:', cacheInfo.expiresAt?.toISOString());
|
|
142
142
|
}
|
|
143
143
|
} catch (filterError) {
|
|
144
144
|
console.warn('[BraveBlocker] Failed to fetch latest filters:', (filterError as Error).message);
|
|
@@ -149,19 +149,19 @@ export class BraveBlocker {
|
|
|
149
149
|
// No filter updater, use local custom filters only
|
|
150
150
|
additionalFilters += '\n' + this.loadLocalCustomFiltersString();
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
|
|
153
153
|
// Parse additional filters and enable them separately
|
|
154
154
|
// Note: We keep prebuilt as base and parse custom separately to avoid conflicts
|
|
155
155
|
try {
|
|
156
156
|
const customBlocker = await PuppeteerBlocker.parse(additionalFilters);
|
|
157
157
|
// Store for later reference but don't try to merge serialized data
|
|
158
|
-
console.
|
|
158
|
+
console.error('[BraveBlocker] Parsed additional filters successfully');
|
|
159
159
|
} catch (parseError) {
|
|
160
160
|
console.warn('[BraveBlocker] Failed to parse additional filters:', (parseError as Error).message);
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
this.initialized = true;
|
|
164
|
-
console.
|
|
164
|
+
console.error('[BraveBlocker] Initialized with ad blocking engine');
|
|
165
165
|
} catch (e) {
|
|
166
166
|
console.error('[BraveBlocker] Failed to initialize:', e);
|
|
167
167
|
// Fallback to basic blocker
|
|
@@ -169,18 +169,18 @@ export class BraveBlocker {
|
|
|
169
169
|
this.initialized = true;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
/**
|
|
174
174
|
* Load local custom filters as string
|
|
175
175
|
*/
|
|
176
176
|
private loadLocalCustomFiltersString(): string {
|
|
177
|
-
const customFiltersPath = this.options.customFiltersPath ||
|
|
177
|
+
const customFiltersPath = this.options.customFiltersPath ||
|
|
178
178
|
path.join(currentDir, '..', 'assets', 'ublock-custom-filters.txt');
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
try {
|
|
181
181
|
if (fs.existsSync(customFiltersPath)) {
|
|
182
182
|
const content = fs.readFileSync(customFiltersPath, 'utf-8');
|
|
183
|
-
console.
|
|
183
|
+
console.error('[BraveBlocker] Loaded custom filters from:', customFiltersPath);
|
|
184
184
|
return content;
|
|
185
185
|
}
|
|
186
186
|
} catch (e) {
|
|
@@ -231,10 +231,10 @@ export class BraveBlocker {
|
|
|
231
231
|
if (opts.enableRedirectBlocking) {
|
|
232
232
|
await injectRedirectBlocking(page);
|
|
233
233
|
}
|
|
234
|
-
|
|
235
|
-
console.
|
|
234
|
+
|
|
235
|
+
console.error('[BraveBlocker] All protections enabled for page');
|
|
236
236
|
}
|
|
237
|
-
|
|
237
|
+
|
|
238
238
|
/**
|
|
239
239
|
* Check if a URL should be blocked
|
|
240
240
|
*/
|
|
@@ -34,14 +34,14 @@ export const UBLOCK_FILTER_LISTS = {
|
|
|
34
34
|
ublock_unbreak: 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt',
|
|
35
35
|
ublock_quick_fixes: 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/quick-fixes.txt',
|
|
36
36
|
ublock_annoyances: 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/annoyances.txt',
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
// EasyList
|
|
39
39
|
easylist: 'https://easylist.to/easylist/easylist.txt',
|
|
40
40
|
easyprivacy: 'https://easylist.to/easylist/easyprivacy.txt',
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
// uBlock Origin scriptlets and resources
|
|
43
43
|
ublock_scriptlets: 'https://raw.githubusercontent.com/AzagraMac/nicholast-adblock-list/main/nicholast-adblock-list.txt',
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
// Anti-popup and anti-redirect lists
|
|
46
46
|
anti_popup: 'https://raw.githubusercontent.com/nicholast/nicholast-anti-popup-list/main/nicholast-anti-popup-list.txt',
|
|
47
47
|
anti_redirect: 'https://raw.githubusercontent.com/nicholast/nicholast-anti-redirect-list/main/nicholast-anti-redirect-list.txt',
|
|
@@ -82,7 +82,7 @@ const DEFAULT_OPTIONS: Required<FilterUpdaterOptions> = {
|
|
|
82
82
|
cacheExpiry: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
83
83
|
enabledLists: [
|
|
84
84
|
'ublock_filters',
|
|
85
|
-
'ublock_badware',
|
|
85
|
+
'ublock_badware',
|
|
86
86
|
'ublock_privacy',
|
|
87
87
|
'ublock_quick_fixes',
|
|
88
88
|
'ublock_annoyances',
|
|
@@ -132,7 +132,7 @@ export class FilterUpdater {
|
|
|
132
132
|
private saveCache(cache: FilterCache): void {
|
|
133
133
|
try {
|
|
134
134
|
fs.writeFileSync(this.cacheFilePath, JSON.stringify(cache, null, 2));
|
|
135
|
-
console.
|
|
135
|
+
console.error('[FilterUpdater] Cache saved successfully');
|
|
136
136
|
} catch (e) {
|
|
137
137
|
console.error('[FilterUpdater] Failed to save cache:', e);
|
|
138
138
|
}
|
|
@@ -143,16 +143,16 @@ export class FilterUpdater {
|
|
|
143
143
|
*/
|
|
144
144
|
private isCacheValid(): boolean {
|
|
145
145
|
if (this.options.forceUpdate) return false;
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
const cache = this.loadCache();
|
|
148
148
|
if (!cache) return false;
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
const now = Date.now();
|
|
151
151
|
if (now >= cache.expiresAt) {
|
|
152
|
-
console.
|
|
152
|
+
console.error('[FilterUpdater] Cache expired, will update');
|
|
153
153
|
return false;
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
this.cache = cache;
|
|
157
157
|
return true;
|
|
158
158
|
}
|
|
@@ -165,30 +165,30 @@ export class FilterUpdater {
|
|
|
165
165
|
try {
|
|
166
166
|
const controller = new AbortController();
|
|
167
167
|
const timeoutId = setTimeout(() => controller.abort(), this.options.fetchTimeout);
|
|
168
|
-
|
|
169
|
-
const response = await fetch(url, {
|
|
168
|
+
|
|
169
|
+
const response = await fetch(url, {
|
|
170
170
|
signal: controller.signal,
|
|
171
171
|
headers: {
|
|
172
172
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
|
|
173
173
|
}
|
|
174
174
|
});
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
clearTimeout(timeoutId);
|
|
177
|
-
|
|
177
|
+
|
|
178
178
|
if (!response.ok) {
|
|
179
179
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
const text = await response.text();
|
|
183
|
-
console.
|
|
183
|
+
console.error(`[FilterUpdater] Fetched ${name}: ${text.length} bytes`);
|
|
184
184
|
return text;
|
|
185
185
|
} catch (e: any) {
|
|
186
186
|
console.warn(`[FilterUpdater] Failed to fetch ${name} (attempt ${attempt + 1}):`, e.message);
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
// Try backup URL if available
|
|
189
189
|
const backupUrl = BACKUP_FILTER_LISTS[name as keyof typeof BACKUP_FILTER_LISTS];
|
|
190
190
|
if (attempt === retries && backupUrl) {
|
|
191
|
-
console.
|
|
191
|
+
console.error(`[FilterUpdater] Trying backup URL for ${name}`);
|
|
192
192
|
try {
|
|
193
193
|
const response = await fetch(backupUrl);
|
|
194
194
|
if (response.ok) {
|
|
@@ -198,11 +198,11 @@ export class FilterUpdater {
|
|
|
198
198
|
// Backup also failed
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
|
|
202
202
|
if (attempt === retries) {
|
|
203
203
|
return ''; // Return empty string on final failure
|
|
204
204
|
}
|
|
205
|
-
|
|
205
|
+
|
|
206
206
|
// Wait before retry
|
|
207
207
|
await new Promise(resolve => setTimeout(resolve, 1000 * (attempt + 1)));
|
|
208
208
|
}
|
|
@@ -217,7 +217,7 @@ export class FilterUpdater {
|
|
|
217
217
|
try {
|
|
218
218
|
if (fs.existsSync(this.options.customFiltersPath)) {
|
|
219
219
|
const content = fs.readFileSync(this.options.customFiltersPath, 'utf-8');
|
|
220
|
-
console.
|
|
220
|
+
console.error(`[FilterUpdater] Loaded custom filters: ${content.length} bytes`);
|
|
221
221
|
return content;
|
|
222
222
|
}
|
|
223
223
|
} catch (e) {
|
|
@@ -230,11 +230,11 @@ export class FilterUpdater {
|
|
|
230
230
|
* Fetch all enabled filter lists and combine them
|
|
231
231
|
*/
|
|
232
232
|
async updateFilters(): Promise<string> {
|
|
233
|
-
console.
|
|
234
|
-
|
|
233
|
+
console.error('[FilterUpdater] Starting filter update...');
|
|
234
|
+
|
|
235
235
|
// Check cache first
|
|
236
236
|
if (this.isCacheValid() && this.cache) {
|
|
237
|
-
console.
|
|
237
|
+
console.error('[FilterUpdater] Using cached filters (valid until:', new Date(this.cache.expiresAt).toISOString(), ')');
|
|
238
238
|
return this.cache.combinedFilters;
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -277,7 +277,7 @@ export class FilterUpdater {
|
|
|
277
277
|
this.cache = cache;
|
|
278
278
|
this.saveCache(cache);
|
|
279
279
|
|
|
280
|
-
console.
|
|
280
|
+
console.error(`[FilterUpdater] Updated filters: ${combinedFilters.length} bytes total`);
|
|
281
281
|
return combinedFilters;
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -334,7 +334,7 @@ ${content}
|
|
|
334
334
|
if (!cache) {
|
|
335
335
|
return { valid: false, expiresAt: null, lastUpdated: null };
|
|
336
336
|
}
|
|
337
|
-
|
|
337
|
+
|
|
338
338
|
return {
|
|
339
339
|
valid: Date.now() < cache.expiresAt,
|
|
340
340
|
expiresAt: new Date(cache.expiresAt),
|
|
@@ -349,7 +349,7 @@ ${content}
|
|
|
349
349
|
try {
|
|
350
350
|
if (fs.existsSync(this.cacheFilePath)) {
|
|
351
351
|
fs.unlinkSync(this.cacheFilePath);
|
|
352
|
-
console.
|
|
352
|
+
console.error('[FilterUpdater] Cache cleared');
|
|
353
353
|
}
|
|
354
354
|
} catch (e) {
|
|
355
355
|
console.error('[FilterUpdater] Failed to clear cache:', e);
|
|
@@ -38,16 +38,16 @@ if (!globalObj[SINGLETON_KEY]) {
|
|
|
38
38
|
*/
|
|
39
39
|
export function getBraveBlockerSingleton(options: BraveBlockerOptions = {}): BraveBlocker {
|
|
40
40
|
const storage = globalObj[SINGLETON_KEY];
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
if (!storage.instance) {
|
|
43
43
|
storage.instance = new BraveBlocker(options);
|
|
44
44
|
storage.options = options;
|
|
45
|
-
console.
|
|
45
|
+
console.error('[BraveBlocker] Created singleton instance');
|
|
46
46
|
} else if (Object.keys(options).length > 0 && !storage.initialized) {
|
|
47
47
|
// Allow updating options before initialization
|
|
48
|
-
console.
|
|
48
|
+
console.error('[BraveBlocker] Using existing singleton (options ignored after first creation)');
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
return storage.instance;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -60,13 +60,13 @@ export function getBraveBlockerSingleton(options: BraveBlockerOptions = {}): Bra
|
|
|
60
60
|
export async function initBraveBlockerSingleton(options: BraveBlockerOptions = {}): Promise<BraveBlocker> {
|
|
61
61
|
const storage = globalObj[SINGLETON_KEY];
|
|
62
62
|
const blocker = getBraveBlockerSingleton(options);
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
if (!storage.initialized) {
|
|
65
65
|
await blocker.init();
|
|
66
66
|
storage.initialized = true;
|
|
67
|
-
console.
|
|
67
|
+
console.error('[BraveBlocker] Singleton initialized successfully');
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
return blocker;
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -87,7 +87,7 @@ export function resetBraveBlockerSingleton(): void {
|
|
|
87
87
|
storage.instance = null;
|
|
88
88
|
storage.initialized = false;
|
|
89
89
|
storage.options = null;
|
|
90
|
-
console.
|
|
90
|
+
console.error('[BraveBlocker] Singleton reset');
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-launcher",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.8",
|
|
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.17.
|
|
57
|
+
"brave-real-blocker": "^1.17.8",
|
|
58
58
|
"escape-string-regexp": "^5.0.0",
|
|
59
59
|
"is-wsl": "^3.1.0",
|
|
60
60
|
"which": "^6.0.0"
|
|
@@ -32,7 +32,7 @@ export {
|
|
|
32
32
|
} from 'brave-real-launcher';
|
|
33
33
|
|
|
34
34
|
// Import stealth functions for easy integration
|
|
35
|
-
import {
|
|
35
|
+
import {
|
|
36
36
|
getComprehensiveStealthScript,
|
|
37
37
|
getPuppeteerOptimizedScript,
|
|
38
38
|
getPlaywrightOptimizedScript,
|
|
@@ -81,11 +81,11 @@ export async function applyStealthToPuppeteer(page, options = {}) {
|
|
|
81
81
|
comprehensiveStealth = true,
|
|
82
82
|
userAgent = null
|
|
83
83
|
} = options;
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
try {
|
|
86
86
|
// Get CDP session
|
|
87
87
|
const client = await page.target().createCDPSession();
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
// Apply CDP bypasses first (before any other scripts)
|
|
90
90
|
if (cdpBypasses) {
|
|
91
91
|
const cdpScript = getCDPBypassScripts();
|
|
@@ -94,7 +94,7 @@ export async function applyStealthToPuppeteer(page, options = {}) {
|
|
|
94
94
|
runImmediately: true
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
// Apply comprehensive stealth
|
|
99
99
|
if (comprehensiveStealth) {
|
|
100
100
|
const stealthScript = getPuppeteerOptimizedScript(options);
|
|
@@ -103,11 +103,11 @@ export async function applyStealthToPuppeteer(page, options = {}) {
|
|
|
103
103
|
runImmediately: true
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
|
|
107
107
|
// Set user agent if provided or use dynamic
|
|
108
108
|
const ua = userAgent || getDynamicUserAgent(false);
|
|
109
109
|
const uaMetadata = getDynamicUserAgentMetadata(false);
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
await client.send('Emulation.setUserAgentOverride', {
|
|
112
112
|
userAgent: ua,
|
|
113
113
|
userAgentMetadata: {
|
|
@@ -122,8 +122,8 @@ export async function applyStealthToPuppeteer(page, options = {}) {
|
|
|
122
122
|
wow64: uaMetadata.wow64
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
|
-
|
|
126
|
-
console.
|
|
125
|
+
|
|
126
|
+
console.error('[brave-real-puppeteer-core] Stealth applied to Puppeteer page');
|
|
127
127
|
return true;
|
|
128
128
|
} catch (error) {
|
|
129
129
|
console.error('[brave-real-puppeteer-core] Failed to apply stealth:', error.message);
|
|
@@ -149,20 +149,20 @@ export async function applyStealthToPlaywright(page, options = {}) {
|
|
|
149
149
|
comprehensiveStealth = true,
|
|
150
150
|
userAgent = null
|
|
151
151
|
} = options;
|
|
152
|
-
|
|
152
|
+
|
|
153
153
|
try {
|
|
154
154
|
// For Playwright, use addInitScript
|
|
155
155
|
if (cdpBypasses) {
|
|
156
156
|
const cdpScript = getCDPBypassScripts();
|
|
157
157
|
await page.addInitScript(cdpScript);
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
if (comprehensiveStealth) {
|
|
161
161
|
const stealthScript = getPlaywrightOptimizedScript(options);
|
|
162
162
|
await page.addInitScript(stealthScript);
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
console.
|
|
164
|
+
|
|
165
|
+
console.error('[brave-real-puppeteer-core] Stealth applied to Playwright page');
|
|
166
166
|
return true;
|
|
167
167
|
} catch (error) {
|
|
168
168
|
console.error('[brave-real-puppeteer-core] Failed to apply stealth:', error.message);
|
|
@@ -181,19 +181,19 @@ export async function applyStealthToPlaywrightContext(context, options = {}) {
|
|
|
181
181
|
cdpBypasses = true,
|
|
182
182
|
comprehensiveStealth = true
|
|
183
183
|
} = options;
|
|
184
|
-
|
|
184
|
+
|
|
185
185
|
try {
|
|
186
186
|
if (cdpBypasses) {
|
|
187
187
|
const cdpScript = getCDPBypassScripts();
|
|
188
188
|
await context.addInitScript(cdpScript);
|
|
189
189
|
}
|
|
190
|
-
|
|
190
|
+
|
|
191
191
|
if (comprehensiveStealth) {
|
|
192
192
|
const stealthScript = getPlaywrightOptimizedScript(options);
|
|
193
193
|
await context.addInitScript(stealthScript);
|
|
194
194
|
}
|
|
195
|
-
|
|
196
|
-
console.
|
|
195
|
+
|
|
196
|
+
console.error('[brave-real-puppeteer-core] Stealth applied to Playwright context');
|
|
197
197
|
return true;
|
|
198
198
|
} catch (error) {
|
|
199
199
|
console.error('[brave-real-puppeteer-core] Failed to apply stealth:', error.message);
|
|
@@ -209,18 +209,18 @@ export async function applyStealthToPlaywrightContext(context, options = {}) {
|
|
|
209
209
|
*/
|
|
210
210
|
export async function connectWithBlocker(options = {}, launchedBrave = null) {
|
|
211
211
|
const browser = await puppeteerCore.connect(options);
|
|
212
|
-
|
|
212
|
+
|
|
213
213
|
// If launchedBrave has blocker, setup ecosystem chain
|
|
214
214
|
if (launchedBrave?.blocker) {
|
|
215
215
|
launchedBrave.setupEcosystemChain?.(browser);
|
|
216
|
-
|
|
216
|
+
|
|
217
217
|
// Enable blocker on existing pages
|
|
218
218
|
const pages = await browser.pages();
|
|
219
219
|
for (const page of pages) {
|
|
220
220
|
await launchedBrave.enableBlockerOnPage?.(page);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
return {
|
|
225
225
|
browser,
|
|
226
226
|
blocker: launchedBrave?.blocker || null
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brave-real-puppeteer-core",
|
|
3
|
-
"version": "24.37.1-brave.
|
|
3
|
+
"version": "24.37.1-brave.7",
|
|
4
4
|
"description": "🦁 Brave Real-World Optimized Puppeteer & Playwright Core with 1-5ms ultra-fast timing, 50+ professional stealth features, intelligent browser auto-detection, and 100% bot detection bypass. Features cross-platform Brave browser integration, comprehensive anti-detection, and breakthrough performance improvements.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"test-version": "node ./scripts/test-version-management.js"
|
|
135
135
|
},
|
|
136
136
|
"dependencies": {
|
|
137
|
-
"brave-real-launcher": "^1.23.
|
|
137
|
+
"brave-real-launcher": "^1.23.8",
|
|
138
138
|
"get-east-asian-width": "^1.4.0",
|
|
139
139
|
"yargs": "^18.0.0"
|
|
140
140
|
},
|