@web-auto/camo 0.1.26 → 0.2.1
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/LICENSE +21 -21
- package/README.md +586 -586
- package/bin/browser-service.mjs +11 -11
- package/bin/camo.mjs +22 -22
- package/package.json +48 -48
- package/scripts/build.mjs +19 -19
- package/scripts/bump-version.mjs +34 -34
- package/scripts/check-file-size.mjs +80 -80
- package/scripts/file-size-policy.json +12 -2
- package/scripts/install.mjs +76 -76
- package/scripts/release.sh +54 -54
- package/src/autoscript/action-providers/index.mjs +6 -6
- package/src/autoscript/impact-engine.mjs +78 -78
- package/src/autoscript/runtime.mjs +1017 -1017
- package/src/autoscript/schema.mjs +376 -376
- package/src/cli.mjs +405 -405
- package/src/commands/attach.mjs +141 -141
- package/src/commands/autoscript.mjs +1011 -1011
- package/src/commands/browser.mjs +1255 -1257
- package/src/commands/container.mjs +401 -401
- package/src/commands/cookies.mjs +69 -69
- package/src/commands/create.mjs +98 -98
- package/src/commands/devtools.mjs +349 -349
- package/src/commands/events.mjs +152 -152
- package/src/commands/highlight-mode.mjs +24 -24
- package/src/commands/init.mjs +68 -68
- package/src/commands/lifecycle.mjs +275 -275
- package/src/commands/mouse.mjs +45 -45
- package/src/commands/profile.mjs +46 -46
- package/src/commands/record.mjs +115 -115
- package/src/commands/system.mjs +14 -14
- package/src/commands/window.mjs +123 -123
- package/src/container/change-notifier.mjs +362 -362
- package/src/container/element-filter.mjs +143 -143
- package/src/container/index.mjs +3 -3
- package/src/container/runtime-core/checkpoint.mjs +209 -209
- package/src/container/runtime-core/index.mjs +21 -21
- package/src/container/runtime-core/operations/index.mjs +774 -774
- package/src/container/runtime-core/operations/selector-scripts.mjs +277 -277
- package/src/container/runtime-core/operations/tab-pool.mjs +746 -746
- package/src/container/runtime-core/operations/viewport.mjs +189 -189
- package/src/container/runtime-core/search.mjs +190 -190
- package/src/container/runtime-core/subscription.mjs +224 -224
- package/src/container/runtime-core/utils.mjs +94 -94
- package/src/container/runtime-core/validation.mjs +127 -184
- package/src/container/runtime-core.mjs +1 -1
- package/src/container/subscription-registry.mjs +459 -459
- package/src/core/actions.mjs +561 -561
- package/src/core/browser.mjs +266 -266
- package/src/core/index.mjs +52 -52
- package/src/core/utils.mjs +91 -91
- package/src/events/daemon-entry.mjs +33 -33
- package/src/events/daemon.mjs +80 -80
- package/src/events/progress-log.mjs +109 -109
- package/src/events/ws-server.mjs +239 -239
- package/src/lib/client.mjs +200 -200
- package/src/lifecycle/cleanup.mjs +83 -83
- package/src/lifecycle/lock.mjs +126 -126
- package/src/lifecycle/session-registry.mjs +279 -279
- package/src/lifecycle/session-view.mjs +76 -76
- package/src/lifecycle/session-watchdog.mjs +281 -281
- package/src/services/browser-service/index.js +671 -674
- package/src/services/browser-service/internal/BrowserSession.input.test.js +389 -389
- package/src/services/browser-service/internal/BrowserSession.js +325 -336
- package/src/services/browser-service/internal/ElementRegistry.js +60 -60
- package/src/services/browser-service/internal/ProfileLock.js +84 -84
- package/src/services/browser-service/internal/SessionManager.js +184 -184
- package/src/services/browser-service/internal/SessionManager.test.js +39 -39
- package/src/services/browser-service/internal/browser-session/cookies.js +144 -144
- package/src/services/browser-service/internal/browser-session/input-ops.js +222 -219
- package/src/services/browser-service/internal/browser-session/input-pipeline.js +144 -144
- package/src/services/browser-service/internal/browser-session/logging.js +46 -46
- package/src/services/browser-service/internal/browser-session/navigation.js +38 -38
- package/src/services/browser-service/internal/browser-session/page-hooks.js +442 -442
- package/src/services/browser-service/internal/browser-session/page-management.js +302 -336
- package/src/services/browser-service/internal/browser-session/page-management.test.js +148 -148
- package/src/services/browser-service/internal/browser-session/recording.js +198 -198
- package/src/services/browser-service/internal/browser-session/runtime-events.js +61 -61
- package/src/services/browser-service/internal/browser-session/session-core.js +84 -84
- package/src/services/browser-service/internal/browser-session/session-state.js +38 -38
- package/src/services/browser-service/internal/browser-session/types.js +14 -14
- package/src/services/browser-service/internal/browser-session/utils.js +95 -95
- package/src/services/browser-service/internal/browser-session/viewport-manager.js +46 -46
- package/src/services/browser-service/internal/browser-session/viewport.js +215 -215
- package/src/services/browser-service/internal/container-matcher.js +851 -851
- package/src/services/browser-service/internal/container-registry.js +182 -182
- package/src/services/browser-service/internal/engine-manager.js +259 -259
- package/src/services/browser-service/internal/fingerprint.js +203 -203
- package/src/services/browser-service/internal/heartbeat.js +137 -137
- package/src/services/browser-service/internal/logging.js +46 -46
- package/src/services/browser-service/internal/page-runtime/runtime.js +1317 -1317
- package/src/services/browser-service/internal/pageRuntime.js +28 -28
- package/src/services/browser-service/internal/runtimeInjector.js +31 -31
- package/src/services/browser-service/internal/service-process-logger.js +140 -140
- package/src/services/browser-service/internal/state-bus.js +45 -45
- package/src/services/browser-service/internal/storage-paths.js +42 -42
- package/src/services/browser-service/internal/ws-server.js +1194 -1194
- package/src/services/browser-service/internal/ws-server.test.js +58 -58
- package/src/services/browser-service/server.mjs +6 -6
- package/src/services/controller/cli-bridge.js +93 -93
- package/src/services/controller/container-index.js +50 -50
- package/src/services/controller/container-storage.js +36 -36
- package/src/services/controller/controller-actions.js +207 -207
- package/src/services/controller/controller.js +1138 -1138
- package/src/services/controller/selectors.js +54 -54
- package/src/services/controller/transport.js +125 -125
- package/src/utils/args.mjs +26 -26
- package/src/utils/browser-service.mjs +544 -544
- package/src/utils/command-log.mjs +64 -64
- package/src/utils/config.mjs +214 -214
- package/src/utils/fingerprint.mjs +181 -181
- package/src/utils/help.mjs +216 -216
- package/src/utils/js-policy.mjs +13 -13
- package/src/utils/ws-client.mjs +30 -30
- package/src/container/runtime-core/operations/tab-pool.mjs.bak +0 -762
- package/src/container/runtime-core/operations/tab-pool.mjs.syntax-error +0 -762
- package/src/services/browser-service/index.js.bak +0 -671
|
@@ -1,181 +1,181 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import https from 'node:https';
|
|
5
|
-
import { execSync } from 'node:child_process';
|
|
6
|
-
import { CONFIG_DIR, ensureDir } from './config.mjs';
|
|
7
|
-
|
|
8
|
-
const GEOIP_DIR = path.join(CONFIG_DIR, 'geoip');
|
|
9
|
-
const GEOIP_MMDB = path.join(GEOIP_DIR, 'GeoLite2-City.mmdb');
|
|
10
|
-
|
|
11
|
-
// GeoIP regions mapping
|
|
12
|
-
export const GEOIP_REGIONS = {
|
|
13
|
-
'us': { country: 'United States', timezone: 'America/New_York', locale: 'en-US', city: 'New York' },
|
|
14
|
-
'us-west': { country: 'United States', timezone: 'America/Los_Angeles', locale: 'en-US', city: 'Los Angeles' },
|
|
15
|
-
'uk': { country: 'United Kingdom', timezone: 'Europe/London', locale: 'en-GB', city: 'London' },
|
|
16
|
-
'de': { country: 'Germany', timezone: 'Europe/Berlin', locale: 'de-DE', city: 'Berlin' },
|
|
17
|
-
'fr': { country: 'France', timezone: 'Europe/Paris', locale: 'fr-FR', city: 'Paris' },
|
|
18
|
-
'jp': { country: 'Japan', timezone: 'Asia/Tokyo', locale: 'ja-JP', city: 'Tokyo' },
|
|
19
|
-
'sg': { country: 'Singapore', timezone: 'Asia/Singapore', locale: 'en-SG', city: 'Singapore' },
|
|
20
|
-
'au': { country: 'Australia', timezone: 'Australia/Sydney', locale: 'en-AU', city: 'Sydney' },
|
|
21
|
-
'br': { country: 'Brazil', timezone: 'America/Sao_Paulo', locale: 'pt-BR', city: 'Sao Paulo' },
|
|
22
|
-
'in': { country: 'India', timezone: 'Asia/Kolkata', locale: 'en-IN', city: 'Mumbai' },
|
|
23
|
-
'hk': { country: 'Hong Kong', timezone: 'Asia/Hong_Kong', locale: 'zh-HK', city: 'Hong Kong' },
|
|
24
|
-
'tw': { country: 'Taiwan', timezone: 'Asia/Taipei', locale: 'zh-TW', city: 'Taipei' },
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// OS options for fingerprint
|
|
28
|
-
export const OS_OPTIONS = {
|
|
29
|
-
'mac': { platform: 'darwin', os: 'Macintosh', osVersion: '14.0', cpuCores: 8, memory: 16 },
|
|
30
|
-
'mac-m1': { platform: 'darwin', os: 'Macintosh', osVersion: '14.0', cpuCores: 8, memory: 16, arch: 'arm64' },
|
|
31
|
-
'mac-intel': { platform: 'darwin', os: 'Macintosh', osVersion: '14.0', cpuCores: 8, memory: 16, arch: 'x64' },
|
|
32
|
-
'windows': { platform: 'win32', os: 'Windows', osVersion: '11', cpuCores: 8, memory: 16 },
|
|
33
|
-
'windows-10': { platform: 'win32', os: 'Windows', osVersion: '10', cpuCores: 4, memory: 8 },
|
|
34
|
-
'linux': { platform: 'linux', os: 'Linux', osVersion: 'Ubuntu 22.04', cpuCores: 4, memory: 8 },
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export function hasGeoIP() {
|
|
38
|
-
return fs.existsSync(GEOIP_MMDB);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getGeoIPPath() {
|
|
42
|
-
return GEOIP_MMDB;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function downloadGeoIP(progressCb = console.log) {
|
|
46
|
-
ensureDir(GEOIP_DIR);
|
|
47
|
-
|
|
48
|
-
if (hasGeoIP()) {
|
|
49
|
-
progressCb('GeoIP database already exists.');
|
|
50
|
-
return GEOIP_MMDB;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
progressCb('Downloading GeoLite2-City database...');
|
|
54
|
-
|
|
55
|
-
// Use MaxMind's public GeoLite2 database
|
|
56
|
-
const url = 'https://git.io/GeoLite2-City.mmdb';
|
|
57
|
-
|
|
58
|
-
return new Promise((resolve, reject) => {
|
|
59
|
-
const file = fs.createWriteStream(GEOIP_MMDB + '.tmp');
|
|
60
|
-
|
|
61
|
-
https.get(url, (response) => {
|
|
62
|
-
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
63
|
-
// Follow redirect
|
|
64
|
-
const locUrl = response.headers.location;
|
|
65
|
-
https.get(locUrl, (resp) => {
|
|
66
|
-
const total = parseInt(resp.headers['content-length'], 10);
|
|
67
|
-
let downloaded = 0;
|
|
68
|
-
|
|
69
|
-
resp.on('data', (chunk) => {
|
|
70
|
-
downloaded += chunk.length;
|
|
71
|
-
if (total) {
|
|
72
|
-
const pct = Math.floor((downloaded / total) * 100);
|
|
73
|
-
if (pct % 10 === 0) {
|
|
74
|
-
progressCb(`Downloading GeoIP: ${pct}%`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
resp.pipe(file);
|
|
80
|
-
file.on('finish', () => {
|
|
81
|
-
file.close();
|
|
82
|
-
fs.renameSync(GEOIP_MMDB + '.tmp', GEOIP_MMDB);
|
|
83
|
-
progressCb('GeoIP database downloaded successfully.');
|
|
84
|
-
resolve(GEOIP_MMDB);
|
|
85
|
-
});
|
|
86
|
-
}).on('error', (err) => {
|
|
87
|
-
fs.unlinkSync(GEOIP_MMDB + '.tmp');
|
|
88
|
-
reject(new Error(`Failed to download GeoIP: ${err.message}`));
|
|
89
|
-
});
|
|
90
|
-
} else {
|
|
91
|
-
response.pipe(file);
|
|
92
|
-
file.on('finish', () => {
|
|
93
|
-
file.close();
|
|
94
|
-
fs.renameSync(GEOIP_MMDB + '.tmp', GEOIP_MMDB);
|
|
95
|
-
progressCb('GeoIP database downloaded successfully.');
|
|
96
|
-
resolve(GEOIP_MMDB);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}).on('error', (err) => {
|
|
100
|
-
fs.unlinkSync(GEOIP_MMDB + '.tmp');
|
|
101
|
-
reject(new Error(`Failed to download GeoIP: ${err.message}`));
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function generateFingerprint(options = {}) {
|
|
107
|
-
const osKey = options.os || 'mac';
|
|
108
|
-
const regionKey = options.region || 'us';
|
|
109
|
-
|
|
110
|
-
const osConfig = OS_OPTIONS[osKey] || OS_OPTIONS['mac'];
|
|
111
|
-
const regionConfig = GEOIP_REGIONS[regionKey] || GEOIP_REGIONS['us'];
|
|
112
|
-
|
|
113
|
-
const screenResolutions = [
|
|
114
|
-
{ width: 1920, height: 1080 },
|
|
115
|
-
{ width: 2560, height: 1440 },
|
|
116
|
-
{ width: 1440, height: 900 },
|
|
117
|
-
{ width: 1366, height: 768 },
|
|
118
|
-
{ width: 1536, height: 864 },
|
|
119
|
-
];
|
|
120
|
-
|
|
121
|
-
const webGLRenderers = {
|
|
122
|
-
'mac': ['Apple M1', 'Apple M2', 'Intel Iris Plus Graphics'],
|
|
123
|
-
'mac-m1': ['Apple M1', 'Apple M2'],
|
|
124
|
-
'mac-intel': ['Intel Iris Plus Graphics', 'Intel UHD Graphics 630'],
|
|
125
|
-
'windows': ['NVIDIA GeForce RTX 3080', 'NVIDIA GeForce RTX 3070', 'AMD Radeon RX 6800'],
|
|
126
|
-
'windows-10': ['NVIDIA GeForce GTX 1660', 'AMD Radeon RX 580'],
|
|
127
|
-
'linux': ['NVIDIA GeForce RTX 3060', 'AMD Radeon RX 6600', 'Mesa Intel Graphics'],
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const screen = screenResolutions[Math.floor(Math.random() * screenResolutions.length)];
|
|
131
|
-
const webglRenderer = (webGLRenderers[osKey] || webGLRenderers['mac'])[Math.floor(Math.random() * (webGLRenderers[osKey] || webGLRenderers['mac']).length)];
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
os: osConfig.os,
|
|
135
|
-
osVersion: osConfig.osVersion,
|
|
136
|
-
platform: osConfig.platform,
|
|
137
|
-
arch: osConfig.arch || (osConfig.platform === 'darwin' ? 'arm64' : 'x64'),
|
|
138
|
-
cpuCores: osConfig.cpuCores,
|
|
139
|
-
memory: osConfig.memory,
|
|
140
|
-
timezone: regionConfig.timezone,
|
|
141
|
-
locale: regionConfig.locale,
|
|
142
|
-
country: regionConfig.country,
|
|
143
|
-
city: regionConfig.city,
|
|
144
|
-
screen,
|
|
145
|
-
webgl: {
|
|
146
|
-
vendor: 'Google Inc. (Apple)',
|
|
147
|
-
renderer: webglRenderer,
|
|
148
|
-
},
|
|
149
|
-
userAgent: buildUserAgent(osConfig, regionConfig),
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function buildUserAgent(osConfig, regionConfig) {
|
|
154
|
-
const chromeVersion = '120.0.0.0';
|
|
155
|
-
|
|
156
|
-
if (osConfig.platform === 'darwin') {
|
|
157
|
-
return `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
|
|
158
|
-
} else if (osConfig.platform === 'win32') {
|
|
159
|
-
return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
|
|
160
|
-
} else {
|
|
161
|
-
return `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function listAvailableRegions() {
|
|
166
|
-
return Object.entries(GEOIP_REGIONS).map(([key, config]) => ({
|
|
167
|
-
key,
|
|
168
|
-
country: config.country,
|
|
169
|
-
city: config.city,
|
|
170
|
-
timezone: config.timezone,
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function listAvailableOS() {
|
|
175
|
-
return Object.entries(OS_OPTIONS).map(([key, config]) => ({
|
|
176
|
-
key,
|
|
177
|
-
os: config.os,
|
|
178
|
-
osVersion: config.osVersion,
|
|
179
|
-
platform: config.platform,
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import https from 'node:https';
|
|
5
|
+
import { execSync } from 'node:child_process';
|
|
6
|
+
import { CONFIG_DIR, ensureDir } from './config.mjs';
|
|
7
|
+
|
|
8
|
+
const GEOIP_DIR = path.join(CONFIG_DIR, 'geoip');
|
|
9
|
+
const GEOIP_MMDB = path.join(GEOIP_DIR, 'GeoLite2-City.mmdb');
|
|
10
|
+
|
|
11
|
+
// GeoIP regions mapping
|
|
12
|
+
export const GEOIP_REGIONS = {
|
|
13
|
+
'us': { country: 'United States', timezone: 'America/New_York', locale: 'en-US', city: 'New York' },
|
|
14
|
+
'us-west': { country: 'United States', timezone: 'America/Los_Angeles', locale: 'en-US', city: 'Los Angeles' },
|
|
15
|
+
'uk': { country: 'United Kingdom', timezone: 'Europe/London', locale: 'en-GB', city: 'London' },
|
|
16
|
+
'de': { country: 'Germany', timezone: 'Europe/Berlin', locale: 'de-DE', city: 'Berlin' },
|
|
17
|
+
'fr': { country: 'France', timezone: 'Europe/Paris', locale: 'fr-FR', city: 'Paris' },
|
|
18
|
+
'jp': { country: 'Japan', timezone: 'Asia/Tokyo', locale: 'ja-JP', city: 'Tokyo' },
|
|
19
|
+
'sg': { country: 'Singapore', timezone: 'Asia/Singapore', locale: 'en-SG', city: 'Singapore' },
|
|
20
|
+
'au': { country: 'Australia', timezone: 'Australia/Sydney', locale: 'en-AU', city: 'Sydney' },
|
|
21
|
+
'br': { country: 'Brazil', timezone: 'America/Sao_Paulo', locale: 'pt-BR', city: 'Sao Paulo' },
|
|
22
|
+
'in': { country: 'India', timezone: 'Asia/Kolkata', locale: 'en-IN', city: 'Mumbai' },
|
|
23
|
+
'hk': { country: 'Hong Kong', timezone: 'Asia/Hong_Kong', locale: 'zh-HK', city: 'Hong Kong' },
|
|
24
|
+
'tw': { country: 'Taiwan', timezone: 'Asia/Taipei', locale: 'zh-TW', city: 'Taipei' },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// OS options for fingerprint
|
|
28
|
+
export const OS_OPTIONS = {
|
|
29
|
+
'mac': { platform: 'darwin', os: 'Macintosh', osVersion: '14.0', cpuCores: 8, memory: 16 },
|
|
30
|
+
'mac-m1': { platform: 'darwin', os: 'Macintosh', osVersion: '14.0', cpuCores: 8, memory: 16, arch: 'arm64' },
|
|
31
|
+
'mac-intel': { platform: 'darwin', os: 'Macintosh', osVersion: '14.0', cpuCores: 8, memory: 16, arch: 'x64' },
|
|
32
|
+
'windows': { platform: 'win32', os: 'Windows', osVersion: '11', cpuCores: 8, memory: 16 },
|
|
33
|
+
'windows-10': { platform: 'win32', os: 'Windows', osVersion: '10', cpuCores: 4, memory: 8 },
|
|
34
|
+
'linux': { platform: 'linux', os: 'Linux', osVersion: 'Ubuntu 22.04', cpuCores: 4, memory: 8 },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function hasGeoIP() {
|
|
38
|
+
return fs.existsSync(GEOIP_MMDB);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getGeoIPPath() {
|
|
42
|
+
return GEOIP_MMDB;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function downloadGeoIP(progressCb = console.log) {
|
|
46
|
+
ensureDir(GEOIP_DIR);
|
|
47
|
+
|
|
48
|
+
if (hasGeoIP()) {
|
|
49
|
+
progressCb('GeoIP database already exists.');
|
|
50
|
+
return GEOIP_MMDB;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
progressCb('Downloading GeoLite2-City database...');
|
|
54
|
+
|
|
55
|
+
// Use MaxMind's public GeoLite2 database
|
|
56
|
+
const url = 'https://git.io/GeoLite2-City.mmdb';
|
|
57
|
+
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const file = fs.createWriteStream(GEOIP_MMDB + '.tmp');
|
|
60
|
+
|
|
61
|
+
https.get(url, (response) => {
|
|
62
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
63
|
+
// Follow redirect
|
|
64
|
+
const locUrl = response.headers.location;
|
|
65
|
+
https.get(locUrl, (resp) => {
|
|
66
|
+
const total = parseInt(resp.headers['content-length'], 10);
|
|
67
|
+
let downloaded = 0;
|
|
68
|
+
|
|
69
|
+
resp.on('data', (chunk) => {
|
|
70
|
+
downloaded += chunk.length;
|
|
71
|
+
if (total) {
|
|
72
|
+
const pct = Math.floor((downloaded / total) * 100);
|
|
73
|
+
if (pct % 10 === 0) {
|
|
74
|
+
progressCb(`Downloading GeoIP: ${pct}%`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
resp.pipe(file);
|
|
80
|
+
file.on('finish', () => {
|
|
81
|
+
file.close();
|
|
82
|
+
fs.renameSync(GEOIP_MMDB + '.tmp', GEOIP_MMDB);
|
|
83
|
+
progressCb('GeoIP database downloaded successfully.');
|
|
84
|
+
resolve(GEOIP_MMDB);
|
|
85
|
+
});
|
|
86
|
+
}).on('error', (err) => {
|
|
87
|
+
fs.unlinkSync(GEOIP_MMDB + '.tmp');
|
|
88
|
+
reject(new Error(`Failed to download GeoIP: ${err.message}`));
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
response.pipe(file);
|
|
92
|
+
file.on('finish', () => {
|
|
93
|
+
file.close();
|
|
94
|
+
fs.renameSync(GEOIP_MMDB + '.tmp', GEOIP_MMDB);
|
|
95
|
+
progressCb('GeoIP database downloaded successfully.');
|
|
96
|
+
resolve(GEOIP_MMDB);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}).on('error', (err) => {
|
|
100
|
+
fs.unlinkSync(GEOIP_MMDB + '.tmp');
|
|
101
|
+
reject(new Error(`Failed to download GeoIP: ${err.message}`));
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function generateFingerprint(options = {}) {
|
|
107
|
+
const osKey = options.os || 'mac';
|
|
108
|
+
const regionKey = options.region || 'us';
|
|
109
|
+
|
|
110
|
+
const osConfig = OS_OPTIONS[osKey] || OS_OPTIONS['mac'];
|
|
111
|
+
const regionConfig = GEOIP_REGIONS[regionKey] || GEOIP_REGIONS['us'];
|
|
112
|
+
|
|
113
|
+
const screenResolutions = [
|
|
114
|
+
{ width: 1920, height: 1080 },
|
|
115
|
+
{ width: 2560, height: 1440 },
|
|
116
|
+
{ width: 1440, height: 900 },
|
|
117
|
+
{ width: 1366, height: 768 },
|
|
118
|
+
{ width: 1536, height: 864 },
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
const webGLRenderers = {
|
|
122
|
+
'mac': ['Apple M1', 'Apple M2', 'Intel Iris Plus Graphics'],
|
|
123
|
+
'mac-m1': ['Apple M1', 'Apple M2'],
|
|
124
|
+
'mac-intel': ['Intel Iris Plus Graphics', 'Intel UHD Graphics 630'],
|
|
125
|
+
'windows': ['NVIDIA GeForce RTX 3080', 'NVIDIA GeForce RTX 3070', 'AMD Radeon RX 6800'],
|
|
126
|
+
'windows-10': ['NVIDIA GeForce GTX 1660', 'AMD Radeon RX 580'],
|
|
127
|
+
'linux': ['NVIDIA GeForce RTX 3060', 'AMD Radeon RX 6600', 'Mesa Intel Graphics'],
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const screen = screenResolutions[Math.floor(Math.random() * screenResolutions.length)];
|
|
131
|
+
const webglRenderer = (webGLRenderers[osKey] || webGLRenderers['mac'])[Math.floor(Math.random() * (webGLRenderers[osKey] || webGLRenderers['mac']).length)];
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
os: osConfig.os,
|
|
135
|
+
osVersion: osConfig.osVersion,
|
|
136
|
+
platform: osConfig.platform,
|
|
137
|
+
arch: osConfig.arch || (osConfig.platform === 'darwin' ? 'arm64' : 'x64'),
|
|
138
|
+
cpuCores: osConfig.cpuCores,
|
|
139
|
+
memory: osConfig.memory,
|
|
140
|
+
timezone: regionConfig.timezone,
|
|
141
|
+
locale: regionConfig.locale,
|
|
142
|
+
country: regionConfig.country,
|
|
143
|
+
city: regionConfig.city,
|
|
144
|
+
screen,
|
|
145
|
+
webgl: {
|
|
146
|
+
vendor: 'Google Inc. (Apple)',
|
|
147
|
+
renderer: webglRenderer,
|
|
148
|
+
},
|
|
149
|
+
userAgent: buildUserAgent(osConfig, regionConfig),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function buildUserAgent(osConfig, regionConfig) {
|
|
154
|
+
const chromeVersion = '120.0.0.0';
|
|
155
|
+
|
|
156
|
+
if (osConfig.platform === 'darwin') {
|
|
157
|
+
return `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
|
|
158
|
+
} else if (osConfig.platform === 'win32') {
|
|
159
|
+
return `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
|
|
160
|
+
} else {
|
|
161
|
+
return `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function listAvailableRegions() {
|
|
166
|
+
return Object.entries(GEOIP_REGIONS).map(([key, config]) => ({
|
|
167
|
+
key,
|
|
168
|
+
country: config.country,
|
|
169
|
+
city: config.city,
|
|
170
|
+
timezone: config.timezone,
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function listAvailableOS() {
|
|
175
|
+
return Object.entries(OS_OPTIONS).map(([key, config]) => ({
|
|
176
|
+
key,
|
|
177
|
+
os: config.os,
|
|
178
|
+
osVersion: config.osVersion,
|
|
179
|
+
platform: config.platform,
|
|
180
|
+
}));
|
|
181
|
+
}
|