bexxcv 0.0.0-stage → 1.0.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/README.md +493 -2
- package/dist/__main__.d.ts +2 -0
- package/dist/__main__.js +156 -0
- package/dist/__version__.d.ts +5 -0
- package/dist/__version__.js +5 -0
- package/dist/addons.d.ts +7 -0
- package/dist/addons.js +56 -0
- package/dist/browser-pin.d.ts +15 -0
- package/dist/browser-pin.js +34 -0
- package/dist/data-files/browser-pin.json +7 -0
- package/dist/data-files/territoryInfo.xml +2024 -0
- package/dist/exceptions.d.ts +79 -0
- package/dist/exceptions.js +159 -0
- package/dist/fingerprints.d.ts +5 -0
- package/dist/fingerprints.js +92 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/ip.d.ts +23 -0
- package/dist/ip.js +98 -0
- package/dist/locale.d.ts +26 -0
- package/dist/locale.js +292 -0
- package/dist/mappings/browserforge.config.d.ts +44 -0
- package/dist/mappings/browserforge.config.js +43 -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/multiversion.d.ts +27 -0
- package/dist/multiversion.js +88 -0
- package/dist/pkgman.d.ts +69 -0
- package/dist/pkgman.js +529 -0
- package/dist/selfupdate.d.ts +8 -0
- package/dist/selfupdate.js +84 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +6 -0
- package/dist/sync_api.d.ts +11 -0
- package/dist/sync_api.js +47 -0
- package/dist/utils.d.ts +45 -0
- package/dist/utils.js +514 -0
- package/dist/virtdisplay.d.ts +12 -0
- package/dist/virtdisplay.js +139 -0
- package/dist/warnings.d.ts +4 -0
- package/dist/warnings.js +33 -0
- package/dist/webgl/sample.d.ts +19 -0
- package/dist/webgl/sample.js +103 -0
- package/dist/xvfb.d.ts +6 -0
- package/dist/xvfb.js +25 -0
- package/package.json +103 -5
package/dist/locale.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import tags from "language-tags";
|
|
5
|
+
import maxmind from "maxmind";
|
|
6
|
+
import xml2js from "xml2js";
|
|
7
|
+
import { InvalidLocale, MissingRelease, NotInstalledGeoIPExtra, UnknownIPLocation, UnknownLanguage, UnknownTerritory, } from "./exceptions.js";
|
|
8
|
+
import { validateIP } from "./ip.js";
|
|
9
|
+
import { GitHubDownloader, INSTALL_DIR, webdl } from "./pkgman.js";
|
|
10
|
+
import { getAsBooleanFromENV } from "./utils.js";
|
|
11
|
+
import { LeakWarning } from "./warnings.js";
|
|
12
|
+
const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
export const ALLOW_GEOIP = true;
|
|
14
|
+
class Locale {
|
|
15
|
+
language;
|
|
16
|
+
region;
|
|
17
|
+
script;
|
|
18
|
+
constructor(language, region, script) {
|
|
19
|
+
this.language = language;
|
|
20
|
+
this.region = region;
|
|
21
|
+
this.script = script;
|
|
22
|
+
}
|
|
23
|
+
asString() {
|
|
24
|
+
if (this.region) {
|
|
25
|
+
return `${this.language}-${this.region}`;
|
|
26
|
+
}
|
|
27
|
+
return this.language;
|
|
28
|
+
}
|
|
29
|
+
asConfig() {
|
|
30
|
+
if (!this.region) {
|
|
31
|
+
throw new Error("Region is required for config");
|
|
32
|
+
}
|
|
33
|
+
const data = {
|
|
34
|
+
"locale:region": this.region,
|
|
35
|
+
"locale:language": this.language,
|
|
36
|
+
};
|
|
37
|
+
if (this.script) {
|
|
38
|
+
data["locale:script"] = this.script;
|
|
39
|
+
}
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class Geolocation {
|
|
44
|
+
locale;
|
|
45
|
+
longitude;
|
|
46
|
+
latitude;
|
|
47
|
+
timezone;
|
|
48
|
+
accuracy;
|
|
49
|
+
constructor(locale, longitude, latitude, timezone, accuracy) {
|
|
50
|
+
this.locale = locale;
|
|
51
|
+
this.longitude = longitude;
|
|
52
|
+
this.latitude = latitude;
|
|
53
|
+
this.timezone = timezone;
|
|
54
|
+
this.accuracy = accuracy;
|
|
55
|
+
}
|
|
56
|
+
asConfig() {
|
|
57
|
+
const data = {
|
|
58
|
+
"geolocation:longitude": this.longitude,
|
|
59
|
+
"geolocation:latitude": this.latitude,
|
|
60
|
+
timezone: this.timezone,
|
|
61
|
+
...this.locale.asConfig(),
|
|
62
|
+
};
|
|
63
|
+
if (this.accuracy !== undefined) {
|
|
64
|
+
data["geolocation:accuracy"] = this.accuracy;
|
|
65
|
+
}
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function verifyLocale(loc) {
|
|
70
|
+
if (tags.check(loc)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
throw InvalidLocale.invalidInput(loc);
|
|
74
|
+
}
|
|
75
|
+
export function normalizeLocale(locale) {
|
|
76
|
+
verifyLocale(locale);
|
|
77
|
+
const parser = tags(locale);
|
|
78
|
+
if (!parser.region) {
|
|
79
|
+
throw InvalidLocale.invalidInput(locale);
|
|
80
|
+
}
|
|
81
|
+
return new Locale(parser.language()?.format() ?? "en", parser.region()?.format(), parser.language()?.script()?.format());
|
|
82
|
+
}
|
|
83
|
+
export function handleLocale(locale, ignoreRegion = false) {
|
|
84
|
+
if (locale.length > 3) {
|
|
85
|
+
return normalizeLocale(locale);
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return SELECTOR.fromRegion(locale);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
if (e instanceof UnknownTerritory) {
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (ignoreRegion) {
|
|
98
|
+
verifyLocale(locale);
|
|
99
|
+
return new Locale(locale);
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const language = SELECTOR.fromLanguage(locale);
|
|
103
|
+
LeakWarning.warn("no_region");
|
|
104
|
+
return language;
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
if (e instanceof UnknownLanguage) {
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
throw InvalidLocale.invalidInput(locale);
|
|
114
|
+
}
|
|
115
|
+
export function handleLocales(locales, config) {
|
|
116
|
+
if (typeof locales === "string") {
|
|
117
|
+
locales = locales.split(",").map((loc) => loc.trim());
|
|
118
|
+
}
|
|
119
|
+
const intlLocale = handleLocale(locales[0]).asConfig();
|
|
120
|
+
for (const key in intlLocale) {
|
|
121
|
+
config[key] = intlLocale[key];
|
|
122
|
+
}
|
|
123
|
+
if (locales.length < 2) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
config["locale:all"] = joinUnique(locales.map((locale) => handleLocale(locale, true).asString()));
|
|
127
|
+
}
|
|
128
|
+
function joinUnique(seq) {
|
|
129
|
+
const seen = new Set();
|
|
130
|
+
return seq.filter((x) => !seen.has(x) && seen.add(x)).join(", ");
|
|
131
|
+
}
|
|
132
|
+
const MMDB_FILE = path.join(INSTALL_DIR.toString(), "GeoLite2-City.mmdb");
|
|
133
|
+
const MMDB_REPO = "P3TERX/GeoLite.mmdb";
|
|
134
|
+
class MaxMindDownloader extends GitHubDownloader {
|
|
135
|
+
checkAsset(asset) {
|
|
136
|
+
if (asset.name.endsWith("-City.mmdb")) {
|
|
137
|
+
return asset.browser_download_url;
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
missingAssetError() {
|
|
142
|
+
throw new MissingRelease("Failed to find GeoIP database release asset");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function geoipAllowed() {
|
|
146
|
+
if (!ALLOW_GEOIP) {
|
|
147
|
+
throw new NotInstalledGeoIPExtra("Please install the geoip extra to use this feature: pip install camoufox[geoip]");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export async function downloadMMDB() {
|
|
151
|
+
geoipAllowed();
|
|
152
|
+
if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
|
|
153
|
+
console.log("Skipping GeoIP database download due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const assetUrl = await new MaxMindDownloader(MMDB_REPO).getAsset();
|
|
157
|
+
const tempFile = `${MMDB_FILE}.${process.pid}.download`;
|
|
158
|
+
const fileStream = fs.createWriteStream(tempFile);
|
|
159
|
+
try {
|
|
160
|
+
await webdl(assetUrl, "Downloading GeoIP database", true, fileStream);
|
|
161
|
+
await new Promise((resolve, reject) => fileStream.close((err) => (err ? reject(err) : resolve())));
|
|
162
|
+
fs.renameSync(tempFile, MMDB_FILE);
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
if (!fileStream.closed) {
|
|
166
|
+
await new Promise((resolve) => fileStream.close(() => resolve()));
|
|
167
|
+
}
|
|
168
|
+
fs.rmSync(tempFile, { force: true });
|
|
169
|
+
throw e;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export function removeMMDB() {
|
|
173
|
+
if (!fs.existsSync(MMDB_FILE)) {
|
|
174
|
+
console.log("GeoIP database not found.");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
fs.unlinkSync(MMDB_FILE);
|
|
178
|
+
console.log("GeoIP database removed.");
|
|
179
|
+
}
|
|
180
|
+
export async function getGeolocation(ip) {
|
|
181
|
+
if (!fs.existsSync(MMDB_FILE)) {
|
|
182
|
+
await downloadMMDB();
|
|
183
|
+
}
|
|
184
|
+
validateIP(ip);
|
|
185
|
+
const reader = await maxmind.open(MMDB_FILE);
|
|
186
|
+
const resp = reader.get(ip);
|
|
187
|
+
const isoCode = resp.country?.iso_code.toUpperCase();
|
|
188
|
+
const location = resp.location;
|
|
189
|
+
if (!location?.longitude ||
|
|
190
|
+
!location?.latitude ||
|
|
191
|
+
!location?.time_zone ||
|
|
192
|
+
!isoCode) {
|
|
193
|
+
throw new UnknownIPLocation(`Unknown IP location: ${ip}`);
|
|
194
|
+
}
|
|
195
|
+
const locale = SELECTOR.fromRegion(isoCode);
|
|
196
|
+
return new Geolocation(locale, location.longitude, location.latitude, location.time_zone);
|
|
197
|
+
}
|
|
198
|
+
async function getUnicodeInfo() {
|
|
199
|
+
const data = await fs.promises.readFile(path.join(currentDir, "data-files", "territoryInfo.xml"));
|
|
200
|
+
const parser = new xml2js.Parser();
|
|
201
|
+
return parser.parseStringPromise(data);
|
|
202
|
+
}
|
|
203
|
+
function asFloat(element, attr) {
|
|
204
|
+
return parseFloat(element[attr] || "0");
|
|
205
|
+
}
|
|
206
|
+
class StatisticalLocaleSelector {
|
|
207
|
+
root;
|
|
208
|
+
constructor() {
|
|
209
|
+
this.loadUnicodeInfo();
|
|
210
|
+
}
|
|
211
|
+
async loadUnicodeInfo() {
|
|
212
|
+
this.root = await getUnicodeInfo();
|
|
213
|
+
}
|
|
214
|
+
loadTerritoryData(isoCode) {
|
|
215
|
+
const territory = this.root.territoryInfo.territory.find((t) => t.$.type === isoCode);
|
|
216
|
+
if (!territory) {
|
|
217
|
+
throw new UnknownTerritory(`Unknown territory: ${isoCode}`);
|
|
218
|
+
}
|
|
219
|
+
const langPopulations = territory.languagePopulation;
|
|
220
|
+
if (!langPopulations) {
|
|
221
|
+
throw new Error(`No language data found for region: ${isoCode}`);
|
|
222
|
+
}
|
|
223
|
+
const languages = langPopulations.map((lang) => lang.$.type);
|
|
224
|
+
const percentages = langPopulations.map((lang) => asFloat(lang.$, "populationPercent"));
|
|
225
|
+
return this.normalizeProbabilities(languages, percentages);
|
|
226
|
+
}
|
|
227
|
+
loadLanguageData(language) {
|
|
228
|
+
const territories = this.root.territory.filter((t) => t.languagePopulation.some((lp) => lp.$.type === language));
|
|
229
|
+
if (!territories.length) {
|
|
230
|
+
throw new UnknownLanguage(`No region data found for language: ${language}`);
|
|
231
|
+
}
|
|
232
|
+
const regions = [];
|
|
233
|
+
const percentages = [];
|
|
234
|
+
for (const terr of territories) {
|
|
235
|
+
const region = terr.$.type;
|
|
236
|
+
const langPop = terr.languagePopulation.find((lp) => lp.$.type === language);
|
|
237
|
+
if (region && langPop) {
|
|
238
|
+
regions.push(region);
|
|
239
|
+
percentages.push(((asFloat(langPop.$, "populationPercent") *
|
|
240
|
+
asFloat(terr.$, "literacyPercent")) /
|
|
241
|
+
10000) *
|
|
242
|
+
asFloat(terr.$, "population"));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!regions.length) {
|
|
246
|
+
throw new Error(`No valid region data found for language: ${language}`);
|
|
247
|
+
}
|
|
248
|
+
return this.normalizeProbabilities(regions, percentages);
|
|
249
|
+
}
|
|
250
|
+
normalizeProbabilities(languages, freq) {
|
|
251
|
+
const total = freq.reduce((a, b) => a + b, 0);
|
|
252
|
+
return [languages, freq.map((f) => f / total)];
|
|
253
|
+
}
|
|
254
|
+
weightedRandomChoice(items, weights) {
|
|
255
|
+
if (items.length === 0) {
|
|
256
|
+
throw new Error("items must not be empty");
|
|
257
|
+
}
|
|
258
|
+
if (items.length !== weights.length) {
|
|
259
|
+
throw new Error("items and weights must have the same length");
|
|
260
|
+
}
|
|
261
|
+
let total = 0;
|
|
262
|
+
for (const w of weights) {
|
|
263
|
+
if (w < 0) {
|
|
264
|
+
throw new Error("weights must be non-negative");
|
|
265
|
+
}
|
|
266
|
+
total += w;
|
|
267
|
+
}
|
|
268
|
+
if (total === 0) {
|
|
269
|
+
return items[Math.floor(Math.random() * items.length)];
|
|
270
|
+
}
|
|
271
|
+
const r = Math.random() * total;
|
|
272
|
+
let acc = 0;
|
|
273
|
+
for (let i = 0; i < items.length; i++) {
|
|
274
|
+
acc += weights[i];
|
|
275
|
+
if (r < acc) {
|
|
276
|
+
return items[i];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return items[items.length - 1];
|
|
280
|
+
}
|
|
281
|
+
fromRegion(region) {
|
|
282
|
+
const [languages, probabilities] = this.loadTerritoryData(region);
|
|
283
|
+
const language = this.weightedRandomChoice(languages, probabilities).replace("_", "-");
|
|
284
|
+
return normalizeLocale(`${language}-${region}`);
|
|
285
|
+
}
|
|
286
|
+
fromLanguage(language) {
|
|
287
|
+
const [regions, probabilities] = this.loadLanguageData(language);
|
|
288
|
+
const region = this.weightedRandomChoice(regions, probabilities);
|
|
289
|
+
return normalizeLocale(`${language}-${region}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const SELECTOR = new StatisticalLocaleSelector();
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
navigator: {
|
|
3
|
+
userAgent: string;
|
|
4
|
+
doNotTrack: string;
|
|
5
|
+
appCodeName: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
appVersion: string;
|
|
8
|
+
oscpu: string;
|
|
9
|
+
platform: string;
|
|
10
|
+
hardwareConcurrency: string;
|
|
11
|
+
product: string;
|
|
12
|
+
maxTouchPoints: string;
|
|
13
|
+
extraProperties: {
|
|
14
|
+
globalPrivacyControl: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
screen: {
|
|
18
|
+
availLeft: string;
|
|
19
|
+
availTop: string;
|
|
20
|
+
availWidth: string;
|
|
21
|
+
availHeight: string;
|
|
22
|
+
height: string;
|
|
23
|
+
width: string;
|
|
24
|
+
colorDepth: string;
|
|
25
|
+
pixelDepth: string;
|
|
26
|
+
pageXOffset: string;
|
|
27
|
+
pageYOffset: string;
|
|
28
|
+
outerHeight: string;
|
|
29
|
+
outerWidth: string;
|
|
30
|
+
innerHeight: string;
|
|
31
|
+
innerWidth: string;
|
|
32
|
+
screenX: string;
|
|
33
|
+
screenY: string;
|
|
34
|
+
};
|
|
35
|
+
headers: {
|
|
36
|
+
"Accept-Encoding": string;
|
|
37
|
+
};
|
|
38
|
+
battery: {
|
|
39
|
+
charging: string;
|
|
40
|
+
chargingTime: string;
|
|
41
|
+
dischargingTime: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export default _default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
navigator: {
|
|
3
|
+
userAgent: "navigator.userAgent",
|
|
4
|
+
doNotTrack: "navigator.doNotTrack",
|
|
5
|
+
appCodeName: "navigator.appCodeName",
|
|
6
|
+
appName: "navigator.appName",
|
|
7
|
+
appVersion: "navigator.appVersion",
|
|
8
|
+
oscpu: "navigator.oscpu",
|
|
9
|
+
platform: "navigator.platform",
|
|
10
|
+
hardwareConcurrency: "navigator.hardwareConcurrency",
|
|
11
|
+
product: "navigator.product",
|
|
12
|
+
maxTouchPoints: "navigator.maxTouchPoints",
|
|
13
|
+
extraProperties: {
|
|
14
|
+
globalPrivacyControl: "navigator.globalPrivacyControl",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
screen: {
|
|
18
|
+
availLeft: "screen.availLeft",
|
|
19
|
+
availTop: "screen.availTop",
|
|
20
|
+
availWidth: "screen.availWidth",
|
|
21
|
+
availHeight: "screen.availHeight",
|
|
22
|
+
height: "screen.height",
|
|
23
|
+
width: "screen.width",
|
|
24
|
+
colorDepth: "screen.colorDepth",
|
|
25
|
+
pixelDepth: "screen.pixelDepth",
|
|
26
|
+
pageXOffset: "screen.pageXOffset",
|
|
27
|
+
pageYOffset: "screen.pageYOffset",
|
|
28
|
+
outerHeight: "window.outerHeight",
|
|
29
|
+
outerWidth: "window.outerWidth",
|
|
30
|
+
innerHeight: "window.innerHeight",
|
|
31
|
+
innerWidth: "window.innerWidth",
|
|
32
|
+
screenX: "window.screenX",
|
|
33
|
+
screenY: "window.screenY",
|
|
34
|
+
},
|
|
35
|
+
headers: {
|
|
36
|
+
"Accept-Encoding": "headers.Accept-Encoding",
|
|
37
|
+
},
|
|
38
|
+
battery: {
|
|
39
|
+
charging: "battery:charging",
|
|
40
|
+
chargingTime: "battery:chargingTime",
|
|
41
|
+
dischargingTime: "battery:dischargingTime",
|
|
42
|
+
},
|
|
43
|
+
};
|