camoucore 0.2.0 → 0.6.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/LICENSE +4 -3
- package/dist/camoufox/__main__.d.ts +10 -0
- package/dist/camoufox/__main__.js +1175 -0
- package/dist/camoufox/__version__.d.ts +31 -0
- package/dist/camoufox/__version__.js +32 -0
- package/dist/camoufox/_humanize_playwright.d.ts +54 -0
- package/dist/camoufox/_humanize_playwright.js +429 -0
- package/dist/camoufox/addons.d.ts +21 -0
- package/dist/camoufox/addons.js +56 -0
- package/dist/camoufox/async_api.d.ts +9 -0
- package/dist/camoufox/async_api.js +9 -0
- package/dist/camoufox/browser-pin.d.ts +46 -0
- package/dist/camoufox/browser-pin.js +96 -0
- package/dist/camoufox/cli.d.ts +7 -0
- package/dist/camoufox/cli.js +20 -0
- package/dist/camoufox/coherence.d.ts +141 -0
- package/dist/camoufox/coherence.js +708 -0
- package/dist/camoufox/data-files/audio-output-latency.json +15 -0
- package/dist/camoufox/data-files/browser-pin.json +7 -0
- package/dist/camoufox/data-files/display-profiles.json +6 -0
- package/dist/camoufox/data-files/essential-fonts.json +5 -0
- package/dist/camoufox/data-files/fingerprint-presets-v150.json +14544 -0
- package/dist/camoufox/data-files/fingerprint-presets.json +5192 -0
- package/dist/camoufox/data-files/font-bases.json +1888 -0
- package/dist/camoufox/data-files/font-groups.json +716 -0
- package/dist/camoufox/data-files/font-prefs.json +1046 -0
- package/dist/camoufox/data-files/fonts.json +240 -0
- package/dist/camoufox/data-files/fpgen.yml +44 -0
- package/dist/camoufox/data-files/launcher-constants.json +136 -0
- package/dist/camoufox/data-files/media-devices.json +180 -0
- package/dist/camoufox/data-files/repos.yml +40 -0
- package/dist/camoufox/data-files/voice-manifests.json +1864 -0
- package/dist/camoufox/data-files/voice-uris.json +188 -0
- package/dist/camoufox/data-files/warnings.yml +146 -0
- package/dist/camoufox/display_profile.d.ts +21 -0
- package/dist/camoufox/display_profile.js +129 -0
- package/dist/camoufox/driver_defaults.d.ts +27 -0
- package/dist/camoufox/driver_defaults.js +119 -0
- package/dist/camoufox/exceptions.d.ts +68 -0
- package/dist/camoufox/exceptions.js +122 -0
- package/dist/camoufox/fingerprints.d.ts +434 -0
- package/dist/camoufox/fingerprints.js +1936 -0
- package/dist/camoufox/gpudisplay.d.ts +158 -0
- package/dist/camoufox/gpudisplay.js +695 -0
- package/dist/camoufox/host_rendering.d.ts +38 -0
- package/dist/camoufox/host_rendering.js +180 -0
- package/dist/camoufox/humanize.d.ts +89 -0
- package/dist/camoufox/humanize.js +143 -0
- package/dist/camoufox/index.d.ts +21 -0
- package/dist/camoufox/index.js +21 -0
- package/dist/camoufox/ip.d.ts +45 -0
- package/dist/camoufox/ip.js +114 -0
- package/dist/camoufox/multiversion.d.ts +131 -0
- package/dist/camoufox/multiversion.js +490 -0
- package/dist/camoufox/node-floor.d.ts +5 -0
- package/dist/camoufox/node-floor.js +17 -0
- package/dist/camoufox/paths.d.ts +45 -0
- package/dist/camoufox/paths.js +62 -0
- package/dist/camoufox/pkgman.d.ts +361 -0
- package/dist/camoufox/pkgman.js +1066 -0
- package/dist/camoufox/product.d.ts +8 -0
- package/dist/camoufox/product.js +8 -0
- package/dist/camoufox/pycompat.d.ts +97 -0
- package/dist/camoufox/pycompat.js +458 -0
- package/dist/camoufox/server.d.ts +36 -0
- package/dist/camoufox/server.js +82 -0
- package/dist/camoufox/sync_api.d.ts +77 -0
- package/dist/camoufox/sync_api.js +207 -0
- package/dist/camoufox/utils.d.ts +638 -0
- package/dist/camoufox/utils.js +2507 -0
- package/dist/camoufox/warnings.d.ts +16 -0
- package/dist/camoufox/warnings.js +65 -0
- package/dist/camoufox/webgl.d.ts +52 -0
- package/dist/camoufox/webgl.js +264 -0
- package/dist/camouwolf/__main__.d.ts +10 -0
- package/dist/camouwolf/__main__.js +1180 -0
- package/dist/camouwolf/__version__.d.ts +31 -0
- package/dist/camouwolf/__version__.js +32 -0
- package/dist/camouwolf/_humanize_playwright.d.ts +53 -0
- package/dist/camouwolf/_humanize_playwright.js +427 -0
- package/dist/camouwolf/addons.d.ts +42 -0
- package/dist/camouwolf/addons.js +113 -0
- package/dist/camouwolf/async_api.d.ts +9 -0
- package/dist/camouwolf/async_api.js +9 -0
- package/dist/camouwolf/browser-pin.d.ts +46 -0
- package/dist/camouwolf/browser-pin.js +96 -0
- package/dist/camouwolf/cli.d.ts +7 -0
- package/dist/camouwolf/cli.js +20 -0
- package/dist/camouwolf/clienthints.d.ts +61 -0
- package/dist/camouwolf/clienthints.js +176 -0
- package/dist/camouwolf/coherence.d.ts +152 -0
- package/dist/camouwolf/coherence.js +554 -0
- package/dist/camouwolf/data-files/browser-pin.json +7 -0
- package/dist/camouwolf/data-files/camouwolf.defaults.json +118 -0
- package/dist/camouwolf/data-files/data/bundle-fonts.json +1983 -0
- package/dist/camouwolf/data-files/data/chrome-languages.json +517 -0
- package/dist/camouwolf/data-files/data/properties.json +321 -0
- package/dist/camouwolf/data-files/data/system-colors.json +35 -0
- package/dist/camouwolf/data-files/data/ubo.json +6 -0
- package/dist/camouwolf/data-files/fpgen.yml +41 -0
- package/dist/camouwolf/data-files/launcher-constants.json +26 -0
- package/dist/camouwolf/data-files/repos.yml +23 -0
- package/dist/camouwolf/data-files/warnings.yml +96 -0
- package/dist/camouwolf/driver_defaults.d.ts +25 -0
- package/dist/camouwolf/driver_defaults.js +114 -0
- package/dist/camouwolf/exceptions.d.ts +95 -0
- package/dist/camouwolf/exceptions.js +150 -0
- package/dist/camouwolf/fingerprints.d.ts +227 -0
- package/dist/camouwolf/fingerprints.js +753 -0
- package/dist/camouwolf/gpudisplay.d.ts +171 -0
- package/dist/camouwolf/gpudisplay.js +711 -0
- package/dist/camouwolf/host_rendering.d.ts +18 -0
- package/dist/camouwolf/host_rendering.js +114 -0
- package/dist/camouwolf/humanize.d.ts +84 -0
- package/dist/camouwolf/humanize.js +128 -0
- package/dist/camouwolf/index.d.ts +22 -0
- package/dist/camouwolf/index.js +21 -0
- package/dist/camouwolf/multiversion.d.ts +131 -0
- package/dist/camouwolf/multiversion.js +491 -0
- package/dist/camouwolf/node-floor.d.ts +5 -0
- package/dist/camouwolf/node-floor.js +17 -0
- package/dist/camouwolf/paths.d.ts +34 -0
- package/dist/camouwolf/paths.js +58 -0
- package/dist/camouwolf/pkgman.d.ts +331 -0
- package/dist/camouwolf/pkgman.js +972 -0
- package/dist/camouwolf/product.d.ts +3 -0
- package/dist/camouwolf/product.js +3 -0
- package/dist/camouwolf/pycompat.d.ts +92 -0
- package/dist/camouwolf/pycompat.js +461 -0
- package/dist/camouwolf/server.d.ts +36 -0
- package/dist/camouwolf/server.js +81 -0
- package/dist/camouwolf/switches.d.ts +77 -0
- package/dist/camouwolf/switches.js +222 -0
- package/dist/camouwolf/sync_api.d.ts +84 -0
- package/dist/camouwolf/sync_api.js +173 -0
- package/dist/camouwolf/utils.d.ts +644 -0
- package/dist/camouwolf/utils.js +2057 -0
- package/dist/camouwolf/warnings.d.ts +14 -0
- package/dist/camouwolf/warnings.js +59 -0
- package/dist/camouwolf/webgl.d.ts +41 -0
- package/dist/camouwolf/webgl.js +198 -0
- package/dist/data-files/antibot-rules.json +146 -0
- package/dist/data.d.ts +1 -1
- package/dist/data.js +4 -3
- package/dist/download.js +1 -1
- package/dist/exceptions.d.ts +1 -1
- package/dist/exceptions.js +1 -1
- package/dist/geolocation.js +1 -1
- package/dist/host.d.ts +2 -0
- package/dist/host.js +17 -1
- package/dist/ip.js +1 -1
- package/dist/locales.js +1 -1
- package/dist/mcp/cli.d.ts +15 -0
- package/dist/mcp/cli.js +108 -0
- package/dist/mcp/index.d.ts +8 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/main.d.ts +2 -0
- package/dist/mcp/main.js +8 -0
- package/dist/mcp/secrets.d.ts +50 -0
- package/dist/mcp/secrets.js +193 -0
- package/dist/mcp/server.d.ts +48 -0
- package/dist/mcp/server.js +653 -0
- package/dist/mcp/tree.d.ts +10 -0
- package/dist/mcp/tree.js +36 -0
- package/dist/passthrough.d.ts +16 -0
- package/dist/passthrough.js +50 -0
- package/dist/product.js +1 -1
- package/dist/settings.d.ts +12 -0
- package/dist/settings.js +95 -0
- package/dist/telemetry.d.ts +127 -0
- package/dist/telemetry.js +426 -0
- package/dist/virtdisplay.d.ts +1 -1
- package/dist/virtdisplay.js +1 -1
- package/dist/warnings.js +1 -1
- package/package.json +57 -13
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome identities: drawing one with fpgen and turning it into Camouwolf config.
|
|
3
|
+
*
|
|
4
|
+
* An fpgen fingerprint is one recorded Chrome on one real machine, so its
|
|
5
|
+
* fields agree with each other; the launcher maps them and leaves them
|
|
6
|
+
* together. What the record cannot know is filled in afterwards: the Chromium
|
|
7
|
+
* milestone the binary really is, and the client hints that milestone and OS
|
|
8
|
+
* imply (clienthints.ts).
|
|
9
|
+
*
|
|
10
|
+
* TypeScript twin of python/camoucore/src/camoucore/camouwolf/fingerprints.py.
|
|
11
|
+
*/
|
|
12
|
+
import { generate, InvalidConstraints } from "fpgen-js";
|
|
13
|
+
import * as random from "python-random";
|
|
14
|
+
import { supported as cpuAffinitySupported, hostCoreCount, } from "../cpu_affinity.js";
|
|
15
|
+
import { retargetUserAgent, uaOs } from "./clienthints.js";
|
|
16
|
+
import { ValueError } from "./exceptions.js";
|
|
17
|
+
import { LAUNCHER_CONSTANTS, loadDataFile } from "./paths.js";
|
|
18
|
+
import { isPlainObject, num, pyStr, pyStrRepr, pyTruthy } from "./pycompat.js";
|
|
19
|
+
import { webglIdentity } from "./webgl.js";
|
|
20
|
+
/** The fpgen mapping file. */
|
|
21
|
+
export const FPGEN_DATA = loadDataFile("fpgen.yml");
|
|
22
|
+
/** Camouwolf's OS names and the keys the rest of the launcher uses for them. */
|
|
23
|
+
export const OS_KEYS = {
|
|
24
|
+
macos: "mac",
|
|
25
|
+
windows: "win",
|
|
26
|
+
linux: "lin",
|
|
27
|
+
};
|
|
28
|
+
export const OS_NAMES = {
|
|
29
|
+
mac: "macos",
|
|
30
|
+
win: "windows",
|
|
31
|
+
lin: "linux",
|
|
32
|
+
};
|
|
33
|
+
/** The OS name ('macos', 'windows', 'linux') a navigator.platform belongs to. */
|
|
34
|
+
export function platformToOs(platform) {
|
|
35
|
+
if (platform.startsWith("Mac"))
|
|
36
|
+
return "macos";
|
|
37
|
+
if (platform.startsWith("Win"))
|
|
38
|
+
return "windows";
|
|
39
|
+
return "linux";
|
|
40
|
+
}
|
|
41
|
+
/** fpgen's OS names, from Camouwolf's. */
|
|
42
|
+
export const FPGEN_OS = {
|
|
43
|
+
lin: "Linux",
|
|
44
|
+
linux: "Linux",
|
|
45
|
+
mac: "macOS",
|
|
46
|
+
macos: "macOS",
|
|
47
|
+
win: "Windows",
|
|
48
|
+
windows: "Windows",
|
|
49
|
+
};
|
|
50
|
+
/** Python dict.get(key, default): the default only when the key is absent. */
|
|
51
|
+
function get(config, key, dflt = undefined) {
|
|
52
|
+
return Object.hasOwn(config, key) ? config[key] : dflt;
|
|
53
|
+
}
|
|
54
|
+
function isNone(value) {
|
|
55
|
+
return value === null || value === undefined;
|
|
56
|
+
}
|
|
57
|
+
/** isinstance(value, int): a bool counts, an integral float does not reach here. */
|
|
58
|
+
function isInt(value) {
|
|
59
|
+
return (typeof value === "boolean" ||
|
|
60
|
+
(typeof value === "number" && Number.isInteger(value)));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A bound on the screen a generated fingerprint may claim: the generated
|
|
64
|
+
* screen must fit inside the given fields.
|
|
65
|
+
*/
|
|
66
|
+
export class Screen {
|
|
67
|
+
minWidth;
|
|
68
|
+
maxWidth;
|
|
69
|
+
minHeight;
|
|
70
|
+
maxHeight;
|
|
71
|
+
constructor({ minWidth = null, maxWidth = null, minHeight = null, maxHeight = null, } = {}) {
|
|
72
|
+
this.minWidth = minWidth;
|
|
73
|
+
this.maxWidth = maxWidth;
|
|
74
|
+
this.minHeight = minHeight;
|
|
75
|
+
this.maxHeight = maxHeight;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The bound, as fpgen conditions. fpgen takes a predicate per field and
|
|
79
|
+
* rejects a value the predicate refuses, so a range is a closure rather
|
|
80
|
+
* than a list of allowed values.
|
|
81
|
+
*/
|
|
82
|
+
asConditions() {
|
|
83
|
+
const conditions = {};
|
|
84
|
+
const { minWidth: loW, maxWidth: hiW, minHeight: loH, maxHeight: hiH, } = this;
|
|
85
|
+
const within = (v, lo, hi) => isInt(v) &&
|
|
86
|
+
(lo === null || Number(v) >= lo) &&
|
|
87
|
+
(hi === null || Number(v) <= hi);
|
|
88
|
+
if (loW !== null || hiW !== null)
|
|
89
|
+
conditions["screen.width"] = (w) => within(w, loW, hiW);
|
|
90
|
+
if (loH !== null || hiH !== null)
|
|
91
|
+
conditions["screen.height"] = (h) => within(h, loH, hiH);
|
|
92
|
+
return conditions;
|
|
93
|
+
}
|
|
94
|
+
/** dataclasses.asdict(), with the Python field names. */
|
|
95
|
+
toPyDict() {
|
|
96
|
+
return {
|
|
97
|
+
min_width: this.minWidth,
|
|
98
|
+
max_width: this.maxWidth,
|
|
99
|
+
min_height: this.minHeight,
|
|
100
|
+
max_height: this.maxHeight,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Logical CPUs this process may actually run on (cgroup/affinity aware). */
|
|
105
|
+
export function hostCpuCount() {
|
|
106
|
+
return hostCoreCount() || null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Core counts real desktop machines ship with, from the recorded presets. 2 is
|
|
110
|
+
* excluded although the scraped corpus has it: no Apple Silicon part has fewer
|
|
111
|
+
* than 8 cores, so 2 beside the common "Apple M1" renderer is a machine that
|
|
112
|
+
* does not exist. A host outside the table is snapped into it.
|
|
113
|
+
*/
|
|
114
|
+
export const PLAUSIBLE_CORE_COUNTS = LAUNCHER_CONSTANTS.plausibleCoreCounts;
|
|
115
|
+
/**
|
|
116
|
+
* navigator.hardwareConcurrency = the host's parallelism, snapped DOWN into
|
|
117
|
+
* PLAUSIBLE_CORE_COUNTS -- or the fingerprint's own value (snapped, capped by
|
|
118
|
+
* the host) when the browser can be pinned to that many cores.
|
|
119
|
+
*
|
|
120
|
+
* @param canPin false when nothing will pin the browser (launchServer, or
|
|
121
|
+
* launchOptions used directly); undefined/null: whatever the host supports.
|
|
122
|
+
* @param host overrides for the host probes (tests).
|
|
123
|
+
*/
|
|
124
|
+
export function fixHardwareConcurrency(config, canPin, host = {}) {
|
|
125
|
+
const n = "cpuCount" in host ? host.cpuCount : hostCpuCount();
|
|
126
|
+
if (!n)
|
|
127
|
+
return;
|
|
128
|
+
const pinnable = (host.canPinHost ?? cpuAffinitySupported()) && canPin !== false;
|
|
129
|
+
const cap = Math.trunc(n);
|
|
130
|
+
const hostAllowed = PLAUSIBLE_CORE_COUNTS.filter((c) => c <= cap);
|
|
131
|
+
const hostValue = hostAllowed.length
|
|
132
|
+
? hostAllowed[hostAllowed.length - 1]
|
|
133
|
+
: PLAUSIBLE_CORE_COUNTS[0];
|
|
134
|
+
let drawn = config["navigator.hardwareConcurrency"];
|
|
135
|
+
if (typeof drawn === "boolean")
|
|
136
|
+
drawn = Number(drawn); // a Python bool is an int
|
|
137
|
+
if (pinnable &&
|
|
138
|
+
typeof drawn === "number" &&
|
|
139
|
+
Number.isInteger(drawn) &&
|
|
140
|
+
drawn >= 1) {
|
|
141
|
+
const target = Math.min(drawn, cap);
|
|
142
|
+
const allowed = PLAUSIBLE_CORE_COUNTS.filter((c) => c <= target);
|
|
143
|
+
config["navigator.hardwareConcurrency"] = allowed.length
|
|
144
|
+
? allowed[allowed.length - 1]
|
|
145
|
+
: PLAUSIBLE_CORE_COUNTS[0];
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
config["navigator.hardwareConcurrency"] = hostValue;
|
|
149
|
+
}
|
|
150
|
+
/** Enforce inner <= outer <= avail <= screen on both axes. */
|
|
151
|
+
export function clampWindowDimensions(config) {
|
|
152
|
+
for (const axis of ["Width", "Height"]) {
|
|
153
|
+
const screen = config[`screen.${axis.toLowerCase()}`];
|
|
154
|
+
const avail = config[`screen.avail${axis}`];
|
|
155
|
+
const outer = config[`window.outer${axis}`];
|
|
156
|
+
const inner = config[`window.inner${axis}`];
|
|
157
|
+
// avail must not exceed screen
|
|
158
|
+
if (pyTruthy(screen) && pyTruthy(avail) && num(avail) > num(screen)) {
|
|
159
|
+
config[`screen.avail${axis}`] = screen;
|
|
160
|
+
}
|
|
161
|
+
const availClamped = get(config, `screen.avail${axis}`, screen);
|
|
162
|
+
// outer must not exceed avail (or screen if avail is unknown)
|
|
163
|
+
const outerCap = !isNone(availClamped) ? availClamped : screen;
|
|
164
|
+
if (pyTruthy(outer) && pyTruthy(outerCap) && num(outer) > num(outerCap)) {
|
|
165
|
+
const chrome = pyTruthy(inner) ? Math.max(0, num(outer) - num(inner)) : 0;
|
|
166
|
+
config[`window.outer${axis}`] = outerCap;
|
|
167
|
+
if (pyTruthy(inner))
|
|
168
|
+
config[`window.inner${axis}`] = Math.max(1, num(outerCap) - chrome);
|
|
169
|
+
}
|
|
170
|
+
// inner must not exceed outer
|
|
171
|
+
const outerClamped = get(config, `window.outer${axis}`, outer);
|
|
172
|
+
const innerNow = config[`window.inner${axis}`];
|
|
173
|
+
if (pyTruthy(innerNow) &&
|
|
174
|
+
pyTruthy(outerClamped) &&
|
|
175
|
+
num(innerNow) > num(outerClamped)) {
|
|
176
|
+
config[`window.inner${axis}`] = outerClamped;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Shrink screen.width/height down to the bounds of the real display, keeping
|
|
182
|
+
* the taskbar delta. Run clampWindowDimensions afterwards.
|
|
183
|
+
*/
|
|
184
|
+
export function clampScreenToDisplay(config, maxWidth, maxHeight) {
|
|
185
|
+
for (const [axis, cap] of [
|
|
186
|
+
["width", maxWidth],
|
|
187
|
+
["height", maxHeight],
|
|
188
|
+
]) {
|
|
189
|
+
const screen = config[`screen.${axis}`];
|
|
190
|
+
if (!(pyTruthy(screen) && pyTruthy(cap)) || num(screen) <= cap)
|
|
191
|
+
continue;
|
|
192
|
+
const availKey = axis === "width" ? "screen.availWidth" : "screen.availHeight";
|
|
193
|
+
const avail = config[availKey];
|
|
194
|
+
config[`screen.${axis}`] = cap;
|
|
195
|
+
if (pyTruthy(avail)) {
|
|
196
|
+
config[availKey] = Math.max(1, cap - Math.max(0, num(screen) - num(avail)));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Keep the window box inside the screen: 0 <= screenX/Y <= screen - outer. */
|
|
201
|
+
export function clampWindowPosition(config) {
|
|
202
|
+
for (const [axis, posKey] of [
|
|
203
|
+
["Width", "window.screenX"],
|
|
204
|
+
["Height", "window.screenY"],
|
|
205
|
+
]) {
|
|
206
|
+
const screen = config[`screen.${axis.toLowerCase()}`];
|
|
207
|
+
const outer = config[`window.outer${axis}`];
|
|
208
|
+
const pos = config[posKey];
|
|
209
|
+
if (isNone(pos) || !(pyTruthy(screen) && pyTruthy(outer)))
|
|
210
|
+
continue;
|
|
211
|
+
config[posKey] = Math.max(0, Math.min(num(pos), num(screen) - num(outer)));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** `rounding` of a device-pixel edge, unless it is within 0.001 of a whole pixel. */
|
|
215
|
+
function outward(value, rounding) {
|
|
216
|
+
const nearest = Math.round(value);
|
|
217
|
+
return Math.abs(nearest - value) < Math.fround(0.001)
|
|
218
|
+
? nearest
|
|
219
|
+
: rounding(value);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The window position and size, in CSS pixels, Chrome reads back on X11 for a
|
|
223
|
+
* window it was asked to open at `position` and `size`.
|
|
224
|
+
*
|
|
225
|
+
* The bounds go to device pixels as ToPixelRect (float32, enclosing rect, a
|
|
226
|
+
* 0.001 rounding allowance) and come back as ToDIPRect (float32 times
|
|
227
|
+
* 1.f/scale, enclosing rect, no allowance), so at 1.75 a 1000 px window is
|
|
228
|
+
* reported 1001 px wide.
|
|
229
|
+
*/
|
|
230
|
+
export function chromeWindowReports(position, size, dpr) {
|
|
231
|
+
const f = Math.fround;
|
|
232
|
+
const scale = f(dpr);
|
|
233
|
+
const left = f(f(position) * scale);
|
|
234
|
+
const right = f(left + f(f(size) * scale));
|
|
235
|
+
const leftPx = outward(left, Math.floor);
|
|
236
|
+
const rightPx = outward(right, Math.ceil);
|
|
237
|
+
const inverse = f(1 / scale);
|
|
238
|
+
const back = f(f(leftPx) * inverse);
|
|
239
|
+
const backRight = f(back + f(f(rightPx - leftPx) * inverse));
|
|
240
|
+
return [Math.floor(back), Math.ceil(backRight) - Math.floor(back)];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The innerWidth Chrome reports in a window `width` CSS pixels wide.
|
|
244
|
+
*
|
|
245
|
+
* The page spans the window, sized up to whole device pixels and read back
|
|
246
|
+
* to the nearest CSS pixel, so at 1.25 a window 1537 wide reports an
|
|
247
|
+
* innerWidth of 1538, wider than the window itself.
|
|
248
|
+
*/
|
|
249
|
+
export function chromeViewportWidth(width, dpr) {
|
|
250
|
+
const f = Math.fround;
|
|
251
|
+
const scale = f(dpr);
|
|
252
|
+
return Math.floor(outward(f(f(width) * scale), Math.ceil) / scale + 0.5);
|
|
253
|
+
}
|
|
254
|
+
/** (switch input, what Chrome reports for it) around `position`, `size`. */
|
|
255
|
+
function windowInputs(position, size, dpr) {
|
|
256
|
+
const out = [];
|
|
257
|
+
for (let p = Math.max(0, position - 8); p < position + 3; p++) {
|
|
258
|
+
for (let z = Math.max(1, size - 16); z < size + 5; z++) {
|
|
259
|
+
out.push([[p, z], chromeWindowReports(p, z, dpr)]);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Claim the nearest window Chrome can report at its devicePixelRatio.
|
|
266
|
+
*
|
|
267
|
+
* At a fractional ratio some positions and sizes are never read back (at 1.75
|
|
268
|
+
* no window reports screenX 7). The claim moves to the nearest one Chrome
|
|
269
|
+
* does report, inside the drawn window's box so it still fits the screen, and
|
|
270
|
+
* no narrower than the page Chrome lays out in it.
|
|
271
|
+
*/
|
|
272
|
+
export function snapWindowToDevicePixels(config) {
|
|
273
|
+
const dpr = num(config["window.devicePixelRatio"] || 1);
|
|
274
|
+
for (const [axis, posKey] of [
|
|
275
|
+
["Width", "window.screenX"],
|
|
276
|
+
["Height", "window.screenY"],
|
|
277
|
+
]) {
|
|
278
|
+
const sizeKey = `window.outer${axis}`;
|
|
279
|
+
const size = config[sizeKey];
|
|
280
|
+
if (!pyTruthy(size))
|
|
281
|
+
continue;
|
|
282
|
+
const position = num(config[posKey] || 0);
|
|
283
|
+
let best;
|
|
284
|
+
let bestShift = Number.POSITIVE_INFINITY;
|
|
285
|
+
for (const [, seen] of windowInputs(position, num(size), dpr)) {
|
|
286
|
+
if (!(position >= seen[0] && seen[0] >= 0))
|
|
287
|
+
continue;
|
|
288
|
+
if (seen[0] + seen[1] > position + num(size))
|
|
289
|
+
continue;
|
|
290
|
+
// Down the window the toolbar keeps the page shorter than it; across, the page spans it.
|
|
291
|
+
if (axis === "Width" && chromeViewportWidth(seen[1], dpr) > seen[1])
|
|
292
|
+
continue;
|
|
293
|
+
const shift = Math.abs(position - seen[0]) + Math.abs(num(size) - seen[1]);
|
|
294
|
+
if (shift < bestShift) {
|
|
295
|
+
best = seen;
|
|
296
|
+
bestShift = shift;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (best) {
|
|
300
|
+
config[sizeKey] = best[1];
|
|
301
|
+
if (posKey in config)
|
|
302
|
+
config[posKey] = best[0];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The --window-position/--window-size values Chrome reports back as
|
|
308
|
+
* `position`, `size`; the claim itself when no input near it does.
|
|
309
|
+
*/
|
|
310
|
+
export function windowSwitchBounds(position, size, dpr) {
|
|
311
|
+
for (const [given, seen] of windowInputs(position, size, dpr)) {
|
|
312
|
+
if (seen[0] === position && seen[1] === size)
|
|
313
|
+
return given;
|
|
314
|
+
}
|
|
315
|
+
return [position, size];
|
|
316
|
+
}
|
|
317
|
+
/** The smallest screen mainstream hardware still ships. */
|
|
318
|
+
export const MODERN_SCREEN_FLOOR = [1366, 768];
|
|
319
|
+
/**
|
|
320
|
+
* Lift netbook-era screen geometry to the modern floor, keeping the
|
|
321
|
+
* screen-to-avail gaps. Call BEFORE clampScreenToDisplay.
|
|
322
|
+
*/
|
|
323
|
+
export function raiseScreenToModernFloor(config) {
|
|
324
|
+
const [minW, minH] = MODERN_SCREEN_FLOOR;
|
|
325
|
+
const sw = config["screen.width"];
|
|
326
|
+
const sh = config["screen.height"];
|
|
327
|
+
if (!(pyTruthy(sw) && pyTruthy(sh)) || (num(sw) >= minW && num(sh) >= minH))
|
|
328
|
+
return;
|
|
329
|
+
// Measure the gaps before mutating, or they get folded into themselves.
|
|
330
|
+
const aw = config["screen.availWidth"];
|
|
331
|
+
const ah = config["screen.availHeight"];
|
|
332
|
+
const gapW = pyTruthy(aw) ? num(sw) - num(aw) : null;
|
|
333
|
+
const gapH = pyTruthy(ah) ? num(sh) - num(ah) : null;
|
|
334
|
+
const newW = Math.max(num(sw), minW);
|
|
335
|
+
const newH = Math.max(num(sh), minH);
|
|
336
|
+
config["screen.width"] = newW;
|
|
337
|
+
config["screen.height"] = newH;
|
|
338
|
+
if (gapW !== null)
|
|
339
|
+
config["screen.availWidth"] = Math.max(1, newW - Math.max(0, gapW));
|
|
340
|
+
if (gapH !== null)
|
|
341
|
+
config["screen.availHeight"] = Math.max(1, newH - Math.max(0, gapH));
|
|
342
|
+
}
|
|
343
|
+
const SOFTWARE_RENDERERS = [
|
|
344
|
+
"llvmpipe",
|
|
345
|
+
"Microsoft Basic Render Driver",
|
|
346
|
+
"SwiftShader",
|
|
347
|
+
"Generic Renderer",
|
|
348
|
+
];
|
|
349
|
+
/**
|
|
350
|
+
* Whether `renderer` is a software rasterizer rather than real hardware.
|
|
351
|
+
* Case-insensitive: fpgen hands a condition's predicate the value lowercased.
|
|
352
|
+
*/
|
|
353
|
+
export function isSoftwareRenderer(renderer) {
|
|
354
|
+
if (!renderer)
|
|
355
|
+
return false;
|
|
356
|
+
const lowered = renderer.toLowerCase();
|
|
357
|
+
return SOFTWARE_RENDERERS.some((name) => lowered.includes(name.toLowerCase()));
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* The taskbar, menu bar or panel a desktop reserves, in CSS pixels. A screen
|
|
361
|
+
* whose available area equals its whole area on both axes has none, which only
|
|
362
|
+
* a kiosk shows.
|
|
363
|
+
*/
|
|
364
|
+
export const TASKBAR_HEIGHT = LAUNCHER_CONSTANTS.taskbarHeight;
|
|
365
|
+
/** Reserve the OS's taskbar when the identity's available area is its whole screen. */
|
|
366
|
+
export function fixScreenNoTaskbar(config, targetOs) {
|
|
367
|
+
const width = config["screen.width"];
|
|
368
|
+
const height = config["screen.height"];
|
|
369
|
+
if (!(pyTruthy(width) && pyTruthy(height)))
|
|
370
|
+
return;
|
|
371
|
+
const availW = config["screen.availWidth"];
|
|
372
|
+
const availH = config["screen.availHeight"];
|
|
373
|
+
if (isNone(availW) || isNone(availH))
|
|
374
|
+
return;
|
|
375
|
+
if (num(availW) !== num(width) || num(availH) !== num(height))
|
|
376
|
+
return;
|
|
377
|
+
const taskbar = TASKBAR_HEIGHT[targetOs];
|
|
378
|
+
config["screen.availHeight"] = num(height) - taskbar;
|
|
379
|
+
if (targetOs === "mac")
|
|
380
|
+
config["screen.availTop"] = taskbar;
|
|
381
|
+
const outer = config["window.outerHeight"];
|
|
382
|
+
if (pyTruthy(outer) && num(outer) > num(height) - taskbar) {
|
|
383
|
+
config["window.outerHeight"] = num(height) - taskbar;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Families every installation of the OS has. fpgen records the fonts a probe
|
|
388
|
+
* list found, so a short record (six families on some Linux machines) would
|
|
389
|
+
* otherwise leave a page with almost nothing to render in.
|
|
390
|
+
*/
|
|
391
|
+
export const ESSENTIAL_FONTS = LAUNCHER_CONSTANTS.essentialFonts;
|
|
392
|
+
/**
|
|
393
|
+
* The families each OS's persona can render from the shipped font bundle
|
|
394
|
+
* (scripts/gen-bundle-fonts.py). A claimed family the bundle cannot render is
|
|
395
|
+
* caught by one measureText call, so nothing outside this list is claimed.
|
|
396
|
+
*/
|
|
397
|
+
const BUNDLE_FONTS = (() => {
|
|
398
|
+
const { families } = loadDataFile("data/bundle-fonts.json");
|
|
399
|
+
const lower = (os) => new Set(families[os].map((f) => f.toLowerCase()));
|
|
400
|
+
return { win: lower("win"), mac: lower("mac"), lin: lower("lin") };
|
|
401
|
+
})();
|
|
402
|
+
/**
|
|
403
|
+
* The devices a machine with nothing plugged in enumerates, before the page
|
|
404
|
+
* has media permission: one entry per kind, with empty id, label and group.
|
|
405
|
+
*/
|
|
406
|
+
export const MEDIA_DEVICE_KINDS = [
|
|
407
|
+
"audioinput",
|
|
408
|
+
"videoinput",
|
|
409
|
+
"audiooutput",
|
|
410
|
+
];
|
|
411
|
+
export const DEFAULT_MEDIA_DEVICES = {
|
|
412
|
+
win: ["audioinput|||", "videoinput|||", "audiooutput|||"],
|
|
413
|
+
mac: ["audioinput|||", "videoinput|||", "audiooutput|||"],
|
|
414
|
+
lin: ["audioinput|||", "audiooutput|||"],
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* fpgen's device counts as `mediaDevices:enumerated` entries.
|
|
418
|
+
*
|
|
419
|
+
* Before a page holds media permission Chrome lists at most one device of
|
|
420
|
+
* each kind, with empty deviceId, label and groupId.
|
|
421
|
+
*/
|
|
422
|
+
export function mediaDevices(devices) {
|
|
423
|
+
if (!isPlainObject(devices))
|
|
424
|
+
return null;
|
|
425
|
+
const listed = MEDIA_DEVICE_KINDS.filter((kind) => num(pyTruthy(devices[kind]) ? devices[kind] : 0) > 0).map((kind) => `${kind}|||`);
|
|
426
|
+
return listed.length ? listed : null;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* fpgen's speechSynthesis voices as `voices` entries: name|lang|uri|local|default.
|
|
430
|
+
*
|
|
431
|
+
* Network voices (Google's) only with `network`: they come with Chrome, not
|
|
432
|
+
* Chromium, so only a build whose product is Chrome claims them.
|
|
433
|
+
*/
|
|
434
|
+
export function packVoices(voices, network = false) {
|
|
435
|
+
if (!Array.isArray(voices))
|
|
436
|
+
return null;
|
|
437
|
+
const packed = [];
|
|
438
|
+
for (const voice of voices) {
|
|
439
|
+
if (!isPlainObject(voice) ||
|
|
440
|
+
!pyTruthy(voice.name) ||
|
|
441
|
+
!pyTruthy(voice.lang) ||
|
|
442
|
+
(!network && !pyTruthy(voice.localService))) {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
const fields = [
|
|
446
|
+
voice.name,
|
|
447
|
+
voice.lang,
|
|
448
|
+
pyTruthy(voice.voiceURI) ? voice.voiceURI : voice.name,
|
|
449
|
+
].map(pyStr);
|
|
450
|
+
// The separator; no recorded voice has one.
|
|
451
|
+
if (fields.some((field) => field.includes("|")))
|
|
452
|
+
continue;
|
|
453
|
+
packed.push([
|
|
454
|
+
...fields,
|
|
455
|
+
pyTruthy(voice.localService) ? "1" : "0",
|
|
456
|
+
pyTruthy(voice.default) ? "1" : "0",
|
|
457
|
+
].join("|"));
|
|
458
|
+
}
|
|
459
|
+
return packed.length ? packed : null;
|
|
460
|
+
}
|
|
461
|
+
/** A WebCodecs codec string's prefix, as media::GetCodecName names the codec. */
|
|
462
|
+
export const CODEC_NAMES = {
|
|
463
|
+
avc1: "h264",
|
|
464
|
+
avc3: "h264",
|
|
465
|
+
vp8: "vp8",
|
|
466
|
+
vp09: "vp9",
|
|
467
|
+
av01: "av1",
|
|
468
|
+
hev1: "hevc",
|
|
469
|
+
hvc1: "hevc",
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* The receive formats Chrome's hardware decoder factory adds for a codec: H264
|
|
473
|
+
* High at the fixed level 3.1, and HEVC Main and Main 10 at the level of an
|
|
474
|
+
* 8K-capable decoder (what a recorded macOS Chrome reports).
|
|
475
|
+
*/
|
|
476
|
+
export const RTC_DECODE_FORMATS = {
|
|
477
|
+
h264: [
|
|
478
|
+
"H264|level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f",
|
|
479
|
+
"H264|level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=64001f",
|
|
480
|
+
],
|
|
481
|
+
hevc: [
|
|
482
|
+
"H265|level-id=180;profile-id=1;tier-flag=0;tx-mode=SRST",
|
|
483
|
+
"H265|level-id=180;profile-id=2;tier-flag=0;tx-mode=SRST",
|
|
484
|
+
],
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* The identity's hardware codecs, as the media:* keys.
|
|
488
|
+
*
|
|
489
|
+
* A decoder is the GPU's when the record decoded it with prefer-hardware. The
|
|
490
|
+
* hardware encoders are the sender formats software never offers (H264 High,
|
|
491
|
+
* H265). AAC is encoded by the OS on Windows and macOS. A record without the
|
|
492
|
+
* data claims nothing.
|
|
493
|
+
*/
|
|
494
|
+
export function platformCodecs(fingerprint, targetOs) {
|
|
495
|
+
const decoders = fingerprint.mediaDecoderSupport?.video;
|
|
496
|
+
const codecs = fingerprint.rtcCapabilities?.video?.codecs;
|
|
497
|
+
if (!isPlainObject(decoders) || !Array.isArray(codecs))
|
|
498
|
+
return {};
|
|
499
|
+
const decoded = new Set();
|
|
500
|
+
for (const [codec, configs] of Object.entries(decoders)) {
|
|
501
|
+
const name = CODEC_NAMES[codec.split(".", 1)[0]];
|
|
502
|
+
if (name &&
|
|
503
|
+
Array.isArray(configs) &&
|
|
504
|
+
configs.some((config) => isPlainObject(config) &&
|
|
505
|
+
Object.keys(config).length === 1 &&
|
|
506
|
+
config.hardwareAcceleration === "prefer-hardware")) {
|
|
507
|
+
decoded.add(name);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const encodeFormats = [];
|
|
511
|
+
const encoded = new Set();
|
|
512
|
+
for (const codec of codecs) {
|
|
513
|
+
const name = pyStr(codec?.mimeType ?? "").replace(/^video\//, "");
|
|
514
|
+
const fmtp = codec?.sdpFmtpLine ?? "";
|
|
515
|
+
if (name === "H265" ||
|
|
516
|
+
(name === "H264" && fmtp.includes("profile-level-id=64"))) {
|
|
517
|
+
encodeFormats.push(`${name}|${fmtp}`);
|
|
518
|
+
encoded.add(name === "H265" ? "hevc" : "h264");
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (targetOs === "win" || targetOs === "mac")
|
|
522
|
+
encoded.add("aac");
|
|
523
|
+
const decodedList = [...decoded].sort();
|
|
524
|
+
return {
|
|
525
|
+
"media:platformDecoders": decodedList,
|
|
526
|
+
"media:platformEncoders": [...encoded].sort(),
|
|
527
|
+
"media:rtcEncodeFormats": encodeFormats,
|
|
528
|
+
"media:rtcDecodeFormats": decodedList.flatMap((codec) => RTC_DECODE_FORMATS[codec] ?? []),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* The WebGPU adapter of an fpgen record, as webGpu:* keys.
|
|
533
|
+
*
|
|
534
|
+
* The preferred canvas format is the OS's, so it is claimed from any record,
|
|
535
|
+
* including one of a machine that had no adapter (an empty list), except on a
|
|
536
|
+
* Linux identity: the browser is Chrome on Linux at its own milestone, and
|
|
537
|
+
* fpgen's Linux records predate the milestone that moved Linux to rgba8unorm.
|
|
538
|
+
* The adapter is claimed only from a record of the identity's GPU, which
|
|
539
|
+
* gpuInfo names in unmaskedRenderer.
|
|
540
|
+
*/
|
|
541
|
+
export function webgpuAdapter(gpuInfo, renderer, targetOs) {
|
|
542
|
+
if (!isPlainObject(gpuInfo))
|
|
543
|
+
return {};
|
|
544
|
+
const out = {};
|
|
545
|
+
const format = gpuInfo.preferredCanvasFormat;
|
|
546
|
+
if (targetOs !== "lin" &&
|
|
547
|
+
(format === "bgra8unorm" || format === "rgba8unorm")) {
|
|
548
|
+
out["webGpu:preferredCanvasFormat"] = format;
|
|
549
|
+
}
|
|
550
|
+
if (!renderer || gpuInfo.unmaskedRenderer !== renderer)
|
|
551
|
+
return out;
|
|
552
|
+
const adapter = gpuInfo.adapter;
|
|
553
|
+
const dflt = isPlainObject(adapter) ? adapter.default : null;
|
|
554
|
+
const info = isPlainObject(dflt) ? dflt.info : null;
|
|
555
|
+
if (!isPlainObject(info))
|
|
556
|
+
return out;
|
|
557
|
+
for (const key of ["vendor", "architecture", "device"]) {
|
|
558
|
+
if (typeof info[key] === "string")
|
|
559
|
+
out[`webGpu:${key}`] = info[key];
|
|
560
|
+
}
|
|
561
|
+
for (const key of ["subgroupMinSize", "subgroupMaxSize"]) {
|
|
562
|
+
if (Number.isInteger(info[key]) && info[key] >= 0) {
|
|
563
|
+
out[`webGpu:${key}`] = info[key];
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const features = dflt.features;
|
|
567
|
+
if (Array.isArray(features) && features.every((f) => typeof f === "string")) {
|
|
568
|
+
out["webGpu:features"] = features;
|
|
569
|
+
}
|
|
570
|
+
const limits = dflt.limits;
|
|
571
|
+
if (isPlainObject(limits)) {
|
|
572
|
+
const numeric = Object.fromEntries(Object.entries(limits).filter(([, v]) => Number.isInteger(v) || typeof v === "bigint"));
|
|
573
|
+
if (Object.keys(numeric).length)
|
|
574
|
+
out["webGpu:limits"] = numeric;
|
|
575
|
+
}
|
|
576
|
+
return out;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* The identity's installed families: the record's, with the OS's own, less
|
|
580
|
+
* any the bundle cannot render for that OS.
|
|
581
|
+
*/
|
|
582
|
+
export function fontList(fonts, targetOs) {
|
|
583
|
+
if (!Array.isArray(fonts) || !fonts.length)
|
|
584
|
+
return null;
|
|
585
|
+
const shippable = BUNDLE_FONTS[targetOs];
|
|
586
|
+
const families = new Map();
|
|
587
|
+
for (const name of [...fonts, ...ESSENTIAL_FONTS[targetOs]]) {
|
|
588
|
+
if (typeof name !== "string")
|
|
589
|
+
continue;
|
|
590
|
+
const key = name.toLowerCase();
|
|
591
|
+
if (shippable.has(key) && !families.has(key))
|
|
592
|
+
families.set(key, name);
|
|
593
|
+
}
|
|
594
|
+
return [...families.values()];
|
|
595
|
+
}
|
|
596
|
+
/** Copy the scalar fields fpgen.yml names into Camouwolf config properties. */
|
|
597
|
+
function castToProperties(camouwolfData, castEnum, fp) {
|
|
598
|
+
for (const [key, raw] of Object.entries(fp)) {
|
|
599
|
+
const typeKey = Object.hasOwn(castEnum, key) ? castEnum[key] : undefined;
|
|
600
|
+
if (!pyTruthy(typeKey))
|
|
601
|
+
continue;
|
|
602
|
+
if (isPlainObject(raw)) {
|
|
603
|
+
if (isPlainObject(typeKey))
|
|
604
|
+
castToProperties(camouwolfData, typeKey, raw);
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
// fpgen writes a field the browser did not have as None or "undefined".
|
|
608
|
+
if (isNone(raw) || raw === "" || raw === "undefined" || Array.isArray(raw))
|
|
609
|
+
continue;
|
|
610
|
+
if (typeof typeKey !== "string")
|
|
611
|
+
continue;
|
|
612
|
+
let data = raw;
|
|
613
|
+
// Fix values that are out of bounds
|
|
614
|
+
if (typeKey.startsWith("screen.") && isInt(data) && Number(data) < 0)
|
|
615
|
+
data = 0;
|
|
616
|
+
camouwolfData[typeKey] = data;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
/** Sets window.screenY based on the generated screenX value. */
|
|
620
|
+
export function handleScreenXY(camouwolfData, fingerprint) {
|
|
621
|
+
// Skip if manually provided
|
|
622
|
+
if ("window.screenY" in camouwolfData)
|
|
623
|
+
return;
|
|
624
|
+
const screen = pyTruthy(fingerprint.screen) ? fingerprint.screen : {};
|
|
625
|
+
const window = pyTruthy(fingerprint.window) ? fingerprint.window : {};
|
|
626
|
+
// Default screenX to 0 if not provided
|
|
627
|
+
const screenX = window.screenX;
|
|
628
|
+
if (!pyTruthy(screenX)) {
|
|
629
|
+
camouwolfData["window.screenX"] = 0;
|
|
630
|
+
camouwolfData["window.screenY"] = 0;
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
// If screenX is within [-50, 50], use the same value for screenY
|
|
634
|
+
const x = num(screenX);
|
|
635
|
+
if (Number.isInteger(x) && x >= -50 && x <= 50) {
|
|
636
|
+
camouwolfData["window.screenY"] = screenX;
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
// The generator thinks the browser is windowed. Randomly generate a screenY.
|
|
640
|
+
const screenY = num(pyTruthy(screen.availHeight) ? screen.availHeight : 0) -
|
|
641
|
+
num(pyTruthy(window.outerHeight) ? window.outerHeight : 0);
|
|
642
|
+
if (screenY === 0)
|
|
643
|
+
camouwolfData["window.screenY"] = 0;
|
|
644
|
+
else if (screenY > 0)
|
|
645
|
+
camouwolfData["window.screenY"] = random.randrange(0, screenY);
|
|
646
|
+
else
|
|
647
|
+
camouwolfData["window.screenY"] = random.randrange(screenY, 0);
|
|
648
|
+
}
|
|
649
|
+
/** The OS key ('win', 'mac', 'lin') an fpgen fingerprint was recorded on. */
|
|
650
|
+
export function fingerprintOs(fingerprint) {
|
|
651
|
+
const navigator = pyTruthy(fingerprint.navigator)
|
|
652
|
+
? fingerprint.navigator
|
|
653
|
+
: {};
|
|
654
|
+
const userAgent = navigator.userAgent;
|
|
655
|
+
return typeof userAgent === "string" ? uaOs(userAgent) : null;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Converts an fpgen Chrome fingerprint to a Camouwolf config.
|
|
659
|
+
*
|
|
660
|
+
* `chromeVersion` is the Chromium milestone of the browser that will run; the
|
|
661
|
+
* recorded user agent is rewritten to it. `networkVoices` keeps the recorded
|
|
662
|
+
* network voices, for a build whose product is Chrome (packVoices).
|
|
663
|
+
*/
|
|
664
|
+
export function fromFpgen(fingerprint, chromeVersion, networkVoices = false) {
|
|
665
|
+
const camouwolfData = {};
|
|
666
|
+
castToProperties(camouwolfData, FPGEN_DATA, fingerprint);
|
|
667
|
+
handleScreenXY(camouwolfData, fingerprint);
|
|
668
|
+
const userAgent = camouwolfData["navigator.userAgent"];
|
|
669
|
+
if (pyTruthy(chromeVersion) && typeof userAgent === "string") {
|
|
670
|
+
camouwolfData["navigator.userAgent"] = retargetUserAgent(userAgent, pyStr(chromeVersion).split(".", 1)[0]);
|
|
671
|
+
}
|
|
672
|
+
const targetOs = fingerprintOs(fingerprint);
|
|
673
|
+
const voices = packVoices(fingerprint.voices, networkVoices);
|
|
674
|
+
if (voices)
|
|
675
|
+
camouwolfData.voices = voices;
|
|
676
|
+
Object.assign(camouwolfData, webglIdentity(fingerprint, camouwolfData["webGl:renderer"]), webgpuAdapter(fingerprint.gpuInfo, camouwolfData["webGl:renderer"], targetOs), platformCodecs(fingerprint, targetOs));
|
|
677
|
+
const devices = mediaDevices(fingerprint.devices);
|
|
678
|
+
if (devices)
|
|
679
|
+
camouwolfData["mediaDevices:enumerated"] = devices;
|
|
680
|
+
if (targetOs) {
|
|
681
|
+
const fonts = fontList(fingerprint.allFonts, targetOs);
|
|
682
|
+
if (fonts)
|
|
683
|
+
camouwolfData.fonts = fonts;
|
|
684
|
+
}
|
|
685
|
+
return camouwolfData;
|
|
686
|
+
}
|
|
687
|
+
/** Sets a custom outer window size and centers it in the screen (in place). */
|
|
688
|
+
export function handleWindowSize(fp, outerWidth, outerHeight) {
|
|
689
|
+
fp.screen ??= {};
|
|
690
|
+
fp.window ??= {};
|
|
691
|
+
const screen = fp.screen;
|
|
692
|
+
const window = fp.window;
|
|
693
|
+
// Center the window on the screen
|
|
694
|
+
window.screenX =
|
|
695
|
+
(window.screenX || 0) +
|
|
696
|
+
Math.floor(((screen.width || outerWidth) - outerWidth) / 2);
|
|
697
|
+
window.screenY = Math.floor(((screen.height || outerHeight) - outerHeight) / 2);
|
|
698
|
+
// Update inner dimensions if set
|
|
699
|
+
if (pyTruthy(window.innerWidth)) {
|
|
700
|
+
window.innerWidth = Math.max(outerWidth - (window.outerWidth || 0) + window.innerWidth, 0);
|
|
701
|
+
}
|
|
702
|
+
if (pyTruthy(window.innerHeight)) {
|
|
703
|
+
window.innerHeight = Math.max(outerHeight - (window.outerHeight || 0) + window.innerHeight, 0);
|
|
704
|
+
}
|
|
705
|
+
// Set outer dimensions
|
|
706
|
+
window.outerWidth = outerWidth;
|
|
707
|
+
window.outerHeight = outerHeight;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Generates a Chrome fingerprint with fpgen (the model must be installed:
|
|
711
|
+
* `await ensureFpgenModel()`).
|
|
712
|
+
*
|
|
713
|
+
* `screen` bounds the generated screen; `window` overrides the outer window
|
|
714
|
+
* size afterwards. `os` is Camouwolf's name for the platform ('linux',
|
|
715
|
+
* 'macos', 'windows', or several); anything else is passed to fpgen as a
|
|
716
|
+
* condition.
|
|
717
|
+
*/
|
|
718
|
+
export function generateFingerprint({ window, screen, os, ...conditions } = {}) {
|
|
719
|
+
if (os?.length) {
|
|
720
|
+
const names = typeof os === "string" ? [os] : [...os];
|
|
721
|
+
const resolved = names.map((n) => {
|
|
722
|
+
const key = pyStr(n).toLowerCase();
|
|
723
|
+
if (!Object.hasOwn(FPGEN_OS, key)) {
|
|
724
|
+
throw new ValueError(`Unknown OS for fingerprint generation: ${pyStrRepr(key)}`);
|
|
725
|
+
}
|
|
726
|
+
return FPGEN_OS[key];
|
|
727
|
+
});
|
|
728
|
+
// fpgen takes one value, or a set of alternatives (Python: a tuple; an
|
|
729
|
+
// array is read as one value).
|
|
730
|
+
conditions.os = resolved.length === 1 ? resolved[0] : new Set(resolved);
|
|
731
|
+
}
|
|
732
|
+
const screenConditions = screen ? screen.asConditions() : {};
|
|
733
|
+
let fingerprint;
|
|
734
|
+
try {
|
|
735
|
+
fingerprint = generate({
|
|
736
|
+
browser: "Chrome",
|
|
737
|
+
...conditions,
|
|
738
|
+
...screenConditions,
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
catch (err) {
|
|
742
|
+
if (!Object.keys(screenConditions).length ||
|
|
743
|
+
!(err instanceof InvalidConstraints))
|
|
744
|
+
throw err;
|
|
745
|
+
// The screen bound is best-effort: a display the model has nothing to
|
|
746
|
+
// fit (a 1x1 Xvfb, a small panel) must not stop generation, and
|
|
747
|
+
// clampScreenToDisplay() still bounds the result afterwards.
|
|
748
|
+
fingerprint = generate({ browser: "Chrome", ...conditions });
|
|
749
|
+
}
|
|
750
|
+
if (window)
|
|
751
|
+
handleWindowSize(fingerprint, window[0], window[1]);
|
|
752
|
+
return fingerprint;
|
|
753
|
+
}
|