arn-browser 0.0.3 → 0.0.5

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 (67) hide show
  1. package/README.md +3 -2
  2. package/package.json +31 -47
  3. package/src/all_routes/routeWithSuperagent.d.ts +67 -0
  4. package/src/all_routes/routeWithSuperagent.js +322 -0
  5. package/src/human-cursor/HumanCursor.js +448 -0
  6. package/src/human-cursor/bezier.js +248 -0
  7. package/src/human-cursor/index.d.ts +154 -0
  8. package/src/human-cursor/index.js +9 -0
  9. package/src/human-cursor/randomizer.js +149 -0
  10. package/src/human-cursor/tweening.js +260 -0
  11. package/src/index.d.ts +19 -0
  12. package/src/index.js +15 -0
  13. package/src/others/totp-generator.d.ts +15 -0
  14. package/src/others/totp-generator.js +86 -0
  15. package/src/utility/deleteDirectory.js +105 -0
  16. package/src/utility/launchBrowser.d.ts +248 -0
  17. package/src/utility/launchBrowser.js +899 -0
  18. package/src/utility/multilogin_token_manager.js +164 -0
  19. package/src/utility/playwright-helper.d.ts +61 -0
  20. package/src/utility/playwright-helper.js +129 -0
  21. package/src/utility/proxy-utility/custom-proxy.d.ts +93 -0
  22. package/src/utility/proxy-utility/custom-proxy.js +625 -0
  23. package/src/utility/proxy-utility/proxy-chain.d.ts +123 -0
  24. package/src/utility/proxy-utility/proxy-chain.js +337 -0
  25. package/src/utility/proxy-utility/proxy-helper.d.ts +91 -0
  26. package/src/utility/proxy-utility/proxy-helper.js +222 -0
  27. package/dist/__main__.d.ts +0 -2
  28. package/dist/__main__.js +0 -127
  29. package/dist/__version__.d.ts +0 -11
  30. package/dist/__version__.js +0 -16
  31. package/dist/addons.d.ts +0 -17
  32. package/dist/addons.js +0 -70
  33. package/dist/data-files/territoryInfo.xml +0 -2024
  34. package/dist/data-files/webgl_data.db +0 -0
  35. package/dist/exceptions.d.ts +0 -76
  36. package/dist/exceptions.js +0 -153
  37. package/dist/fingerprints.d.ts +0 -4
  38. package/dist/fingerprints.js +0 -82
  39. package/dist/index.d.ts +0 -3
  40. package/dist/index.js +0 -3
  41. package/dist/ip.d.ts +0 -25
  42. package/dist/ip.js +0 -90
  43. package/dist/locale.d.ts +0 -26
  44. package/dist/locale.js +0 -280
  45. package/dist/mappings/browserforge.config.d.ts +0 -47
  46. package/dist/mappings/browserforge.config.js +0 -72
  47. package/dist/mappings/fonts.config.d.ts +0 -6
  48. package/dist/mappings/fonts.config.js +0 -822
  49. package/dist/mappings/warnings.config.d.ts +0 -16
  50. package/dist/mappings/warnings.config.js +0 -28
  51. package/dist/pkgman.d.ts +0 -62
  52. package/dist/pkgman.js +0 -347
  53. package/dist/server.d.ts +0 -6
  54. package/dist/server.js +0 -9
  55. package/dist/sync_api.d.ts +0 -7
  56. package/dist/sync_api.js +0 -27
  57. package/dist/utils.d.ts +0 -88
  58. package/dist/utils.js +0 -500
  59. package/dist/virtdisplay.d.ts +0 -20
  60. package/dist/virtdisplay.js +0 -123
  61. package/dist/warnings.d.ts +0 -4
  62. package/dist/warnings.js +0 -30
  63. package/dist/webgl/db-compat.d.ts +0 -9
  64. package/dist/webgl/db-compat.js +0 -44
  65. package/dist/webgl/sample.d.ts +0 -19
  66. package/dist/webgl/sample.js +0 -85
  67. /package/{LICENSE.md → LICENSE} +0 -0
