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,222 @@
1
+ import { setTimeout as sleep } from "timers/promises";
2
+ import randomstring from "randomstring";
3
+ import { getMultiloginToken } from "../multilogin_token_manager.js";
4
+ import { getActiveProxyWithStartStop as fetchAwsProxy } from "./custom-proxy.js";
5
+ import { arn, query } from "arn-knexjs";
6
+
7
+ // Environment variables for PacketStream
8
+ const PACKETSTREAM_USER = process.env.PACKETSTREAM_USER;
9
+ const PACKETSTREAM_PASS_KEY = process.env.PACKETSTREAM_PASS_KEY;
10
+ const PACKETSTREAM_HOST = process.env.PACKETSTREAM_HOST;
11
+ const PACKETSTREAM_PORT = process.env.PACKETSTREAM_PORT;
12
+
13
+ // ==========================================
14
+ // SECTION 1: CONFIGURATION & UTILITIES
15
+ // ==========================================
16
+
17
+ /**
18
+ * Validates PacketStream environment variables are set.
19
+ */
20
+ function validatePacketStreamEnv() {
21
+ const required = {
22
+ PACKETSTREAM_USER,
23
+ PACKETSTREAM_PASS_KEY,
24
+ PACKETSTREAM_HOST,
25
+ PACKETSTREAM_PORT,
26
+ };
27
+
28
+ const missing = Object.entries(required)
29
+ .filter(([, value]) => !value)
30
+ .map(([key]) => key);
31
+
32
+ if (missing.length > 0) {
33
+ throw new Error(`[Proxy Manager] Missing environment variables: ${missing.join(", ")}`);
34
+ }
35
+ }
36
+
37
+ // ==========================================
38
+ // SECTION 2: MULTILOGIN PROXY
39
+ // ==========================================
40
+
41
+ /**
42
+ * Fetches and parses a Multilogin proxy using Native Fetch.
43
+ */
44
+ export async function get_multilogin_proxy({
45
+ country = "us",
46
+ sessionType = "sticky",
47
+ protocol = "http",
48
+ region = "",
49
+ city = "",
50
+ IPTTL = 1800,
51
+ strictMode = false,
52
+ } = {}) {
53
+ try {
54
+ // 1. Get Token
55
+ const token = await getMultiloginToken();
56
+
57
+ // 2. Prepare Data
58
+ const data = { country, sessionType, protocol, region, city, IPTTL, count: 1 };
59
+ Object.keys(data).forEach((k) => (data[k] === "" || data[k] === 0 || data[k] == null) && delete data[k]);
60
+
61
+ // 3. Setup Timeout
62
+ const controller = new AbortController();
63
+ const timeoutId = setTimeout(() => controller.abort(), 20000);
64
+
65
+ try {
66
+ const response = await fetch("https://profile-proxy.multilogin.com/v1/proxy/connection_url", {
67
+ method: "POST",
68
+ headers: {
69
+ Authorization: `Bearer ${token}`,
70
+ "X-Strict-Mode": strictMode ? "true" : "false",
71
+ "Content-Type": "application/json",
72
+ },
73
+ body: JSON.stringify(data),
74
+ signal: controller.signal,
75
+ });
76
+
77
+ if (!response.ok) {
78
+ const errText = await response.text();
79
+ throw new Error(`HTTP ${response.status}: ${errText}`);
80
+ }
81
+
82
+ const json = await response.json();
83
+
84
+ let proxyStr = json?.data;
85
+ if (Array.isArray(proxyStr)) proxyStr = proxyStr[0];
86
+
87
+ if (!proxyStr || typeof proxyStr !== "string") {
88
+ console.error("Multilogin proxy API: Unexpected format", json);
89
+ return null;
90
+ }
91
+
92
+ // Format: host:port:user:pass
93
+ const parts = proxyStr.split(":");
94
+ if (parts.length < 4) {
95
+ console.error("Unexpected Multilogin proxy string:", proxyStr);
96
+ return null;
97
+ }
98
+
99
+ const [host, port, user, ...passParts] = parts;
100
+ const pass = passParts.join(":");
101
+
102
+ const temp_proxy = {
103
+ type: protocol,
104
+ host,
105
+ port: parseInt(port, 10),
106
+ user,
107
+ pass,
108
+ };
109
+
110
+ console.log("Multilogin Proxy:", temp_proxy);
111
+ return temp_proxy;
112
+ } finally {
113
+ clearTimeout(timeoutId);
114
+ }
115
+ } catch (error) {
116
+ console.error("Failed to get Multilogin proxy:", error.message);
117
+ return null;
118
+ }
119
+ }
120
+
121
+ // ==========================================
122
+ // SECTION 3: PACKETSTREAM PROXY
123
+ // ==========================================
124
+
125
+ /**
126
+ * Generates a PacketStream proxy object with a random session ID using credentials from config.
127
+ */
128
+ export async function get_packetstream_proxy() {
129
+ // 1. Validate environment variables
130
+ validatePacketStreamEnv();
131
+
132
+ // 2. Generate Random Session ID
133
+ const proxy_session_id = randomstring.generate({
134
+ length: 8,
135
+ charset: "alphanumeric",
136
+ capitalization: "both",
137
+ readable: false,
138
+ });
139
+
140
+ // 3. Construct the proxy object
141
+ const temp_proxy = {
142
+ type: "http",
143
+ host: PACKETSTREAM_HOST,
144
+ port: Number(PACKETSTREAM_PORT),
145
+ user: PACKETSTREAM_USER,
146
+ pass: `${PACKETSTREAM_PASS_KEY}-${proxy_session_id}`,
147
+ };
148
+
149
+ console.log("PacketStream Proxy:", temp_proxy);
150
+ return temp_proxy;
151
+ }
152
+
153
+ // ==========================================
154
+ // SECTION 4: DATABASE PROXY (X_ACCOUNTS)
155
+ // ==========================================
156
+
157
+ export async function get_x_proxy({ provider }) {
158
+ const { data: [proxyInstance] = [], error: getProxy_error } = await arn.single(
159
+ query("x_accounts_proxy")
160
+ .update({
161
+ total_used: query.raw("total_used + 1"),
162
+ last_used_time: new Date().toISOString(),
163
+ })
164
+ .where("id", function () {
165
+ let subquery = this.select("id").from("x_accounts_proxy").where("status", 1);
166
+
167
+ if (provider) {
168
+ subquery = subquery.where("provider", provider);
169
+ }
170
+
171
+ subquery = subquery
172
+ .andWhere(
173
+ query.raw("COALESCE(last_used_time, '1970-01-01T00:00:00.000Z') < ?", [
174
+ new Date(Date.now() - 60 * 60 * 1000).toISOString(),
175
+ ])
176
+ )
177
+ .orderBy("total_used", "asc")
178
+ .limit(1);
179
+ return subquery;
180
+ })
181
+ .returning("*")
182
+ );
183
+
184
+ if (getProxy_error || !proxyInstance) {
185
+ console.error(getProxy_error || "No proxy instances found");
186
+ await sleep(30000);
187
+ return null;
188
+ }
189
+
190
+ return proxyInstance;
191
+ }
192
+
193
+ // ==========================================
194
+ // SECTION 5: AWS PROXY ROTATION
195
+ // ==========================================
196
+
197
+ export function fetchNextProxy(proxies) {
198
+ if (proxies.isFetching) return;
199
+
200
+ proxies.isFetching = true;
201
+
202
+ fetchAwsProxy({
203
+ instance_name: proxies.proxyInstance,
204
+ })
205
+ .then((newProxyIp) => {
206
+ if (newProxyIp) {
207
+ proxies.proxy = {
208
+ host: newProxyIp,
209
+ port: 9002,
210
+ };
211
+ proxies.proxyUsed = 0;
212
+ console.log(`Successfully prepared next proxy: ${newProxyIp}`);
213
+ } else {
214
+ console.log("Next proxy fetch returned null");
215
+ }
216
+ proxies.isFetching = false;
217
+ })
218
+ .catch((error) => {
219
+ console.error(`Error fetching next proxy ${proxies.proxyInstance}:`, error.message);
220
+ proxies.isFetching = false;
221
+ });
222
+ }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/__main__.js DELETED
@@ -1,127 +0,0 @@
1
- #!/usr/bin/env node
2
- import { existsSync, rmSync } from "node:fs";
3
- import { Command } from "commander";
4
- import { DefaultAddons, maybeDownloadAddons } from "./addons.js";
5
- import { ALLOW_GEOIP, downloadMMDB, removeMMDB } from "./locale.js";
6
- import { CamoufoxFetcher, INSTALL_DIR, installedVerStr } from "./pkgman.js";
7
- import { launchServer } from "./server.js";
8
- import { Camoufox } from "./sync_api.js";
9
- import { getAsBooleanFromENV } from "./utils.js";
10
- class CamoufoxUpdate extends CamoufoxFetcher {
11
- currentVerStr;
12
- constructor() {
13
- super();
14
- this.currentVerStr = null;
15
- try {
16
- this.currentVerStr = installedVerStr();
17
- }
18
- catch (error) {
19
- if (error instanceof Error && error.name === "FileNotFoundError") {
20
- this.currentVerStr = null;
21
- }
22
- else {
23
- throw error;
24
- }
25
- }
26
- }
27
- static async create() {
28
- const updater = new CamoufoxUpdate();
29
- await updater.init();
30
- return updater;
31
- }
32
- isUpdateNeeded() {
33
- if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
34
- console.log("Skipping browser download / update check due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
35
- return false;
36
- }
37
- return this.currentVerStr === null || this.currentVerStr !== this.verstr;
38
- }
39
- async update() {
40
- if (!this.isUpdateNeeded()) {
41
- console.log("Camoufox binaries up to date!");
42
- console.log(`Current version: v${this.currentVerStr}`);
43
- return;
44
- }
45
- if (this.currentVerStr !== null) {
46
- console.log(`Updating Camoufox binaries from v${this.currentVerStr} => v${this.verstr}`, "yellow");
47
- }
48
- else {
49
- console.log(`Fetching Camoufox binaries...`);
50
- }
51
- await this.install();
52
- }
53
- async cleanup() {
54
- if (!existsSync(INSTALL_DIR)) {
55
- return false;
56
- }
57
- await rmSync(INSTALL_DIR, { recursive: true, force: true });
58
- console.log("Camoufox binaries removed!");
59
- return true;
60
- }
61
- }
62
- const program = new Command();
63
- program.command("fetch").action(async () => {
64
- const updater = await CamoufoxUpdate.create();
65
- await updater.update();
66
- if (ALLOW_GEOIP) {
67
- downloadMMDB();
68
- }
69
- maybeDownloadAddons(DefaultAddons);
70
- });
71
- program.command("remove").action(async () => {
72
- const updater = await CamoufoxUpdate.create();
73
- if (!(await updater.cleanup())) {
74
- console.log("Camoufox binaries not found!", "red");
75
- }
76
- removeMMDB();
77
- });
78
- program
79
- .command("test")
80
- .argument("[url]", "URL to open", null)
81
- .action(async (url) => {
82
- const browser = await Camoufox({
83
- headless: false,
84
- env: process.env,
85
- config: { showcursor: true },
86
- humanize: 0.5,
87
- geoip: true,
88
- });
89
- const page = await browser.newPage();
90
- if (url) {
91
- await page.goto(url);
92
- }
93
- await page.pause();
94
- });
95
- program.command("server").action(async () => {
96
- const server = await launchServer({});
97
- console.log(`Camoufox server started at ${server.wsEndpoint()}`);
98
- console.log();
99
- console.log(`You can connect to it using Playwright's BrowserType.connect() method.`);
100
- console.log(`To stop the server, press Ctrl+C or close this terminal.`);
101
- });
102
- program.command("path").action(() => {
103
- console.log(INSTALL_DIR);
104
- });
105
- program.command("version").action(async () => {
106
- try {
107
- const pkgVersion = require("pkg-version");
108
- console.log(`Pip package:\tv${pkgVersion("camoufox")}`);
109
- }
110
- catch (_error) {
111
- console.log("Pip package:\tNot installed!", "red");
112
- }
113
- const updater = await CamoufoxUpdate.create();
114
- const binVer = updater.currentVerStr;
115
- if (!binVer) {
116
- console.log("Camoufox:\tNot downloaded!", "red");
117
- return;
118
- }
119
- console.log(`Camoufox:\tv${binVer} `, "green", false);
120
- if (updater.isUpdateNeeded()) {
121
- console.log(`(Latest supported: v${updater.verstr})`, "red");
122
- }
123
- else {
124
- console.log("(Up to date!)", "yellow");
125
- }
126
- });
127
- program.parse(process.argv);
@@ -1,11 +0,0 @@
1
- /**
2
- * Camoufox version constants.
3
- */
4
- export declare class CONSTRAINTS {
5
- /**
6
- * The minimum and maximum supported versions of the Camoufox browser.
7
- */
8
- static readonly MIN_VERSION: string;
9
- static readonly MAX_VERSION: string;
10
- static asRange(): string;
11
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Camoufox version constants.
3
- */
4
- export class CONSTRAINTS {
5
- /**
6
- * The minimum and maximum supported versions of the Camoufox browser.
7
- */
8
- static MIN_VERSION = "beta.19";
9
- static MAX_VERSION = "1";
10
- static asRange() {
11
- /**
12
- * Returns the version range as a string.
13
- */
14
- return `>=${CONSTRAINTS.MIN_VERSION}, <${CONSTRAINTS.MAX_VERSION}`;
15
- }
16
- }
package/dist/addons.d.ts DELETED
@@ -1,17 +0,0 @@
1
- export declare const DefaultAddons: {
2
- /**
3
- * Default addons to be downloaded
4
- */
5
- UBO: string;
6
- };
7
- export declare function confirmPaths(paths: string[]): void;
8
- export declare function addDefaultAddons(_addonsList: string[], _excludeList?: (keyof typeof DefaultAddons)[]): void;
9
- /**
10
- * Downloads and extracts an addon from a given URL to a specified path
11
- */
12
- export declare function downloadAndExtract(url: string, extractPath: string, name: string): Promise<void>;
13
- /**
14
- * Downloads and extracts addons from a given dictionary to a specified list
15
- * Skips downloading if the addon is already downloaded
16
- */
17
- export declare function maybeDownloadAddons(addons: Record<string, string>, addonsList?: string[]): void;
package/dist/addons.js DELETED
@@ -1,70 +0,0 @@
1
- import fs from "node:fs";
2
- import { join } from "node:path";
3
- import { InvalidAddonPath } from "./exceptions.js";
4
- import { getPath, unzip, webdl } from "./pkgman.js";
5
- import { getAsBooleanFromENV } from "./utils.js";
6
- export const DefaultAddons = {
7
- /**
8
- * Default addons to be downloaded
9
- */
10
- UBO: "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi",
11
- };
12
- export function confirmPaths(paths) {
13
- /**
14
- * Confirms that the addon paths are valid
15
- */
16
- for (const path of paths) {
17
- if (!fs.existsSync(path) || !fs.lstatSync(path).isDirectory()) {
18
- throw new InvalidAddonPath(path);
19
- }
20
- if (!fs.existsSync(join(path, "manifest.json"))) {
21
- throw new InvalidAddonPath("manifest.json is missing. Addon path must be a path to an extracted addon.");
22
- }
23
- }
24
- }
25
- export function addDefaultAddons(_addonsList, _excludeList = []) {
26
- // TODO - enable addons
27
- /**
28
- * Adds default addons, minus any specified in excludeList, to addonsList
29
- */
30
- // const addons = Object.values(DefaultAddons).filter(addon => !excludeList.includes(addon as keyof typeof DefaultAddons));
31
- // maybeDownloadAddons(addons, addonsList);
32
- }
33
- /**
34
- * Downloads and extracts an addon from a given URL to a specified path
35
- */
36
- export async function downloadAndExtract(url, extractPath, name) {
37
- const buffer = await webdl(url, `Downloading addon (${name})`, false);
38
- unzip(buffer, extractPath, `Extracting addon (${name})`, false);
39
- }
40
- /**
41
- * Returns a path to the addon
42
- */
43
- function getAddonPath(addonName) {
44
- return getPath(join("addons", addonName));
45
- }
46
- /**
47
- * Downloads and extracts addons from a given dictionary to a specified list
48
- * Skips downloading if the addon is already downloaded
49
- */
50
- export function maybeDownloadAddons(addons, addonsList = []) {
51
- if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
52
- console.log("Skipping addon download due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
53
- return;
54
- }
55
- for (const addonName in addons) {
56
- const addonPath = getAddonPath(addonName);
57
- if (fs.existsSync(addonPath)) {
58
- addonsList.push(addonPath);
59
- continue;
60
- }
61
- try {
62
- fs.mkdirSync(addonPath, { recursive: true });
63
- downloadAndExtract(addons[addonName], addonPath, addonName);
64
- addonsList.push(addonPath);
65
- }
66
- catch (e) {
67
- console.error(`Failed to download and extract ${addonName}: ${e}`);
68
- }
69
- }
70
- }