camoufox-js 0.6.2 → 0.8.0
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/__main__.js +21 -31
- package/dist/__version__.js +2 -2
- package/dist/addons.d.ts +1 -1
- package/dist/addons.js +10 -10
- package/dist/fingerprints.d.ts +1 -1
- package/dist/fingerprints.js +16 -18
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/ip.js +5 -5
- package/dist/locale.js +71 -43
- package/dist/mappings/browserforge.config.d.ts +47 -0
- package/dist/mappings/browserforge.config.js +72 -0
- package/dist/mappings/fonts.config.d.ts +6 -0
- package/dist/mappings/fonts.config.js +822 -0
- package/dist/mappings/warnings.config.d.ts +16 -0
- package/dist/mappings/warnings.config.js +28 -0
- package/dist/pkgman.d.ts +3 -6
- package/dist/pkgman.js +60 -61
- package/dist/server.d.ts +2 -2
- package/dist/server.js +3 -3
- package/dist/sync_api.d.ts +4 -4
- package/dist/sync_api.js +6 -6
- package/dist/utils.d.ts +9 -9
- package/dist/utils.js +115 -112
- package/dist/virtdisplay.js +33 -23
- package/dist/warnings.js +3 -5
- package/dist/webgl/sample.d.ts +6 -5
- package/dist/webgl/sample.js +29 -35
- package/package.json +58 -47
- package/dist/data-files/browserforge.yml +0 -68
- package/dist/data-files/fonts.json +0 -11
- package/dist/data-files/warnings.yml +0 -51
package/dist/__main__.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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
10
|
class CamoufoxUpdate extends CamoufoxFetcher {
|
|
11
11
|
currentVerStr;
|
|
12
12
|
constructor() {
|
|
@@ -16,7 +16,7 @@ class CamoufoxUpdate extends CamoufoxFetcher {
|
|
|
16
16
|
this.currentVerStr = installedVerStr();
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
|
-
if (error instanceof Error && error.name ===
|
|
19
|
+
if (error instanceof Error && error.name === "FileNotFoundError") {
|
|
20
20
|
this.currentVerStr = null;
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
@@ -30,7 +30,7 @@ class CamoufoxUpdate extends CamoufoxFetcher {
|
|
|
30
30
|
return updater;
|
|
31
31
|
}
|
|
32
32
|
isUpdateNeeded() {
|
|
33
|
-
if (getAsBooleanFromENV(
|
|
33
|
+
if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
|
|
34
34
|
console.log("Skipping browser download / update check due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
@@ -60,9 +60,7 @@ class CamoufoxUpdate extends CamoufoxFetcher {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
const program = new Command();
|
|
63
|
-
program
|
|
64
|
-
.command('fetch')
|
|
65
|
-
.action(async () => {
|
|
63
|
+
program.command("fetch").action(async () => {
|
|
66
64
|
const updater = await CamoufoxUpdate.create();
|
|
67
65
|
await updater.update();
|
|
68
66
|
if (ALLOW_GEOIP) {
|
|
@@ -70,18 +68,16 @@ program
|
|
|
70
68
|
}
|
|
71
69
|
maybeDownloadAddons(DefaultAddons);
|
|
72
70
|
});
|
|
73
|
-
program
|
|
74
|
-
.command('remove')
|
|
75
|
-
.action(async () => {
|
|
71
|
+
program.command("remove").action(async () => {
|
|
76
72
|
const updater = await CamoufoxUpdate.create();
|
|
77
|
-
if (!await updater.cleanup()) {
|
|
73
|
+
if (!(await updater.cleanup())) {
|
|
78
74
|
console.log("Camoufox binaries not found!", "red");
|
|
79
75
|
}
|
|
80
76
|
removeMMDB();
|
|
81
77
|
});
|
|
82
78
|
program
|
|
83
|
-
.command(
|
|
84
|
-
.argument(
|
|
79
|
+
.command("test")
|
|
80
|
+
.argument("[url]", "URL to open", null)
|
|
85
81
|
.action(async (url) => {
|
|
86
82
|
const browser = await Camoufox({
|
|
87
83
|
headless: false,
|
|
@@ -96,28 +92,22 @@ program
|
|
|
96
92
|
}
|
|
97
93
|
await page.pause();
|
|
98
94
|
});
|
|
99
|
-
program
|
|
100
|
-
.command('server')
|
|
101
|
-
.action(async () => {
|
|
95
|
+
program.command("server").action(async () => {
|
|
102
96
|
const server = await launchServer({});
|
|
103
97
|
console.log(`Camoufox server started at ${server.wsEndpoint()}`);
|
|
104
98
|
console.log();
|
|
105
99
|
console.log(`You can connect to it using Playwright's BrowserType.connect() method.`);
|
|
106
100
|
console.log(`To stop the server, press Ctrl+C or close this terminal.`);
|
|
107
101
|
});
|
|
108
|
-
program
|
|
109
|
-
.command('path')
|
|
110
|
-
.action(() => {
|
|
102
|
+
program.command("path").action(() => {
|
|
111
103
|
console.log(INSTALL_DIR);
|
|
112
104
|
});
|
|
113
|
-
program
|
|
114
|
-
.command('version')
|
|
115
|
-
.action(async () => {
|
|
105
|
+
program.command("version").action(async () => {
|
|
116
106
|
try {
|
|
117
|
-
const pkgVersion = require(
|
|
118
|
-
console.log(`Pip package:\tv${pkgVersion(
|
|
107
|
+
const pkgVersion = require("pkg-version");
|
|
108
|
+
console.log(`Pip package:\tv${pkgVersion("camoufox")}`);
|
|
119
109
|
}
|
|
120
|
-
catch (
|
|
110
|
+
catch (_error) {
|
|
121
111
|
console.log("Pip package:\tNot installed!", "red");
|
|
122
112
|
}
|
|
123
113
|
const updater = await CamoufoxUpdate.create();
|
package/dist/__version__.js
CHANGED
|
@@ -5,8 +5,8 @@ export class CONSTRAINTS {
|
|
|
5
5
|
/**
|
|
6
6
|
* The minimum and maximum supported versions of the Camoufox browser.
|
|
7
7
|
*/
|
|
8
|
-
static MIN_VERSION =
|
|
9
|
-
static MAX_VERSION =
|
|
8
|
+
static MIN_VERSION = "beta.19";
|
|
9
|
+
static MAX_VERSION = "1";
|
|
10
10
|
static asRange() {
|
|
11
11
|
/**
|
|
12
12
|
* Returns the version range as a string.
|
package/dist/addons.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const DefaultAddons: {
|
|
|
5
5
|
UBO: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function confirmPaths(paths: string[]): void;
|
|
8
|
-
export declare function addDefaultAddons(
|
|
8
|
+
export declare function addDefaultAddons(_addonsList: string[], _excludeList?: (keyof typeof DefaultAddons)[]): void;
|
|
9
9
|
/**
|
|
10
10
|
* Downloads and extracts an addon from a given URL to a specified path
|
|
11
11
|
*/
|
package/dist/addons.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { getAsBooleanFromENV } from
|
|
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
6
|
export const DefaultAddons = {
|
|
7
7
|
/**
|
|
8
8
|
* Default addons to be downloaded
|
|
9
9
|
*/
|
|
10
|
-
UBO: "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi"
|
|
10
|
+
UBO: "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi",
|
|
11
11
|
};
|
|
12
12
|
export function confirmPaths(paths) {
|
|
13
13
|
/**
|
|
@@ -17,12 +17,12 @@ export function confirmPaths(paths) {
|
|
|
17
17
|
if (!fs.existsSync(path) || !fs.lstatSync(path).isDirectory()) {
|
|
18
18
|
throw new InvalidAddonPath(path);
|
|
19
19
|
}
|
|
20
|
-
if (!fs.existsSync(join(path,
|
|
21
|
-
throw new InvalidAddonPath(
|
|
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
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
export function addDefaultAddons(
|
|
25
|
+
export function addDefaultAddons(_addonsList, _excludeList = []) {
|
|
26
26
|
// TODO - enable addons
|
|
27
27
|
/**
|
|
28
28
|
* Adds default addons, minus any specified in excludeList, to addonsList
|
|
@@ -48,7 +48,7 @@ function getAddonPath(addonName) {
|
|
|
48
48
|
* Skips downloading if the addon is already downloaded
|
|
49
49
|
*/
|
|
50
50
|
export function maybeDownloadAddons(addons, addonsList = []) {
|
|
51
|
-
if (getAsBooleanFromENV(
|
|
51
|
+
if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
|
|
52
52
|
console.log("Skipping addon download due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
|
|
53
53
|
return;
|
|
54
54
|
}
|
package/dist/fingerprints.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fingerprint, FingerprintGeneratorOptions } from
|
|
1
|
+
import { type Fingerprint, type FingerprintGeneratorOptions } from "fingerprint-generator";
|
|
2
2
|
export declare const SUPPORTED_OS: readonly ["linux", "macos", "windows"];
|
|
3
3
|
export declare function fromBrowserforge(fingerprint: Fingerprint, ffVersion?: string): Record<string, any>;
|
|
4
4
|
export declare function generateFingerprint(window?: [number, number], config?: Partial<FingerprintGeneratorOptions>): Fingerprint;
|
package/dist/fingerprints.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export const SUPPORTED_OS = ['linux', 'macos', 'windows'];
|
|
5
|
-
const BROWSERFORGE_DATA = loadYaml(join(import.meta.dirname, 'data-files', 'browserforge.yml'));
|
|
1
|
+
import { FingerprintGenerator, } from "fingerprint-generator";
|
|
2
|
+
import BROWSERFORGE_DATA from "./mappings/browserforge.config.js";
|
|
3
|
+
export const SUPPORTED_OS = ["linux", "macos", "windows"];
|
|
6
4
|
const FP_GENERATOR = new FingerprintGenerator({
|
|
7
|
-
browsers: [
|
|
5
|
+
browsers: ["firefox"],
|
|
8
6
|
operatingSystems: SUPPORTED_OS,
|
|
9
7
|
});
|
|
10
8
|
function randrange(min, max) {
|
|
@@ -17,41 +15,41 @@ function _castToProperties(camoufoxData, castEnum, bfDict, ffVersion) {
|
|
|
17
15
|
const typeKey = castEnum[key];
|
|
18
16
|
if (!typeKey)
|
|
19
17
|
continue;
|
|
20
|
-
if (typeof data ===
|
|
18
|
+
if (typeof data === "object" && !Array.isArray(data)) {
|
|
21
19
|
_castToProperties(camoufoxData, typeKey, data, ffVersion);
|
|
22
20
|
continue;
|
|
23
21
|
}
|
|
24
|
-
if (typeKey.startsWith("screen.") && typeof data ===
|
|
22
|
+
if (typeKey.startsWith("screen.") && typeof data === "number" && data < 0) {
|
|
25
23
|
data = 0;
|
|
26
24
|
}
|
|
27
|
-
if (ffVersion && typeof data ===
|
|
25
|
+
if (ffVersion && typeof data === "string") {
|
|
28
26
|
data = data.replace(/(?<!\d)(1[0-9]{2})(\.0)(?!\d)/, `${ffVersion}$2`);
|
|
29
27
|
}
|
|
30
28
|
camoufoxData[typeKey] = data;
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
function handleScreenXY(camoufoxData, fpScreen) {
|
|
34
|
-
if (
|
|
32
|
+
if ("window.screenY" in camoufoxData)
|
|
35
33
|
return;
|
|
36
|
-
|
|
34
|
+
const screenX = fpScreen.screenX;
|
|
37
35
|
if (!screenX) {
|
|
38
|
-
camoufoxData[
|
|
39
|
-
camoufoxData[
|
|
36
|
+
camoufoxData["window.screenX"] = 0;
|
|
37
|
+
camoufoxData["window.screenY"] = 0;
|
|
40
38
|
return;
|
|
41
39
|
}
|
|
42
40
|
if (screenX >= -50 && screenX <= 50) {
|
|
43
|
-
camoufoxData[
|
|
41
|
+
camoufoxData["window.screenY"] = screenX;
|
|
44
42
|
return;
|
|
45
43
|
}
|
|
46
|
-
|
|
44
|
+
const screenY = fpScreen.availHeight - fpScreen.outerHeight;
|
|
47
45
|
if (screenY === 0) {
|
|
48
|
-
camoufoxData[
|
|
46
|
+
camoufoxData["window.screenY"] = 0;
|
|
49
47
|
}
|
|
50
48
|
else if (screenY > 0) {
|
|
51
|
-
camoufoxData[
|
|
49
|
+
camoufoxData["window.screenY"] = randrange(0, screenY);
|
|
52
50
|
}
|
|
53
51
|
else {
|
|
54
|
-
camoufoxData[
|
|
52
|
+
camoufoxData["window.screenY"] = randrange(screenY, 0);
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
55
|
export function fromBrowserforge(fingerprint, ffVersion) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { launchServer } from "./server.js";
|
|
2
|
+
export { Camoufox, NewBrowser } from "./sync_api.js";
|
|
3
|
+
export { type LaunchOptions, launchOptions } from "./utils.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { launchServer } from "./server.js";
|
|
2
|
+
export { Camoufox, NewBrowser } from "./sync_api.js";
|
|
3
|
+
export { launchOptions } from "./utils.js";
|
package/dist/ip.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Impit } from
|
|
1
|
+
import { Impit } from "impit";
|
|
2
2
|
export class InvalidIP extends Error {
|
|
3
3
|
}
|
|
4
4
|
export class InvalidProxy extends Error {
|
|
@@ -10,20 +10,20 @@ export class ProxyHelper {
|
|
|
10
10
|
throw new InvalidProxy(`Invalid proxy server: ${server}`);
|
|
11
11
|
}
|
|
12
12
|
return {
|
|
13
|
-
schema: proxyMatch[1] ||
|
|
13
|
+
schema: proxyMatch[1] || "http",
|
|
14
14
|
url: proxyMatch[2],
|
|
15
|
-
port: proxyMatch[3]
|
|
15
|
+
port: proxyMatch[3],
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
static asString(proxy) {
|
|
19
|
-
const { schema, url, port } =
|
|
19
|
+
const { schema, url, port } = ProxyHelper.parseServer(proxy.server);
|
|
20
20
|
let result = `${schema}://`;
|
|
21
21
|
if (proxy.username) {
|
|
22
22
|
result += proxy.username;
|
|
23
23
|
if (proxy.password) {
|
|
24
24
|
result += `:${proxy.password}`;
|
|
25
25
|
}
|
|
26
|
-
result +=
|
|
26
|
+
result += "@";
|
|
27
27
|
}
|
|
28
28
|
result += url;
|
|
29
29
|
if (port) {
|
package/dist/locale.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import tags from "language-tags";
|
|
4
|
+
import maxmind from "maxmind";
|
|
5
|
+
import xml2js from "xml2js";
|
|
6
|
+
import { InvalidLocale, MissingRelease, NotInstalledGeoIPExtra, UnknownIPLocation, UnknownLanguage, UnknownTerritory, } from "./exceptions.js";
|
|
7
|
+
import { validateIP } from "./ip.js";
|
|
8
|
+
import { GitHubDownloader, INSTALL_DIR, webdl } from "./pkgman.js";
|
|
9
|
+
import { getAsBooleanFromENV } from "./utils.js";
|
|
10
|
+
import { LeakWarning } from "./warnings.js";
|
|
11
11
|
export const ALLOW_GEOIP = true;
|
|
12
12
|
class Locale {
|
|
13
13
|
language;
|
|
@@ -29,11 +29,11 @@ class Locale {
|
|
|
29
29
|
throw new Error("Region is required for config");
|
|
30
30
|
}
|
|
31
31
|
const data = {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
"locale:region": this.region,
|
|
33
|
+
"locale:language": this.language,
|
|
34
34
|
};
|
|
35
35
|
if (this.script) {
|
|
36
|
-
data[
|
|
36
|
+
data["locale:script"] = this.script;
|
|
37
37
|
}
|
|
38
38
|
return data;
|
|
39
39
|
}
|
|
@@ -53,13 +53,13 @@ class Geolocation {
|
|
|
53
53
|
}
|
|
54
54
|
asConfig() {
|
|
55
55
|
const data = {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
"geolocation:longitude": this.longitude,
|
|
57
|
+
"geolocation:latitude": this.latitude,
|
|
58
|
+
timezone: this.timezone,
|
|
59
59
|
...this.locale.asConfig(),
|
|
60
60
|
};
|
|
61
61
|
if (this.accuracy !== undefined) {
|
|
62
|
-
data[
|
|
62
|
+
data["geolocation:accuracy"] = this.accuracy;
|
|
63
63
|
}
|
|
64
64
|
return data;
|
|
65
65
|
}
|
|
@@ -76,7 +76,7 @@ export function normalizeLocale(locale) {
|
|
|
76
76
|
if (!parser.region) {
|
|
77
77
|
throw InvalidLocale.invalidInput(locale);
|
|
78
78
|
}
|
|
79
|
-
return new Locale(parser.language()?.format() ??
|
|
79
|
+
return new Locale(parser.language()?.format() ?? "en", parser.region()?.format(), parser.language()?.script()?.format());
|
|
80
80
|
}
|
|
81
81
|
export function handleLocale(locale, ignoreRegion = false) {
|
|
82
82
|
if (locale.length > 3) {
|
|
@@ -98,7 +98,7 @@ export function handleLocale(locale, ignoreRegion = false) {
|
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
100
100
|
const language = SELECTOR.fromLanguage(locale);
|
|
101
|
-
LeakWarning.warn(
|
|
101
|
+
LeakWarning.warn("no_region");
|
|
102
102
|
return language;
|
|
103
103
|
}
|
|
104
104
|
catch (e) {
|
|
@@ -111,8 +111,8 @@ export function handleLocale(locale, ignoreRegion = false) {
|
|
|
111
111
|
throw InvalidLocale.invalidInput(locale);
|
|
112
112
|
}
|
|
113
113
|
export function handleLocales(locales, config) {
|
|
114
|
-
if (typeof locales ===
|
|
115
|
-
locales = locales.split(
|
|
114
|
+
if (typeof locales === "string") {
|
|
115
|
+
locales = locales.split(",").map((loc) => loc.trim());
|
|
116
116
|
}
|
|
117
117
|
const intlLocale = handleLocale(locales[0]).asConfig();
|
|
118
118
|
for (const key in intlLocale) {
|
|
@@ -121,39 +121,39 @@ export function handleLocales(locales, config) {
|
|
|
121
121
|
if (locales.length < 2) {
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
|
-
config[
|
|
124
|
+
config["locale:all"] = joinUnique(locales.map((locale) => handleLocale(locale, true).asString()));
|
|
125
125
|
}
|
|
126
126
|
function joinUnique(seq) {
|
|
127
127
|
const seen = new Set();
|
|
128
|
-
return seq.filter(x => !seen.has(x) && seen.add(x)).join(
|
|
128
|
+
return seq.filter((x) => !seen.has(x) && seen.add(x)).join(", ");
|
|
129
129
|
}
|
|
130
|
-
const MMDB_FILE = path.join(INSTALL_DIR.toString(),
|
|
130
|
+
const MMDB_FILE = path.join(INSTALL_DIR.toString(), "GeoLite2-City.mmdb");
|
|
131
131
|
const MMDB_REPO = "P3TERX/GeoLite.mmdb";
|
|
132
132
|
class MaxMindDownloader extends GitHubDownloader {
|
|
133
133
|
checkAsset(asset) {
|
|
134
|
-
if (asset
|
|
135
|
-
return asset
|
|
134
|
+
if (asset.name.endsWith("-City.mmdb")) {
|
|
135
|
+
return asset.browser_download_url;
|
|
136
136
|
}
|
|
137
137
|
return null;
|
|
138
138
|
}
|
|
139
139
|
missingAssetError() {
|
|
140
|
-
throw new MissingRelease(
|
|
140
|
+
throw new MissingRelease("Failed to find GeoIP database release asset");
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
export function geoipAllowed() {
|
|
144
144
|
if (!ALLOW_GEOIP) {
|
|
145
|
-
throw new NotInstalledGeoIPExtra(
|
|
145
|
+
throw new NotInstalledGeoIPExtra("Please install the geoip extra to use this feature: pip install camoufox[geoip]");
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
export async function downloadMMDB() {
|
|
149
149
|
geoipAllowed();
|
|
150
|
-
if (getAsBooleanFromENV(
|
|
150
|
+
if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
|
|
151
151
|
console.log("Skipping GeoIP database download due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
|
-
const assetUrl = await
|
|
154
|
+
const assetUrl = await new MaxMindDownloader(MMDB_REPO).getAsset();
|
|
155
155
|
const fileStream = fs.createWriteStream(MMDB_FILE);
|
|
156
|
-
await webdl(assetUrl,
|
|
156
|
+
await webdl(assetUrl, "Downloading GeoIP database", true, fileStream);
|
|
157
157
|
}
|
|
158
158
|
export function removeMMDB() {
|
|
159
159
|
if (!fs.existsSync(MMDB_FILE)) {
|
|
@@ -172,19 +172,22 @@ export async function getGeolocation(ip) {
|
|
|
172
172
|
const resp = reader.get(ip);
|
|
173
173
|
const isoCode = resp.country?.iso_code.toUpperCase();
|
|
174
174
|
const location = resp.location;
|
|
175
|
-
if (!location?.longitude ||
|
|
175
|
+
if (!location?.longitude ||
|
|
176
|
+
!location?.latitude ||
|
|
177
|
+
!location?.time_zone ||
|
|
178
|
+
!isoCode) {
|
|
176
179
|
throw new UnknownIPLocation(`Unknown IP location: ${ip}`);
|
|
177
180
|
}
|
|
178
181
|
const locale = SELECTOR.fromRegion(isoCode);
|
|
179
182
|
return new Geolocation(locale, location.longitude, location.latitude, location.time_zone);
|
|
180
183
|
}
|
|
181
184
|
async function getUnicodeInfo() {
|
|
182
|
-
const data = await fs.promises.readFile(path.join(import.meta.dirname,
|
|
185
|
+
const data = await fs.promises.readFile(path.join(import.meta.dirname, "data-files", "territoryInfo.xml"));
|
|
183
186
|
const parser = new xml2js.Parser();
|
|
184
187
|
return parser.parseStringPromise(data);
|
|
185
188
|
}
|
|
186
189
|
function asFloat(element, attr) {
|
|
187
|
-
return parseFloat(element[attr] ||
|
|
190
|
+
return parseFloat(element[attr] || "0");
|
|
188
191
|
}
|
|
189
192
|
class StatisticalLocaleSelector {
|
|
190
193
|
root;
|
|
@@ -204,7 +207,7 @@ class StatisticalLocaleSelector {
|
|
|
204
207
|
throw new Error(`No language data found for region: ${isoCode}`);
|
|
205
208
|
}
|
|
206
209
|
const languages = langPopulations.map((lang) => lang.$.type);
|
|
207
|
-
const percentages = langPopulations.map((lang) => asFloat(lang.$,
|
|
210
|
+
const percentages = langPopulations.map((lang) => asFloat(lang.$, "populationPercent"));
|
|
208
211
|
return this.normalizeProbabilities(languages, percentages);
|
|
209
212
|
}
|
|
210
213
|
loadLanguageData(language) {
|
|
@@ -219,9 +222,10 @@ class StatisticalLocaleSelector {
|
|
|
219
222
|
const langPop = terr.languagePopulation.find((lp) => lp.$.type === language);
|
|
220
223
|
if (region && langPop) {
|
|
221
224
|
regions.push(region);
|
|
222
|
-
percentages.push(asFloat(langPop.$,
|
|
223
|
-
asFloat(terr.$,
|
|
224
|
-
|
|
225
|
+
percentages.push(((asFloat(langPop.$, "populationPercent") *
|
|
226
|
+
asFloat(terr.$, "literacyPercent")) /
|
|
227
|
+
10000) *
|
|
228
|
+
asFloat(terr.$, "population"));
|
|
225
229
|
}
|
|
226
230
|
}
|
|
227
231
|
if (!regions.length) {
|
|
@@ -231,16 +235,40 @@ class StatisticalLocaleSelector {
|
|
|
231
235
|
}
|
|
232
236
|
normalizeProbabilities(languages, freq) {
|
|
233
237
|
const total = freq.reduce((a, b) => a + b, 0);
|
|
234
|
-
return [languages, freq.map(f => f / total)];
|
|
238
|
+
return [languages, freq.map((f) => f / total)];
|
|
235
239
|
}
|
|
236
240
|
weightedRandomChoice(items, weights) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
241
|
+
if (items.length === 0) {
|
|
242
|
+
throw new Error("items must not be empty");
|
|
243
|
+
}
|
|
244
|
+
if (items.length !== weights.length) {
|
|
245
|
+
throw new Error("items and weights must have the same length");
|
|
246
|
+
}
|
|
247
|
+
let total = 0;
|
|
248
|
+
for (const w of weights) {
|
|
249
|
+
if (w < 0) {
|
|
250
|
+
throw new Error("weights must be non-negative");
|
|
251
|
+
}
|
|
252
|
+
total += w;
|
|
253
|
+
}
|
|
254
|
+
// Fallback to uniform choice if all weights are zero
|
|
255
|
+
if (total === 0) {
|
|
256
|
+
return items[Math.floor(Math.random() * items.length)];
|
|
257
|
+
}
|
|
258
|
+
const r = Math.random() * total;
|
|
259
|
+
let acc = 0;
|
|
260
|
+
for (let i = 0; i < items.length; i++) {
|
|
261
|
+
acc += weights[i];
|
|
262
|
+
if (r < acc) {
|
|
263
|
+
return items[i];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Numerical edge case
|
|
267
|
+
return items[items.length - 1];
|
|
240
268
|
}
|
|
241
269
|
fromRegion(region) {
|
|
242
270
|
const [languages, probabilities] = this.loadTerritoryData(region);
|
|
243
|
-
const language = this.weightedRandomChoice(languages, probabilities).replace(
|
|
271
|
+
const language = this.weightedRandomChoice(languages, probabilities).replace("_", "-");
|
|
244
272
|
return normalizeLocale(`${language}-${region}`);
|
|
245
273
|
}
|
|
246
274
|
fromLanguage(language) {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mappings of Browserforge fingerprints to Camoufox config properties.
|
|
3
|
+
*/
|
|
4
|
+
declare const _default: {
|
|
5
|
+
navigator: {
|
|
6
|
+
userAgent: string;
|
|
7
|
+
doNotTrack: string;
|
|
8
|
+
appCodeName: string;
|
|
9
|
+
appName: string;
|
|
10
|
+
appVersion: string;
|
|
11
|
+
oscpu: string;
|
|
12
|
+
platform: string;
|
|
13
|
+
hardwareConcurrency: string;
|
|
14
|
+
product: string;
|
|
15
|
+
maxTouchPoints: string;
|
|
16
|
+
extraProperties: {
|
|
17
|
+
globalPrivacyControl: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
screen: {
|
|
21
|
+
availLeft: string;
|
|
22
|
+
availTop: string;
|
|
23
|
+
availWidth: string;
|
|
24
|
+
availHeight: string;
|
|
25
|
+
height: string;
|
|
26
|
+
width: string;
|
|
27
|
+
colorDepth: string;
|
|
28
|
+
pixelDepth: string;
|
|
29
|
+
pageXOffset: string;
|
|
30
|
+
pageYOffset: string;
|
|
31
|
+
outerHeight: string;
|
|
32
|
+
outerWidth: string;
|
|
33
|
+
innerHeight: string;
|
|
34
|
+
innerWidth: string;
|
|
35
|
+
screenX: string;
|
|
36
|
+
screenY: string;
|
|
37
|
+
};
|
|
38
|
+
headers: {
|
|
39
|
+
"Accept-Encoding": string;
|
|
40
|
+
};
|
|
41
|
+
battery: {
|
|
42
|
+
charging: string;
|
|
43
|
+
chargingTime: string;
|
|
44
|
+
dischargingTime: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export default _default;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mappings of Browserforge fingerprints to Camoufox config properties.
|
|
3
|
+
*/
|
|
4
|
+
export default {
|
|
5
|
+
navigator: {
|
|
6
|
+
// Note: Browserforge tends to have outdated UAs.
|
|
7
|
+
// The version will be replaced in Camoufox.
|
|
8
|
+
userAgent: "navigator.userAgent",
|
|
9
|
+
// userAgentData not in Firefox
|
|
10
|
+
doNotTrack: "navigator.doNotTrack",
|
|
11
|
+
appCodeName: "navigator.appCodeName",
|
|
12
|
+
appName: "navigator.appName",
|
|
13
|
+
appVersion: "navigator.appVersion",
|
|
14
|
+
oscpu: "navigator.oscpu",
|
|
15
|
+
// webdriver is always True
|
|
16
|
+
// Locale is now implemented separately:
|
|
17
|
+
// language: "navigator.language",
|
|
18
|
+
// languages: "navigator.languages",
|
|
19
|
+
platform: "navigator.platform",
|
|
20
|
+
// deviceMemory not in Firefox
|
|
21
|
+
hardwareConcurrency: "navigator.hardwareConcurrency",
|
|
22
|
+
product: "navigator.product",
|
|
23
|
+
// Never override productSub #105
|
|
24
|
+
// productSub: "navigator.productSub",
|
|
25
|
+
// vendor is not necessary
|
|
26
|
+
// vendorSub is not necessary
|
|
27
|
+
maxTouchPoints: "navigator.maxTouchPoints",
|
|
28
|
+
extraProperties: {
|
|
29
|
+
// Note: Changing pdfViewerEnabled is not recommended. This will be kept to True.
|
|
30
|
+
globalPrivacyControl: "navigator.globalPrivacyControl",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
screen: {
|
|
34
|
+
// hasHDR is not implemented in Camoufox
|
|
35
|
+
availLeft: "screen.availLeft",
|
|
36
|
+
availTop: "screen.availTop",
|
|
37
|
+
availWidth: "screen.availWidth",
|
|
38
|
+
availHeight: "screen.availHeight",
|
|
39
|
+
height: "screen.height",
|
|
40
|
+
width: "screen.width",
|
|
41
|
+
colorDepth: "screen.colorDepth",
|
|
42
|
+
pixelDepth: "screen.pixelDepth",
|
|
43
|
+
// devicePixelRatio is not recommended. Any value other than 1.0 is suspicious.
|
|
44
|
+
pageXOffset: "screen.pageXOffset",
|
|
45
|
+
pageYOffset: "screen.pageYOffset",
|
|
46
|
+
outerHeight: "window.outerHeight",
|
|
47
|
+
outerWidth: "window.outerWidth",
|
|
48
|
+
innerHeight: "window.innerHeight",
|
|
49
|
+
innerWidth: "window.innerWidth",
|
|
50
|
+
screenX: "window.screenX",
|
|
51
|
+
screenY: "window.screenY",
|
|
52
|
+
// Tends to generate out of bounds (network inconsistencies):
|
|
53
|
+
// clientWidth: "document.body.clientWidth",
|
|
54
|
+
// clientHeight: "document.body.clientHeight",
|
|
55
|
+
},
|
|
56
|
+
// videoCard: {
|
|
57
|
+
// renderer: "webgl:renderer",
|
|
58
|
+
// vendor: "webgl:vendor",
|
|
59
|
+
// },
|
|
60
|
+
headers: {
|
|
61
|
+
// headers.User-Agent is redundant with navigator.userAgent
|
|
62
|
+
// headers.Accept-Language is redundant with locale:*
|
|
63
|
+
"Accept-Encoding": "headers.Accept-Encoding",
|
|
64
|
+
},
|
|
65
|
+
battery: {
|
|
66
|
+
charging: "battery:charging",
|
|
67
|
+
chargingTime: "battery:chargingTime",
|
|
68
|
+
dischargingTime: "battery:dischargingTime",
|
|
69
|
+
},
|
|
70
|
+
// Unsupported: videoCodecs, audioCodecs, pluginsData, multimediaDevices
|
|
71
|
+
// Fonts are listed through the launcher.
|
|
72
|
+
};
|