brave-real-browser 1.5.97 → 1.5.98

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.
Files changed (2) hide show
  1. package/lib/cjs/errors.js +299 -0
  2. package/package.json +1 -1
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Error Handling System for Brave Real Browser
3
+ *
4
+ * Provides standardized error classes and utilities for browser operations
5
+ */
6
+
7
+ // ============================================================================
8
+ // ERROR CATEGORIES
9
+ // ============================================================================
10
+
11
+ const ErrorCategory = {
12
+ // Browser connection errors
13
+ CONNECTION_FAILED: 'CONNECTION_FAILED',
14
+ BROWSER_LAUNCH_FAILED: 'BROWSER_LAUNCH_FAILED',
15
+ BROWSER_CLOSED: 'BROWSER_CLOSED',
16
+
17
+ // Page errors
18
+ PAGE_CREATION_FAILED: 'PAGE_CREATION_FAILED',
19
+ PAGE_CLOSED: 'PAGE_CLOSED',
20
+
21
+ // Plugin errors
22
+ PLUGIN_LOAD_FAILED: 'PLUGIN_LOAD_FAILED',
23
+
24
+ // Proxy errors
25
+ PROXY_CONNECTION_FAILED: 'PROXY_CONNECTION_FAILED',
26
+ INVALID_PROXY_CONFIG: 'INVALID_PROXY_CONFIG',
27
+
28
+ // System errors
29
+ XVFB_INIT_FAILED: 'XVFB_INIT_FAILED',
30
+ PORT_UNAVAILABLE: 'PORT_UNAVAILABLE',
31
+
32
+ // Protocol errors
33
+ PROTOCOL_ERROR: 'PROTOCOL_ERROR',
34
+ TIMEOUT_ERROR: 'TIMEOUT_ERROR',
35
+
36
+ // Unknown
37
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR',
38
+ };
39
+
40
+ // ============================================================================
41
+ // ERROR SEVERITY LEVELS
42
+ // ============================================================================
43
+
44
+ const ErrorSeverity = {
45
+ LOW: 'LOW',
46
+ MEDIUM: 'MEDIUM',
47
+ HIGH: 'HIGH',
48
+ CRITICAL: 'CRITICAL',
49
+ };
50
+
51
+ // ============================================================================
52
+ // CUSTOM ERROR CLASS
53
+ // ============================================================================
54
+
55
+ /**
56
+ * Base error class for Brave Real Browser errors
57
+ */
58
+ class BraveRealBrowserError extends Error {
59
+ constructor(
60
+ message,
61
+ category = ErrorCategory.UNKNOWN_ERROR,
62
+ severity = ErrorSeverity.MEDIUM,
63
+ isRecoverable = false,
64
+ context = {}
65
+ ) {
66
+ super(message);
67
+ this.name = 'BraveRealBrowserError';
68
+ this.category = category;
69
+ this.severity = severity;
70
+ this.isRecoverable = isRecoverable;
71
+ this.timestamp = new Date();
72
+ this.context = context;
73
+
74
+ // Maintains proper stack trace
75
+ if (Error.captureStackTrace) {
76
+ Error.captureStackTrace(this, this.constructor);
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Convert error to user-friendly message
82
+ */
83
+ toUserMessage() {
84
+ let message = `āŒ ${this.message}\n\n`;
85
+ message += `šŸ“‹ Category: ${this.category}\n`;
86
+ message += `āš ļø Severity: ${this.severity}\n`;
87
+
88
+ if (Object.keys(this.context).length > 0) {
89
+ message += `\nšŸ” Context: ${JSON.stringify(this.context, null, 2)}\n`;
90
+ }
91
+
92
+ return message;
93
+ }
94
+ }
95
+
96
+ // ============================================================================
97
+ // ERROR FACTORY FUNCTIONS
98
+ // ============================================================================
99
+
100
+ /**
101
+ * Create browser launch error
102
+ */
103
+ function createBrowserLaunchError(originalError, context = {}) {
104
+ return new BraveRealBrowserError(
105
+ `Failed to launch browser: ${originalError.message}`,
106
+ ErrorCategory.BROWSER_LAUNCH_FAILED,
107
+ ErrorSeverity.CRITICAL,
108
+ false,
109
+ { originalError: originalError.message, ...context }
110
+ );
111
+ }
112
+
113
+ /**
114
+ * Create connection error
115
+ */
116
+ function createConnectionError(url, originalError) {
117
+ return new BraveRealBrowserError(
118
+ `Failed to connect to browser at ${url}: ${originalError.message}`,
119
+ ErrorCategory.CONNECTION_FAILED,
120
+ ErrorSeverity.CRITICAL,
121
+ true,
122
+ { url, originalError: originalError.message }
123
+ );
124
+ }
125
+
126
+ /**
127
+ * Create page creation error
128
+ */
129
+ function createPageCreationError(originalError) {
130
+ return new BraveRealBrowserError(
131
+ `Failed to create or access page: ${originalError.message}`,
132
+ ErrorCategory.PAGE_CREATION_FAILED,
133
+ ErrorSeverity.HIGH,
134
+ true,
135
+ { originalError: originalError.message }
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Create plugin load error
141
+ */
142
+ function createPluginLoadError(pluginName, originalError) {
143
+ return new BraveRealBrowserError(
144
+ `Failed to load plugin '${pluginName}': ${originalError.message}`,
145
+ ErrorCategory.PLUGIN_LOAD_FAILED,
146
+ ErrorSeverity.MEDIUM,
147
+ true,
148
+ { pluginName, originalError: originalError.message }
149
+ );
150
+ }
151
+
152
+ /**
153
+ * Create proxy error
154
+ */
155
+ function createProxyError(proxyConfig, originalError) {
156
+ return new BraveRealBrowserError(
157
+ `Proxy connection failed: ${originalError.message}`,
158
+ ErrorCategory.PROXY_CONNECTION_FAILED,
159
+ ErrorSeverity.HIGH,
160
+ true,
161
+ { proxyConfig, originalError: originalError.message }
162
+ );
163
+ }
164
+
165
+ /**
166
+ * Create XVFB initialization error
167
+ */
168
+ function createXvfbError(originalError) {
169
+ return new BraveRealBrowserError(
170
+ `Failed to initialize Xvfb: ${originalError.message}`,
171
+ ErrorCategory.XVFB_INIT_FAILED,
172
+ ErrorSeverity.MEDIUM,
173
+ false,
174
+ {
175
+ originalError: originalError.message,
176
+ suggestion: 'Install xvfb with: sudo apt-get install xvfb'
177
+ }
178
+ );
179
+ }
180
+
181
+ /**
182
+ * Create port unavailable error
183
+ */
184
+ function createPortUnavailableError(port) {
185
+ return new BraveRealBrowserError(
186
+ `Port ${port} is not available`,
187
+ ErrorCategory.PORT_UNAVAILABLE,
188
+ ErrorSeverity.HIGH,
189
+ true,
190
+ { port }
191
+ );
192
+ }
193
+
194
+ // ============================================================================
195
+ // ERROR CATEGORIZATION
196
+ // ============================================================================
197
+
198
+ /**
199
+ * Categorize a generic error into BraveRealBrowserError
200
+ */
201
+ function categorizeError(error) {
202
+ // Already a BraveRealBrowserError
203
+ if (error instanceof BraveRealBrowserError) {
204
+ return error;
205
+ }
206
+
207
+ // Convert to Error if not already
208
+ const err = error instanceof Error ? error : new Error(String(error));
209
+ const message = err.message.toLowerCase();
210
+
211
+ // Browser launch errors
212
+ if (message.includes('failed to launch') || message.includes('chrome') && message.includes('launch')) {
213
+ return createBrowserLaunchError(err);
214
+ }
215
+
216
+ // Connection errors
217
+ if (message.includes('econnrefused') || message.includes('connection refused')) {
218
+ return new BraveRealBrowserError(
219
+ err.message,
220
+ ErrorCategory.CONNECTION_FAILED,
221
+ ErrorSeverity.CRITICAL,
222
+ true,
223
+ { originalError: err.message }
224
+ );
225
+ }
226
+
227
+ // Protocol errors
228
+ if (message.includes('protocol error') || message.includes('target closed')) {
229
+ return new BraveRealBrowserError(
230
+ err.message,
231
+ ErrorCategory.PROTOCOL_ERROR,
232
+ ErrorSeverity.HIGH,
233
+ true,
234
+ { originalError: err.message }
235
+ );
236
+ }
237
+
238
+ // Timeout errors
239
+ if (message.includes('timeout')) {
240
+ return new BraveRealBrowserError(
241
+ err.message,
242
+ ErrorCategory.TIMEOUT_ERROR,
243
+ ErrorSeverity.MEDIUM,
244
+ true,
245
+ { originalError: err.message }
246
+ );
247
+ }
248
+
249
+ // Port errors
250
+ if (message.includes('eaddrinuse') || message.includes('address in use')) {
251
+ return new BraveRealBrowserError(
252
+ err.message,
253
+ ErrorCategory.PORT_UNAVAILABLE,
254
+ ErrorSeverity.HIGH,
255
+ true,
256
+ { originalError: err.message }
257
+ );
258
+ }
259
+
260
+ // Default unknown error
261
+ return new BraveRealBrowserError(
262
+ err.message,
263
+ ErrorCategory.UNKNOWN_ERROR,
264
+ ErrorSeverity.MEDIUM,
265
+ false,
266
+ { originalError: err.message, stack: err.stack }
267
+ );
268
+ }
269
+
270
+ /**
271
+ * Check if error is recoverable
272
+ */
273
+ function isRecoverableError(error) {
274
+ if (error instanceof BraveRealBrowserError) {
275
+ return error.isRecoverable;
276
+ }
277
+
278
+ const categorized = categorizeError(error);
279
+ return categorized.isRecoverable;
280
+ }
281
+
282
+ // ============================================================================
283
+ // EXPORTS
284
+ // ============================================================================
285
+
286
+ module.exports = {
287
+ ErrorCategory,
288
+ ErrorSeverity,
289
+ BraveRealBrowserError,
290
+ createBrowserLaunchError,
291
+ createConnectionError,
292
+ createPageCreationError,
293
+ createPluginLoadError,
294
+ createProxyError,
295
+ createXvfbError,
296
+ createPortUnavailableError,
297
+ categorizeError,
298
+ isRecoverableError,
299
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brave-real-browser",
3
- "version": "1.5.97",
3
+ "version": "1.5.98",
4
4
  "description": "This package is designed to bypass puppeteer's bot-detecting captchas such as Cloudflare. It acts like a real browser and can be managed with puppeteer.",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/esm/index.mjs",