camoufox-js 0.3.0 → 0.3.2
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/dist/fingerprints.d.ts +2 -1
- package/dist/fingerprints.js +3 -2
- package/dist/locale.d.ts +5 -5
- package/dist/locale.js +1 -2
- package/dist/pkgman.js +14 -3
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +24 -25
- package/dist/webgl/sample.d.ts +6 -2
- package/dist/webgl/sample.js +1 -1
- package/package.json +10 -3
package/dist/fingerprints.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Fingerprint, FingerprintGeneratorOptions } from 'fingerprint-generator';
|
|
2
|
+
export declare const SUPPORTED_OS: readonly ["linux", "macos", "windows"];
|
|
2
3
|
export declare function fromBrowserforge(fingerprint: Fingerprint, ffVersion?: string): Record<string, any>;
|
|
3
|
-
export declare function generateFingerprint(window?: [number, number], config?: FingerprintGeneratorOptions
|
|
4
|
+
export declare function generateFingerprint(window?: [number, number], config?: Partial<FingerprintGeneratorOptions>): Fingerprint;
|
package/dist/fingerprints.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { loadYaml } from './pkgman.js';
|
|
3
3
|
import { FingerprintGenerator } from 'fingerprint-generator';
|
|
4
|
+
export const SUPPORTED_OS = ['linux', 'macos', 'windows'];
|
|
4
5
|
const BROWSERFORGE_DATA = loadYaml(join(import.meta.dirname, 'data-files', 'browserforge.yml'));
|
|
5
6
|
const FP_GENERATOR = new FingerprintGenerator({
|
|
6
7
|
browsers: ['firefox'],
|
|
7
|
-
operatingSystems:
|
|
8
|
+
operatingSystems: SUPPORTED_OS,
|
|
8
9
|
});
|
|
9
10
|
function randrange(min, max) {
|
|
10
11
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
@@ -73,7 +74,7 @@ function handleWindowSize(fp, outerWidth, outerHeight) {
|
|
|
73
74
|
sc.outerHeight = outerHeight;
|
|
74
75
|
fp.screen = sc;
|
|
75
76
|
}
|
|
76
|
-
export function generateFingerprint(window, config
|
|
77
|
+
export function generateFingerprint(window, config) {
|
|
77
78
|
if (window) {
|
|
78
79
|
const { fingerprint } = FP_GENERATOR.getFingerprint(config);
|
|
79
80
|
handleWindowSize(fingerprint, window[0], window[1]);
|
package/dist/locale.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const ALLOW_GEOIP = true;
|
|
2
2
|
declare class Locale {
|
|
3
3
|
language: string;
|
|
4
|
-
region?: string;
|
|
5
|
-
script?: string;
|
|
6
|
-
constructor(language: string, region?: string, script?: string);
|
|
4
|
+
region?: string | undefined;
|
|
5
|
+
script?: string | undefined;
|
|
6
|
+
constructor(language: string, region?: string | undefined, script?: string | undefined);
|
|
7
7
|
asString(): string;
|
|
8
8
|
asConfig(): Record<string, string>;
|
|
9
9
|
}
|
|
@@ -12,8 +12,8 @@ declare class Geolocation {
|
|
|
12
12
|
longitude: number;
|
|
13
13
|
latitude: number;
|
|
14
14
|
timezone: string;
|
|
15
|
-
accuracy?: number;
|
|
16
|
-
constructor(locale: Locale, longitude: number, latitude: number, timezone: string, accuracy?: number);
|
|
15
|
+
accuracy?: number | undefined;
|
|
16
|
+
constructor(locale: Locale, longitude: number, latitude: number, timezone: string, accuracy?: number | undefined);
|
|
17
17
|
asConfig(): Record<string, any>;
|
|
18
18
|
}
|
|
19
19
|
export declare function normalizeLocale(locale: string): Locale;
|
package/dist/locale.js
CHANGED
|
@@ -76,8 +76,7 @@ export function normalizeLocale(locale) {
|
|
|
76
76
|
if (!parser.region) {
|
|
77
77
|
throw InvalidLocale.invalidInput(locale);
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
return new Locale(record['Subtag'], parser.region()?.data['record']['Subtag'], record['Suppress-Script']);
|
|
79
|
+
return new Locale(parser.language()?.format() ?? 'en', parser.region()?.format(), parser.language()?.script()?.format());
|
|
81
80
|
}
|
|
82
81
|
export function handleLocale(locale, ignoreRegion = false) {
|
|
83
82
|
if (locale.length > 3) {
|
package/dist/pkgman.js
CHANGED
|
@@ -22,7 +22,7 @@ if (!(process.platform in OS_MAP)) {
|
|
|
22
22
|
throw new UnsupportedOS(`OS ${process.platform} is not supported`);
|
|
23
23
|
}
|
|
24
24
|
export const OS_NAME = OS_MAP[process.platform];
|
|
25
|
-
export const INSTALL_DIR =
|
|
25
|
+
export const INSTALL_DIR = userCacheDir('camoufox');
|
|
26
26
|
export const LOCAL_DATA = path.join(import.meta.dirname, 'data-files');
|
|
27
27
|
export const OS_ARCH_MATRIX = {
|
|
28
28
|
'win': ['x86_64', 'i686'],
|
|
@@ -162,7 +162,7 @@ export class CamoufoxFetcher extends GitHubDownloader {
|
|
|
162
162
|
return Buffer.from(await response.arrayBuffer());
|
|
163
163
|
}
|
|
164
164
|
async extractZip(zipFile) {
|
|
165
|
-
const zip = AdmZip(zipFile);
|
|
165
|
+
const zip = new AdmZip(zipFile);
|
|
166
166
|
zip.extractAllTo(INSTALL_DIR.toString(), true);
|
|
167
167
|
}
|
|
168
168
|
static cleanup() {
|
|
@@ -219,6 +219,17 @@ export class CamoufoxFetcher extends GitHubDownloader {
|
|
|
219
219
|
return this._version_obj.fullString;
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
+
function userCacheDir(appName) {
|
|
223
|
+
if (OS_NAME === 'win') {
|
|
224
|
+
return path.join(os.homedir(), 'AppData', 'Local', appName, appName, 'Cache');
|
|
225
|
+
}
|
|
226
|
+
else if (OS_NAME === 'mac') {
|
|
227
|
+
return path.join(os.homedir(), 'Library', 'Caches', appName);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
return path.join(os.homedir(), '.cache', appName);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
222
233
|
export function installedVerStr() {
|
|
223
234
|
return Version.fromPath().fullString;
|
|
224
235
|
}
|
|
@@ -281,7 +292,7 @@ export async function webdl(url, desc = '', bar = true, buffer = null) {
|
|
|
281
292
|
return fileBuffer;
|
|
282
293
|
}
|
|
283
294
|
export async function unzip(zipFile, extractPath, desc, bar = true) {
|
|
284
|
-
const zip = AdmZip(zipFile);
|
|
295
|
+
const zip = new AdmZip(zipFile);
|
|
285
296
|
const zipEntries = zip.getEntries();
|
|
286
297
|
if (bar) {
|
|
287
298
|
console.log(desc || 'Extracting files...');
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DefaultAddons } from './addons.js';
|
|
2
|
+
import { SUPPORTED_OS } from './fingerprints.js';
|
|
2
3
|
import { VirtualDisplay } from './virtdisplay.js';
|
|
3
4
|
import { PathLike } from 'fs';
|
|
4
5
|
import { Fingerprint, FingerprintGeneratorOptions } from 'fingerprint-generator';
|
|
@@ -11,7 +12,7 @@ export interface LaunchOptions {
|
|
|
11
12
|
* Can be "windows", "macos", "linux", or a list to randomly choose from.
|
|
12
13
|
* Default: ["windows", "macos", "linux"]
|
|
13
14
|
*/
|
|
14
|
-
os?:
|
|
15
|
+
os?: typeof SUPPORTED_OS[number] | (typeof SUPPORTED_OS[number])[];
|
|
15
16
|
/** Whether to block all images. */
|
|
16
17
|
block_images?: boolean;
|
|
17
18
|
/** Whether to block WebRTC entirely. */
|
package/dist/utils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { addDefaultAddons, confirmPaths } from './addons.js';
|
|
6
6
|
import { InvalidOS, InvalidPropertyType, NonFirefoxFingerprint, UnknownProperty } from './exceptions.js';
|
|
7
|
-
import { fromBrowserforge, generateFingerprint } from './fingerprints.js';
|
|
7
|
+
import { fromBrowserforge, generateFingerprint, SUPPORTED_OS } from './fingerprints.js';
|
|
8
8
|
import { publicIP, validIPv4, validIPv6 } from './ip.js';
|
|
9
9
|
import { geoipAllowed, getGeolocation, handleLocales } from './locale.js';
|
|
10
10
|
import { OS_NAME, getPath, installedVerStr, launchPath } from './pkgman.js';
|
|
@@ -128,20 +128,20 @@ function determineUAOS(userAgent) {
|
|
|
128
128
|
}
|
|
129
129
|
function getScreenCons(headless) {
|
|
130
130
|
if (headless === false) {
|
|
131
|
-
return
|
|
131
|
+
return undefined;
|
|
132
132
|
}
|
|
133
133
|
// TODO - Implement getMonitors
|
|
134
134
|
// try {
|
|
135
135
|
// const monitors = getMonitors();
|
|
136
136
|
// if (!monitors.length) {
|
|
137
|
-
// return
|
|
137
|
+
// return undefined;
|
|
138
138
|
// }
|
|
139
139
|
// const monitor = monitors.reduce((prev, curr) => (prev.width * prev.height > curr.width * curr.height ? prev : curr));
|
|
140
140
|
// return { maxWidth: monitor.width, maxHeight: monitor.height };
|
|
141
141
|
// } catch {
|
|
142
|
-
// return
|
|
142
|
+
// return undefined;
|
|
143
143
|
// }
|
|
144
|
-
return
|
|
144
|
+
return undefined;
|
|
145
145
|
}
|
|
146
146
|
function updateFonts(config, targetOS) {
|
|
147
147
|
const fontsPath = join(import.meta.dirname, 'data-files', 'fonts.json');
|
|
@@ -161,17 +161,17 @@ function checkCustomFingerprint(fingerprint) {
|
|
|
161
161
|
}
|
|
162
162
|
LeakWarning.warn('custom_fingerprint', false);
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function validateOS(os) {
|
|
165
|
+
if (!os)
|
|
166
|
+
return undefined;
|
|
165
167
|
if (Array.isArray(os)) {
|
|
166
|
-
os.
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (!os.toLowerCase()) {
|
|
170
|
-
throw new InvalidOS(`OS values must be lowercase: '${os}'`);
|
|
168
|
+
os.every(validateOS);
|
|
169
|
+
return [...os];
|
|
171
170
|
}
|
|
172
|
-
if (!
|
|
171
|
+
if (!SUPPORTED_OS.includes(os)) {
|
|
173
172
|
throw new InvalidOS(`Camoufox does not support the OS: '${os}'`);
|
|
174
173
|
}
|
|
174
|
+
return [os];
|
|
175
175
|
}
|
|
176
176
|
function cleanLocals(data) {
|
|
177
177
|
delete data.playwright;
|
|
@@ -253,6 +253,8 @@ export function syncAttachVD(browser, virtualDisplay) {
|
|
|
253
253
|
* Implementation from https://github.com/microsoft/playwright/blob/3873b72ac1441ca691f7594f0ed705bd84518f93/packages/playwright-core/src/server/browserContext.ts#L737-L747
|
|
254
254
|
*/
|
|
255
255
|
function getProxyUrl(proxy) {
|
|
256
|
+
if (!proxy)
|
|
257
|
+
return null;
|
|
256
258
|
if (typeof proxy === 'string') {
|
|
257
259
|
return new URL(proxy);
|
|
258
260
|
}
|
|
@@ -314,12 +316,9 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
314
316
|
if (!i_know_what_im_doing) {
|
|
315
317
|
warnManualConfig(config);
|
|
316
318
|
}
|
|
317
|
-
|
|
318
|
-
if (os) {
|
|
319
|
-
checkValidOS(os);
|
|
320
|
-
}
|
|
319
|
+
const operatingSystems = validateOS(os);
|
|
321
320
|
// webgl_config requires OS to be set
|
|
322
|
-
|
|
321
|
+
if (!operatingSystems && webgl_config) {
|
|
323
322
|
throw new Error('OS must be set when using webgl_config');
|
|
324
323
|
}
|
|
325
324
|
// Add the default addons
|
|
@@ -342,7 +341,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
342
341
|
if (!fingerprint) {
|
|
343
342
|
fingerprint = generateFingerprint(window, {
|
|
344
343
|
screen: screen || getScreenCons(headless || 'DISPLAY' in env),
|
|
345
|
-
|
|
344
|
+
operatingSystems,
|
|
346
345
|
});
|
|
347
346
|
}
|
|
348
347
|
else {
|
|
@@ -377,7 +376,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
377
376
|
// Set a fixed font spacing seed
|
|
378
377
|
setInto(config, 'fonts:spacing_seed', Math.floor(Math.random() * 1_073_741_824));
|
|
379
378
|
// Handle proxy
|
|
380
|
-
const proxyUrl =
|
|
379
|
+
const proxyUrl = getProxyUrl(proxy);
|
|
381
380
|
// Set geolocation
|
|
382
381
|
if (geoip) {
|
|
383
382
|
geoipAllowed();
|
|
@@ -439,17 +438,17 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
439
438
|
// If the user has provided a specific WebGL vendor/renderer pair, use it
|
|
440
439
|
let webgl_fp;
|
|
441
440
|
if (webgl_config) {
|
|
442
|
-
webgl_fp = sampleWebGL(targetOS, ...webgl_config);
|
|
441
|
+
webgl_fp = await sampleWebGL(targetOS, ...webgl_config);
|
|
443
442
|
}
|
|
444
443
|
else {
|
|
445
|
-
webgl_fp = sampleWebGL(targetOS);
|
|
444
|
+
webgl_fp = await sampleWebGL(targetOS);
|
|
446
445
|
}
|
|
447
|
-
const
|
|
446
|
+
const { webGl2Enabled, ...webGlConfig } = webgl_fp;
|
|
448
447
|
// Merge the WebGL fingerprint into the config
|
|
449
|
-
mergeInto(config,
|
|
448
|
+
mergeInto(config, webGlConfig);
|
|
450
449
|
// Set the WebGL preferences
|
|
451
450
|
mergeInto(firefox_user_prefs, {
|
|
452
|
-
'webgl.enable-webgl2':
|
|
451
|
+
'webgl.enable-webgl2': webGl2Enabled,
|
|
453
452
|
'webgl.force-enabled': true,
|
|
454
453
|
});
|
|
455
454
|
}
|
|
@@ -490,7 +489,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
490
489
|
server: proxyUrl.origin,
|
|
491
490
|
username: proxyUrl.username,
|
|
492
491
|
password: proxyUrl.password,
|
|
493
|
-
bypass: typeof proxy === 'string' ? undefined : proxy
|
|
492
|
+
bypass: typeof proxy === 'string' ? undefined : proxy?.bypass,
|
|
494
493
|
} : undefined,
|
|
495
494
|
"headless": headless,
|
|
496
495
|
...launch_options,
|
package/dist/webgl/sample.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
interface WebGLData {
|
|
2
2
|
vendor: string;
|
|
3
3
|
renderer: string;
|
|
4
|
-
data:
|
|
4
|
+
data: string;
|
|
5
|
+
win: number;
|
|
6
|
+
mac: number;
|
|
7
|
+
lin: number;
|
|
8
|
+
webGl2Enabled: boolean;
|
|
5
9
|
}
|
|
6
|
-
export declare function sampleWebGL(os:
|
|
10
|
+
export declare function sampleWebGL(os: 'win' | 'mac' | 'lin', vendor?: string, renderer?: string): Promise<WebGLData>;
|
|
7
11
|
interface PossiblePairs {
|
|
8
12
|
[key: string]: Array<{
|
|
9
13
|
vendor: string;
|
package/dist/webgl/sample.js
CHANGED
|
@@ -30,7 +30,7 @@ export async function sampleWebGL(os, vendor, renderer) {
|
|
|
30
30
|
}
|
|
31
31
|
if (vendor && renderer) {
|
|
32
32
|
const result = rows[0];
|
|
33
|
-
if (result[
|
|
33
|
+
if (result[os] <= 0) {
|
|
34
34
|
db.all(`SELECT DISTINCT vendor, renderer FROM webgl_fingerprints WHERE ${os} > 0`, [], (err, pairs) => {
|
|
35
35
|
if (err) {
|
|
36
36
|
reject(err);
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "camoufox-js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rimraf dist && tsc && npm run copy-files",
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "vitest",
|
|
9
9
|
"copy-files": "cp -r src/data-files dist/data-files"
|
|
10
10
|
},
|
|
11
11
|
"bin": "dist/__main__.js",
|
|
@@ -33,7 +33,14 @@
|
|
|
33
33
|
"xml2js": "^0.6.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"@types/adm-zip": "^0.5.7",
|
|
37
|
+
"@types/js-yaml": "^4.0.9",
|
|
38
|
+
"@types/language-tags": "^1.0.4",
|
|
36
39
|
"@types/node": "^22.13.2",
|
|
37
|
-
"
|
|
40
|
+
"@types/progress": "^2.0.7",
|
|
41
|
+
"@types/xml2js": "^0.4.14",
|
|
42
|
+
"rimraf": "^6.0.1",
|
|
43
|
+
"typescript": "^5.8.3",
|
|
44
|
+
"vitest": "^3.1.1"
|
|
38
45
|
}
|
|
39
46
|
}
|