@@ -0,0 +1,105 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { setTimeout as sleep } from "timers/promises";
4
+
5
+ /**
6
+ * Deletes a directory with built-in retry logic.
7
+ * Useful for browser profiles where files might still be locked by the OS process.
8
+ * * @param {string} targetPath - The absolute path to delete.
9
+ * @param {number} maxRetries - How many times to retry (default: 5).
10
+ * @param {number} retryDelayMs - Time to wait between retries (default: 2000ms).
11
+ */
12
+ export async function deleteDirectoryWithRetries(targetPath, maxRetries = 5, retryDelayMs = 2000) {
13
+ if (!fs.existsSync(targetPath)) {
14
+ return true; // Already gone
15
+ }
16
+
17
+ let attempt = 0;
18
+
19
+ while (attempt < maxRetries) {
20
+ try {
21
+ // Force: true allows deleting files even if read-only
22
+ // Recursive: true deletes inner folders
23
+ await fs.promises.rm(targetPath, { recursive: true, force: true });
24
+
25
+ // Double check if it's actually gone
26
+ if (!fs.existsSync(targetPath)) {
27
+ return true;
28
+ }
29
+ } catch (error) {
30
+ const isLastAttempt = attempt === maxRetries - 1;
31
+
32
+ // If it's the last attempt, log error
33
+ if (isLastAttempt) {
34
+ console.error(`❌ Failed to delete directory after ${maxRetries} attempts: ${targetPath}`);
35
+ console.error(` Error: ${error.message}`);
36
+ return false;
37
+ }
38
+
39
+ // Log warning and wait
40
+ console.warn(
41
+ `⚠️ Delete failed (Attempt ${attempt + 1}/${maxRetries}). File might be locked. Retrying in ${
42
+ retryDelayMs / 1000
43
+ }s...`
44
+ );
45
+ await sleep(retryDelayMs);
46
+ }
47
+ attempt++;
48
+ }
49
+
50
+ return false;
51
+ }
52
+
53
+ /**
54
+ * Deletes specific contents inside a directory but keeps the parent folder.
55
+ * (Optional utility if you need to clear cache without removing the profile folder itself)
56
+ */
57
+ export async function deleteAllItemsInDirectory(directoryPath) {
58
+ try {
59
+ if (!fs.existsSync(directoryPath)) return;
60
+
61
+ const files = await fs.promises.readdir(directoryPath);
62
+ for (const file of files) {
63
+ const curPath = path.join(directoryPath, file);
64
+ await deleteDirectoryWithRetries(curPath);
65
+ }
66
+ } catch (error) {
67
+ console.error(`Error emptying directory ${directoryPath}:`, error);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Legacy utility: Scan a directory and delete folders older than X minutes.
73
+ * (Note: launchBrowser.js now has its own internal version of this, but keeping this
74
+ * here is useful if you want to run cleanup scripts independently).
75
+ */
76
+ export function deleteOldDirectories({ directoryPath, ageLimitMinutes }) {
77
+ if (!fs.existsSync(directoryPath)) return;
78
+
79
+ const now = Date.now();
80
+ const limit = ageLimitMinutes * 60 * 1000;
81
+
82
+ try {
83
+ const files = fs.readdirSync(directoryPath);
84
+
85
+ files.forEach((file) => {
86
+ const curPath = path.join(directoryPath, file);
87
+ try {
88
+ const stats = fs.statSync(curPath);
89
+ if (stats.isDirectory()) {
90
+ const age = now - stats.mtimeMs;
91
+ if (age > limit) {
92
+ console.log(`Cleaning up old directory: ${file}`);
93
+ // We use the sync version of retry logic or just fire-and-forget async here
94
+ // For simplicity in a sync loop, we often just do a force removal:
95
+ fs.rmSync(curPath, { recursive: true, force: true });
96
+ }
97
+ }
98
+ } catch (e) {
99
+ // Ignore access errors on specific files
100
+ }
101
+ });
102
+ } catch (err) {
103
+ console.error("Error during old directory cleanup:", err);
104
+ }
105
+ }
@@ -0,0 +1,248 @@
1
+ import { Browser, BrowserContext, Page } from "playwright";
2
+ import type { FingerprintGeneratorOptions } from "fingerprint-generator";
3
+ import type { HumanPage, CreateCursorOptions } from "../human-cursor/index";
4
+ type Screen = FingerprintGeneratorOptions["screen"];
5
+ /**
6
+ * Proxy configuration object.
7
+ */
8
+ export interface ProxyConfig {
9
+ type: "http" | "https" | "socks5" | "socks" | "socks4";
10
+ host: string;
11
+ port: number | string;
12
+ user?: string;
13
+ pass?: string;
14
+ }
15
+
16
+
17
+ /**
18
+ * Configuration options for human-like cursor movement.
19
+ * Only applicable for non-camoufox browsers (camoufox has its own humanize option).
20
+ */
21
+ export interface HumanizeOptions extends CreateCursorOptions {
22
+ /** Enable/disable human-like cursor movement (default: true) */
23
+ humanize?: boolean;
24
+ /** Maximum movement time in seconds (default: 1.5) */
25
+ maxTime?: number;
26
+ /** Minimum movement time in seconds (default: 0.5) */
27
+ minTime?: number;
28
+ /** Auto-show cursor indicator after goto (default: true) */
29
+ showCursor?: boolean;
30
+ }
31
+
32
+ /**
33
+ * Configuration options specific to Camoufox.
34
+ * These are passed directly to camoufox-js.
35
+ */
36
+ export interface CamoufoxOptions {
37
+ /** Firefox version to use. Defaults to the current Camoufox version.
38
+ * To prevent leaks, only use this for special cases.
39
+ */
40
+ ff_version?: number;
41
+ /** Whether to run the browser in headless mode. Defaults to `false`.
42
+ */
43
+ headless?: boolean;
44
+ /**
45
+ * Whether to use GeoIP to automatically detect timezone, locale, and geolocation based on IP.
46
+ * If true, the proxy is passed to Camoufox internal config.
47
+ * Default: false
48
+ */
49
+ geoip?: boolean;
50
+
51
+ /**
52
+ * Override the OS signature.
53
+ * Can be a single OS or a list to randomly choose from.
54
+ * If not provided, it defaults to the detected system OS.
55
+ */
56
+ os?: "windows" | "macos" | "linux" | ("windows" | "macos" | "linux")[];
57
+
58
+ /** Whether to block all images. */
59
+ block_images?: boolean;
60
+
61
+ /** Whether to block WebRTC entirely. */
62
+ block_webrtc?: boolean;
63
+
64
+ /** Humanize the cursor movement.
65
+ * Takes either `true`, or the MAX duration in seconds of the cursor movement.
66
+ * The cursor typically takes up to 1.5 seconds to move across the window.
67
+ */
68
+ humanize?: boolean | number;
69
+
70
+ /** Constrains the screen dimensions of the generated fingerprint. */
71
+ screen?: Screen;
72
+
73
+ /**
74
+ * Allow arbitrary additional options supported by camoufox-js.
75
+ */
76
+ [key: string]: any;
77
+ }
78
+
79
+ /**
80
+ * Configuration options specific to Multilogin.
81
+ */
82
+ export interface MultiloginOptions {
83
+ /**
84
+ * Multilogin Profile ID. If provided, launches an existing profile.
85
+ */
86
+ profileId?: string | null;
87
+
88
+ /**
89
+ * OS Type for Multilogin profile creation.
90
+ * Default: detected OS
91
+ */
92
+ os_type?: "windows" | "macos" | "linux" | "android";
93
+
94
+ /**
95
+ * Multilogin flag: Canvas noise masking.
96
+ * Default: true
97
+ */
98
+ canvas_noise?: boolean;
99
+
100
+ /**
101
+ * Multilogin flag: Media devices masking.
102
+ * Default: true
103
+ */
104
+ media_masking?: boolean;
105
+
106
+ /**
107
+ * Multilogin flag: Audio masking.
108
+ * Default: true
109
+ */
110
+ audio_masking?: boolean;
111
+
112
+ /**
113
+ * Multilogin flag: Custom screen resolution.
114
+ * Default: false
115
+ */
116
+ custom_screen?: boolean;
117
+ }
118
+
119
+ /**
120
+ * Options for launching the browser.
121
+ */
122
+ export interface LaunchOptions {
123
+ // ========================================================================
124
+ // 1. GENERAL & NETWORK
125
+ // ========================================================================
126
+
127
+ /**
128
+ * Timezone ID (e.g., "America/New_York").
129
+ * Ignored if `camoufox_options.geoip` is true.
130
+ */
131
+ timezoneId?: string | null;
132
+
133
+ /**
134
+ * Proxy settings (object or string).
135
+ */
136
+ proxy?: ProxyConfig | string;
137
+
138
+ // ========================================================================
139
+ // 2. BROWSER SELECTION
140
+ // ========================================================================
141
+
142
+ /**
143
+ * Which browser engine to launch.
144
+ * Default: "chromium"
145
+ */
146
+ which_browser?: "chromium" | "chrome" | "firefox" | "brave" | "braveLauncher" | "camoufox" | "multilogin";
147
+
148
+ // ========================================================================
149
+ // 3. STORAGE & PROFILES
150
+ // ========================================================================
151
+
152
+ /**
153
+ * Path to a persistent profile.
154
+ * - If absolute path: Uses that path exactly (no prefix added).
155
+ * - If folder name: Creates inside `.data/browser_profiles/persistent/` AND adds a browser prefix (e.g., `brave_myProfile`).
156
+ * - If null: Creates a temporary, random profile in `.data/browser_profiles/temp/`.
157
+ */
158
+ profile_path?: string | null;
159
+
160
+ /**
161
+ * If set to > 10, deletes temporary profiles older than X minutes.
162
+ * Default: 0 (disabled)
163
+ */
164
+ cleanupMinutes?: number;
165
+
166
+ // ========================================================================
167
+ // 4. STANDARD FINGERPRINTING (Chromium, Firefox, Brave, Camoufox)
168
+ // ========================================================================
169
+
170
+ /**
171
+ * Whether to load the CapSolver extension (Chromium/Brave only).
172
+ * Default: false
173
+ */
174
+ CapSolver?: boolean;
175
+
176
+ /**
177
+ * Maximum width constraint for fingerprint generation.
178
+ * - If <= 10: Treated as multiplier of detected screen width (e.g. 1 = 100%, 0.8 = 80%).
179
+ * - If > 10: Treated as specific pixel width.
180
+ * Default: 1 (100% of detected screen width or 1920px fallback)
181
+ */
182
+ maxWidth?: number;
183
+
184
+ // ========================================================================
185
+ // 5. ENGINE SPECIFIC GROUPS
186
+ // ========================================================================
187
+
188
+ /**
189
+ * Options specific to the Camoufox engine.
190
+ */
191
+ camoufox_options?: CamoufoxOptions;
192
+
193
+ /**
194
+ * Options specific to the Multilogin engine.
195
+ */
196
+ multilogin_options?: MultiloginOptions;
197
+
198
+ /**
199
+ * Options for human-like cursor movement.
200
+ * ENABLED BY DEFAULT for non-camoufox browsers!
201
+ * To disable: set { humanize: false }
202
+ * Camoufox uses its own humanize option in camoufox_options.
203
+ */
204
+ humanize_options?: HumanizeOptions;
205
+ }
206
+
207
+ /**
208
+ * The object returned by launchBrowser.
209
+ */
210
+ export interface BrowserController {
211
+ /**
212
+ * The Playwright Browser or BrowserContext instance.
213
+ * Note: Multilogin and Persistent profiles return a BrowserContext here.
214
+ */
215
+ browser: Browser | BrowserContext | null;
216
+
217
+ /**
218
+ * The active BrowserContext.
219
+ */
220
+ context: BrowserContext | null;
221
+
222
+ /**
223
+ * The initial Page object.
224
+ * When humanize_options is provided, this will be a HumanPage with human-like cursor methods.
225
+ * All standard Playwright Page methods are available.
226
+ */
227
+ page: Page | HumanPage | null;
228
+
229
+ /**
230
+ * Checks if the browser context is currently active.
231
+ */
232
+ isBrowserRunning: () => boolean;
233
+
234
+ /**
235
+ * Safely closes the browser and cleans up temporary directories if applicable.
236
+ */
237
+ closeBrowser: () => Promise<boolean>;
238
+
239
+ /**
240
+ * Captures any error that occurred during launch.
241
+ */
242
+ launchError: Error | null;
243
+ }
244
+
245
+ /**
246
+ * Launches a browser based on the provided options.
247
+ */
248
+ export function launchBrowser(options: LaunchOptions): Promise<BrowserController>;