camoucore 0.3.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.
Files changed (171) hide show
  1. package/LICENSE +4 -3
  2. package/dist/camoufox/__main__.d.ts +10 -0
  3. package/dist/camoufox/__main__.js +1175 -0
  4. package/dist/camoufox/__version__.d.ts +31 -0
  5. package/dist/camoufox/__version__.js +32 -0
  6. package/dist/camoufox/_humanize_playwright.d.ts +54 -0
  7. package/dist/camoufox/_humanize_playwright.js +429 -0
  8. package/dist/camoufox/addons.d.ts +21 -0
  9. package/dist/camoufox/addons.js +56 -0
  10. package/dist/camoufox/async_api.d.ts +9 -0
  11. package/dist/camoufox/async_api.js +9 -0
  12. package/dist/camoufox/browser-pin.d.ts +46 -0
  13. package/dist/camoufox/browser-pin.js +96 -0
  14. package/dist/camoufox/cli.d.ts +7 -0
  15. package/dist/camoufox/cli.js +20 -0
  16. package/dist/camoufox/coherence.d.ts +141 -0
  17. package/dist/camoufox/coherence.js +708 -0
  18. package/dist/camoufox/data-files/audio-output-latency.json +15 -0
  19. package/dist/camoufox/data-files/browser-pin.json +7 -0
  20. package/dist/camoufox/data-files/display-profiles.json +6 -0
  21. package/dist/camoufox/data-files/essential-fonts.json +5 -0
  22. package/dist/camoufox/data-files/fingerprint-presets-v150.json +14544 -0
  23. package/dist/camoufox/data-files/fingerprint-presets.json +5192 -0
  24. package/dist/camoufox/data-files/font-bases.json +1888 -0
  25. package/dist/camoufox/data-files/font-groups.json +716 -0
  26. package/dist/camoufox/data-files/font-prefs.json +1046 -0
  27. package/dist/camoufox/data-files/fonts.json +240 -0
  28. package/dist/camoufox/data-files/fpgen.yml +44 -0
  29. package/dist/camoufox/data-files/launcher-constants.json +136 -0
  30. package/dist/camoufox/data-files/media-devices.json +180 -0
  31. package/dist/camoufox/data-files/repos.yml +40 -0
  32. package/dist/camoufox/data-files/voice-manifests.json +1864 -0
  33. package/dist/camoufox/data-files/voice-uris.json +188 -0
  34. package/dist/camoufox/data-files/warnings.yml +146 -0
  35. package/dist/camoufox/display_profile.d.ts +21 -0
  36. package/dist/camoufox/display_profile.js +129 -0
  37. package/dist/camoufox/driver_defaults.d.ts +27 -0
  38. package/dist/camoufox/driver_defaults.js +119 -0
  39. package/dist/camoufox/exceptions.d.ts +68 -0
  40. package/dist/camoufox/exceptions.js +122 -0
  41. package/dist/camoufox/fingerprints.d.ts +434 -0
  42. package/dist/camoufox/fingerprints.js +1936 -0
  43. package/dist/camoufox/gpudisplay.d.ts +158 -0
  44. package/dist/camoufox/gpudisplay.js +695 -0
  45. package/dist/camoufox/host_rendering.d.ts +38 -0
  46. package/dist/camoufox/host_rendering.js +180 -0
  47. package/dist/camoufox/humanize.d.ts +89 -0
  48. package/dist/camoufox/humanize.js +143 -0
  49. package/dist/camoufox/index.d.ts +21 -0
  50. package/dist/camoufox/index.js +21 -0
  51. package/dist/camoufox/ip.d.ts +45 -0
  52. package/dist/camoufox/ip.js +114 -0
  53. package/dist/camoufox/multiversion.d.ts +131 -0
  54. package/dist/camoufox/multiversion.js +490 -0
  55. package/dist/camoufox/node-floor.d.ts +5 -0
  56. package/dist/camoufox/node-floor.js +17 -0
  57. package/dist/camoufox/paths.d.ts +45 -0
  58. package/dist/camoufox/paths.js +62 -0
  59. package/dist/camoufox/pkgman.d.ts +361 -0
  60. package/dist/camoufox/pkgman.js +1066 -0
  61. package/dist/camoufox/product.d.ts +8 -0
  62. package/dist/camoufox/product.js +8 -0
  63. package/dist/camoufox/pycompat.d.ts +97 -0
  64. package/dist/camoufox/pycompat.js +458 -0
  65. package/dist/camoufox/server.d.ts +36 -0
  66. package/dist/camoufox/server.js +82 -0
  67. package/dist/camoufox/sync_api.d.ts +77 -0
  68. package/dist/camoufox/sync_api.js +207 -0
  69. package/dist/camoufox/utils.d.ts +638 -0
  70. package/dist/camoufox/utils.js +2507 -0
  71. package/dist/camoufox/warnings.d.ts +16 -0
  72. package/dist/camoufox/warnings.js +65 -0
  73. package/dist/camoufox/webgl.d.ts +52 -0
  74. package/dist/camoufox/webgl.js +264 -0
  75. package/dist/camouwolf/__main__.d.ts +10 -0
  76. package/dist/camouwolf/__main__.js +1180 -0
  77. package/dist/camouwolf/__version__.d.ts +31 -0
  78. package/dist/camouwolf/__version__.js +32 -0
  79. package/dist/camouwolf/_humanize_playwright.d.ts +53 -0
  80. package/dist/camouwolf/_humanize_playwright.js +427 -0
  81. package/dist/camouwolf/addons.d.ts +42 -0
  82. package/dist/camouwolf/addons.js +113 -0
  83. package/dist/camouwolf/async_api.d.ts +9 -0
  84. package/dist/camouwolf/async_api.js +9 -0
  85. package/dist/camouwolf/browser-pin.d.ts +46 -0
  86. package/dist/camouwolf/browser-pin.js +96 -0
  87. package/dist/camouwolf/cli.d.ts +7 -0
  88. package/dist/camouwolf/cli.js +20 -0
  89. package/dist/camouwolf/clienthints.d.ts +61 -0
  90. package/dist/camouwolf/clienthints.js +176 -0
  91. package/dist/camouwolf/coherence.d.ts +152 -0
  92. package/dist/camouwolf/coherence.js +554 -0
  93. package/dist/camouwolf/data-files/browser-pin.json +7 -0
  94. package/dist/camouwolf/data-files/camouwolf.defaults.json +118 -0
  95. package/dist/camouwolf/data-files/data/bundle-fonts.json +1983 -0
  96. package/dist/camouwolf/data-files/data/chrome-languages.json +517 -0
  97. package/dist/camouwolf/data-files/data/properties.json +321 -0
  98. package/dist/camouwolf/data-files/data/system-colors.json +35 -0
  99. package/dist/camouwolf/data-files/data/ubo.json +6 -0
  100. package/dist/camouwolf/data-files/fpgen.yml +41 -0
  101. package/dist/camouwolf/data-files/launcher-constants.json +26 -0
  102. package/dist/camouwolf/data-files/repos.yml +23 -0
  103. package/dist/camouwolf/data-files/warnings.yml +96 -0
  104. package/dist/camouwolf/driver_defaults.d.ts +25 -0
  105. package/dist/camouwolf/driver_defaults.js +114 -0
  106. package/dist/camouwolf/exceptions.d.ts +95 -0
  107. package/dist/camouwolf/exceptions.js +150 -0
  108. package/dist/camouwolf/fingerprints.d.ts +227 -0
  109. package/dist/camouwolf/fingerprints.js +753 -0
  110. package/dist/camouwolf/gpudisplay.d.ts +171 -0
  111. package/dist/camouwolf/gpudisplay.js +711 -0
  112. package/dist/camouwolf/host_rendering.d.ts +18 -0
  113. package/dist/camouwolf/host_rendering.js +114 -0
  114. package/dist/camouwolf/humanize.d.ts +84 -0
  115. package/dist/camouwolf/humanize.js +128 -0
  116. package/dist/camouwolf/index.d.ts +22 -0
  117. package/dist/camouwolf/index.js +21 -0
  118. package/dist/camouwolf/multiversion.d.ts +131 -0
  119. package/dist/camouwolf/multiversion.js +491 -0
  120. package/dist/camouwolf/node-floor.d.ts +5 -0
  121. package/dist/camouwolf/node-floor.js +17 -0
  122. package/dist/camouwolf/paths.d.ts +34 -0
  123. package/dist/camouwolf/paths.js +58 -0
  124. package/dist/camouwolf/pkgman.d.ts +331 -0
  125. package/dist/camouwolf/pkgman.js +972 -0
  126. package/dist/camouwolf/product.d.ts +3 -0
  127. package/dist/camouwolf/product.js +3 -0
  128. package/dist/camouwolf/pycompat.d.ts +92 -0
  129. package/dist/camouwolf/pycompat.js +461 -0
  130. package/dist/camouwolf/server.d.ts +36 -0
  131. package/dist/camouwolf/server.js +81 -0
  132. package/dist/camouwolf/switches.d.ts +77 -0
  133. package/dist/camouwolf/switches.js +222 -0
  134. package/dist/camouwolf/sync_api.d.ts +84 -0
  135. package/dist/camouwolf/sync_api.js +173 -0
  136. package/dist/camouwolf/utils.d.ts +644 -0
  137. package/dist/camouwolf/utils.js +2057 -0
  138. package/dist/camouwolf/warnings.d.ts +14 -0
  139. package/dist/camouwolf/warnings.js +59 -0
  140. package/dist/camouwolf/webgl.d.ts +41 -0
  141. package/dist/camouwolf/webgl.js +198 -0
  142. package/dist/data.d.ts +1 -1
  143. package/dist/data.js +3 -3
  144. package/dist/download.js +1 -1
  145. package/dist/exceptions.d.ts +1 -1
  146. package/dist/exceptions.js +1 -1
  147. package/dist/geolocation.js +1 -1
  148. package/dist/host.js +1 -1
  149. package/dist/ip.js +1 -1
  150. package/dist/locales.js +1 -1
  151. package/dist/mcp/cli.d.ts +15 -0
  152. package/dist/mcp/cli.js +108 -0
  153. package/dist/mcp/index.d.ts +8 -0
  154. package/dist/mcp/index.js +8 -0
  155. package/dist/mcp/main.d.ts +2 -0
  156. package/dist/mcp/main.js +8 -0
  157. package/dist/mcp/secrets.d.ts +50 -0
  158. package/dist/mcp/secrets.js +193 -0
  159. package/dist/mcp/server.d.ts +48 -0
  160. package/dist/mcp/server.js +653 -0
  161. package/dist/mcp/tree.d.ts +10 -0
  162. package/dist/mcp/tree.js +36 -0
  163. package/dist/passthrough.d.ts +1 -1
  164. package/dist/product.js +1 -1
  165. package/dist/settings.js +1 -1
  166. package/dist/telemetry.d.ts +0 -1
  167. package/dist/telemetry.js +5 -4
  168. package/dist/virtdisplay.d.ts +1 -1
  169. package/dist/virtdisplay.js +1 -1
  170. package/dist/warnings.js +1 -1
  171. package/package.json +57 -13
@@ -0,0 +1,16 @@
1
+ export { LeakWarning, type RecordedWarning, recordWarnings, warn, } from "../warnings.js";
2
+ /** warnings.yml, loaded once. */
3
+ export declare function loadWarnings(): Record<string, string>;
4
+ /** A warnings.yml message with its {name} fields filled, as Python's str.format fills them. */
5
+ export declare function warningText(key: string, values?: Record<string, unknown>): string;
6
+ /**
7
+ * Emitted when part of an identity could not be drawn and a substitute was used.
8
+ */
9
+ export declare class FallbackWarning extends Error {
10
+ constructor(message: string);
11
+ /**
12
+ * Warns that `what` failed with `error` and the identity uses `instead`,
13
+ * with a block of versions and the error for the user to paste into an issue.
14
+ */
15
+ static warn(what: string, instead: string, error: unknown, identity?: string | null): void;
16
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Camoufox's warning messages and its FallbackWarning.
3
+ *
4
+ * TypeScript twin of python/camoucore/src/camoucore/camoufox/_warnings.py. The messages are read
5
+ * from the same warnings.yml the Python package ships, so both launchers say
6
+ * the same thing. The warning channel (warn, recordWarnings, LeakWarning) is
7
+ * camoucore's, so one recorder sees the core's warnings and camoufox's.
8
+ */
9
+ import * as os from "node:os";
10
+ import { warn } from "../warnings.js";
11
+ import { LIBRARY_VERSION } from "./__version__.js";
12
+ import { CamoufoxNotInstalled } from "./exceptions.js";
13
+ import { loadDataFile } from "./paths.js";
14
+ import { installedVerStr } from "./pkgman.js";
15
+ export { LeakWarning, recordWarnings, warn, } from "../warnings.js";
16
+ let warningsData;
17
+ /** warnings.yml, loaded once. */
18
+ export function loadWarnings() {
19
+ warningsData ??= loadDataFile("warnings.yml");
20
+ return warningsData;
21
+ }
22
+ /** A warnings.yml message with its {name} fields filled, as Python's str.format fills them. */
23
+ export function warningText(key, values = {}) {
24
+ return loadWarnings()[key].replace(/\{(\w+)\}/g, (field, name) => name in values ? String(values[name]) : field);
25
+ }
26
+ function browserVersion() {
27
+ try {
28
+ return installedVerStr();
29
+ }
30
+ catch (error) {
31
+ if (error instanceof CamoufoxNotInstalled)
32
+ return "not installed";
33
+ throw error;
34
+ }
35
+ }
36
+ /**
37
+ * Emitted when part of an identity could not be drawn and a substitute was used.
38
+ */
39
+ export class FallbackWarning extends Error {
40
+ constructor(message) {
41
+ super(message);
42
+ this.name = "FallbackWarning";
43
+ }
44
+ /**
45
+ * Warns that `what` failed with `error` and the identity uses `instead`,
46
+ * with a block of versions and the error for the user to paste into an issue.
47
+ */
48
+ static warn(what, instead, error, identity) {
49
+ const lines = [
50
+ `camoufox: ${LIBRARY_VERSION} (npm)`,
51
+ `browser: ${browserVersion()}`,
52
+ `os: ${os.type()}-${os.release()}-${os.arch()}`,
53
+ `node: ${process.versions.node}`,
54
+ `error: ${error instanceof Error ? `${error.name}: ${error.message}` : String(error)}`,
55
+ ];
56
+ if (identity)
57
+ lines.push(`identity: ${identity}`);
58
+ const values = {
59
+ what,
60
+ instead,
61
+ report: lines.map((line) => ` ${line}`).join("\n"),
62
+ };
63
+ warn(loadWarnings().fallback.replace(/\{(what|instead|report)\}/g, (_, key) => values[key]), "FallbackWarning");
64
+ }
65
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * WebGL identities from the Firefox devices fpgen recorded, the twin of webgl.py.
3
+ * One device supplies every WebGL1 and WebGL2 value, so the two never disagree,
4
+ * and the draws run in a fixed order so a seed gives the same device in both.
5
+ */
6
+ import { type Seed } from "python-random";
7
+ export type TargetOS = "win" | "mac" | "lin";
8
+ /** The config keys a WebGL identity sets. */
9
+ export interface WebGLData {
10
+ "webGl:vendor": string;
11
+ "webGl:renderer": string;
12
+ webGl2Enabled?: boolean;
13
+ [key: string]: any;
14
+ }
15
+ /**
16
+ * Every (vendor, renderer) that fpgen has seen Firefox report on this OS.
17
+ *
18
+ * A GPU outside this set has no recorded WebGL parameters behind it, so an
19
+ * identity naming it could only borrow another device's.
20
+ */
21
+ export declare function firefoxGpus(targetOs: string): Array<[string, string]>;
22
+ /**
23
+ * fpgen's `webgl` and `webgl2` values as Camoufox config keys. `webgl2` is
24
+ * `[]` for a device without WebGL2.
25
+ *
26
+ * Read the values with parsePyJson, as Python reads them, so an integral
27
+ * float and an integer past 2**53 reach CAMOU_CONFIG as the same digits.
28
+ */
29
+ export declare function toConfig(webgl: Record<string, any>, webgl2: any, targetOs: string): WebGLData;
30
+ /**
31
+ * The WebGL config of a device with this GPU, as Firefox on `targetOs`
32
+ * reports it.
33
+ *
34
+ * @throws ValueError for a GPU fpgen has never seen Firefox report on that OS:
35
+ * it has no recorded parameters, and another device's would contradict it.
36
+ */
37
+ export declare function webglForGpu(targetOs: string, vendor: string, renderer: string, seed?: Seed): WebGLData;
38
+ /**
39
+ * Draw a GPU for a synthetic identity, weighted as fpgen records Firefox on
40
+ * `targetOs`, and its WebGL config.
41
+ *
42
+ * Only GPUs the rest of the identity can stand beside are drawn: never a
43
+ * software rasteriser, a GPU the OS cannot report, the resistFingerprinting
44
+ * mask, a discrete GPU behind a netbook panel, or an Intel Mac GPU beside
45
+ * cores or a panel no Intel Mac has, or a GPU the claimed CPU cannot sit
46
+ * beside (cpu: cpu:arch and cpu:manufacturer, coherence.gpuFitsCpu). The
47
+ * screen is left alone:
48
+ * it has already been reconciled with the real display and the window (#499).
49
+ *
50
+ * @throws ValueError when no recorded GPU fits.
51
+ */
52
+ export declare function sampleWebglForScreen(targetOs: string, width?: number | null, height?: number | null, seed?: Seed, cores?: number | null, cpu?: Record<string, any> | null): WebGLData;
@@ -0,0 +1,264 @@
1
+ /**
2
+ * WebGL identities from the Firefox devices fpgen recorded, the twin of webgl.py.
3
+ * One device supplies every WebGL1 and WebGL2 value, so the two never disagree,
4
+ * and the draws run in a fixed order so a seed gives the same device in both.
5
+ */
6
+ import { lookupPossibilities, traceWithEvidence, } from "fpgen-js";
7
+ import { Random } from "python-random";
8
+ import { gpuFitsCpu, gpuFitsMachine, gpuFitsOs } from "./coherence.js";
9
+ import { FPGEN_OS, gpuScreenIsPlausible, isSoftwareRenderer, } from "./fingerprints.js";
10
+ import { comparePyStr, KeyError, orjsonDumps, parsePyJson, pyStr, pyStrRepr, pyTruthy, ValueError, } from "./pycompat.js";
11
+ // Extensions a release Firefox never exposes (draft extensions behind
12
+ // webgl.enable-draft-extensions, or mobile-only): fpgen's corpus carries some
13
+ // of them, and a spoofed list that names one is a tell on its own.
14
+ // EXT_texture_norm16 left draft in Firefox 159; where it is exposed,
15
+ // TEXTURE_NORM16 adds it back.
16
+ const NEVER_EXPOSED_EXTENSIONS = new Set([
17
+ "WEBGL_multi_draw",
18
+ "WEBGL_clip_cull_distance",
19
+ "EXT_texture_norm16",
20
+ "WEBGL_compressed_texture_etc1",
21
+ ]);
22
+ // OVR_multiview2 depends on the graphics backend: ANGLE's D3D11 backend has it
23
+ // on every Windows GPU, a Linux or macOS host driver may not, and the browser
24
+ // answers from the spoofed list without asking the host.
25
+ const HOST_DEPENDENT_EXTENSIONS = new Set([
26
+ "OVR_multiview2",
27
+ ]);
28
+ // Extensions the claimed OS's backend exposes on every GPU in Firefox 156,
29
+ // which fpgen's Firefox 146 records lack. ANGLE sets depthClampEXT
30
+ // unconditionally on D3D11 (renderer11_utils.cpp); 146's ANGLE did not.
31
+ const BACKEND_EXTENSIONS = {
32
+ win: ["EXT_depth_clamp"],
33
+ };
34
+ // Firefox 158 (bug 1854003) exposes EXT_polygon_offset_clamp wherever the GL
35
+ // backend clamps polygon offsets: ANGLE's D3D11 backend from feature level 10_0,
36
+ // which WebGL2 needs, and Linux desktop GL drivers (ARB_polygon_offset_clamp,
37
+ // core in GL 4.6), whose recordings have EXT_depth_clamp. macOS release builds
38
+ // run WebGL on CGL's GL 4.1, which lacks it.
39
+ const POLYGON_OFFSET_CLAMP = "EXT_polygon_offset_clamp";
40
+ // Firefox 159 (bug 1735401) exposes EXT_texture_norm16 on WebGL2 wherever the
41
+ // GL has 16-bit normalized textures, core in desktop GL 3.1: every WebGL2
42
+ // context on macOS (CGL's GL 4.1) and x86_64 Linux (desktop GL). On Windows,
43
+ // ANGLE derives it from 16-bit normalized format support (Caps.cpp
44
+ // DetermineTextureNorm16Support), which D3D11 feature level 10_0, the minimum
45
+ // for WebGL2, requires: stock 159.0 on a GeForce GTX 980 (ANGLE D3D11) lists it
46
+ // on WebGL2 and not WebGL1.
47
+ const TEXTURE_NORM16 = "EXT_texture_norm16";
48
+ const TEXTURE_NORM16_OSES = new Set(["mac", "lin", "win"]);
49
+ // Firefox 159 adds EXT_clip_control (core in GL 4.5) and
50
+ // EXT_texture_mirror_clamp_to_edge (core in GL 4.4) to WebGL1 and WebGL2. ANGLE's
51
+ // D3D11 backend sets clipControlEXT from feature level 10_0, which WebGL2 needs,
52
+ // and textureMirrorClampToEdgeEXT on every device (renderer11_utils.cpp). Linux
53
+ // desktop GL drivers, whose recordings have EXT_depth_clamp, expose both. CGL's
54
+ // GL 4.1 on macOS has neither.
55
+ const CLIP_CONTROL = "EXT_clip_control";
56
+ const TEXTURE_MIRROR_CLAMP_TO_EDGE = "EXT_texture_mirror_clamp_to_edge";
57
+ // Firefox 159 caps this at 64 KiB (WebGL2ContextState.cpp, kMaxUniformBlockSize);
58
+ // fpgen recorded the drivers' own limit, up to 4 GiB.
59
+ const MAX_UNIFORM_BLOCK_SIZE = "35376";
60
+ const MAX_UNIFORM_BLOCK_SIZE_CAP = 64 * 1024;
61
+ // What Firefox reports under privacy.resistFingerprinting, which a Camoufox
62
+ // identity otherwise does not present.
63
+ const RFP_RENDERER = "Mozilla";
64
+ function filteredExtensions(targetOs) {
65
+ if (targetOs === "win")
66
+ return NEVER_EXPOSED_EXTENSIONS;
67
+ return new Set([...NEVER_EXPOSED_EXTENSIONS, ...HOST_DEPENDENT_EXTENSIONS]);
68
+ }
69
+ function fpgenOs(targetOs) {
70
+ const name = FPGEN_OS[targetOs];
71
+ if (name === undefined)
72
+ throw new KeyError(pyStrRepr(targetOs));
73
+ return name;
74
+ }
75
+ /**
76
+ * Evidence fixing `node` to exactly the value stored as `text`.
77
+ *
78
+ * A dict passed to fpgen as a condition is flattened into one condition per
79
+ * leaf, and each leaf replaces the node's evidence, so only the last one
80
+ * applies. Pinning the value's own lookup index is exact.
81
+ */
82
+ function pin(node, text) {
83
+ const index = lookupPossibilities(node, false)?.get(text);
84
+ if (index === undefined)
85
+ throw new KeyError(pyStrRepr(text));
86
+ return [node, index];
87
+ }
88
+ const traceCache = new Map();
89
+ /** fpgen's distribution of `target` for Firefox on `targetOs`, in its order. */
90
+ function trace(target, targetOs, pinned = []) {
91
+ const key = JSON.stringify([target, targetOs, pinned]);
92
+ let results = traceCache.get(key);
93
+ if (!results) {
94
+ results = traceWithEvidence(target, { browser: "Firefox", os: fpgenOs(targetOs) }, {}, new Map(pinned.map(([node, index]) => [node, new Set([index])])));
95
+ traceCache.set(key, results);
96
+ }
97
+ return results;
98
+ }
99
+ function choose(rng, results) {
100
+ return rng.choices(results, {
101
+ weights: results.map((result) => result.probability),
102
+ })[0];
103
+ }
104
+ /**
105
+ * Every (vendor, renderer) that fpgen has seen Firefox report on this OS.
106
+ *
107
+ * A GPU outside this set has no recorded WebGL parameters behind it, so an
108
+ * identity naming it could only borrow another device's.
109
+ */
110
+ export function firefoxGpus(targetOs) {
111
+ return trace("gpu", targetOs.toLowerCase()).map((result) => [
112
+ result.value.vendor,
113
+ result.value.renderer,
114
+ ]);
115
+ }
116
+ /** The extensions the shipped Firefox adds on this device's backend. */
117
+ function backendExtensions(targetOs, webgl, hasWebgl2) {
118
+ const extensions = [...(BACKEND_EXTENSIONS[targetOs] ?? [])];
119
+ const desktopGl = targetOs === "lin" &&
120
+ webgl.supportedExtensions.includes("EXT_depth_clamp");
121
+ if ((targetOs === "win" && hasWebgl2) || desktopGl) {
122
+ extensions.push(POLYGON_OFFSET_CLAMP, CLIP_CONTROL);
123
+ }
124
+ if (targetOs === "win" || desktopGl) {
125
+ extensions.push(TEXTURE_MIRROR_CLAMP_TO_EDGE);
126
+ }
127
+ return extensions;
128
+ }
129
+ function contextConfig(prefix, webgl, targetOs, backend) {
130
+ const blocked = filteredExtensions(targetOs);
131
+ const extensions = webgl.supportedExtensions.filter((extension) => !blocked.has(extension));
132
+ for (const extension of backend) {
133
+ if (extensions.includes(extension))
134
+ continue;
135
+ // Firefox lists them in WebGLExtensionID order: alphabetical, ignoring case.
136
+ const at = extensions.findIndex((other) => other.toLowerCase() > extension.toLowerCase());
137
+ extensions.splice(at === -1 ? extensions.length : at, 0, extension);
138
+ }
139
+ return {
140
+ [`${prefix}:supportedExtensions`]: extensions,
141
+ [`${prefix}:parameters`]: Object.fromEntries(Object.entries(webgl.params).map(([pname, param]) => [pname, param.value])),
142
+ [`${prefix}:shaderPrecisionFormats`]: Object.fromEntries(webgl.shaderPrecisionFormats.map((entry) => [
143
+ `${entry.shaderType},${entry.precisionType}`,
144
+ entry.shaderPrecisionFormat,
145
+ ])),
146
+ };
147
+ }
148
+ /**
149
+ * fpgen's `webgl` and `webgl2` values as Camoufox config keys. `webgl2` is
150
+ * `[]` for a device without WebGL2.
151
+ *
152
+ * Read the values with parsePyJson, as Python reads them, so an integral
153
+ * float and an integer past 2**53 reach CAMOU_CONFIG as the same digits.
154
+ */
155
+ export function toConfig(webgl, webgl2, targetOs) {
156
+ const hasWebgl2 = Array.isArray(webgl2)
157
+ ? webgl2.length > 0
158
+ : Object.keys(webgl2 ?? {}).length > 0;
159
+ const backend = backendExtensions(targetOs, webgl, hasWebgl2);
160
+ const config = {
161
+ "webGl:vendor": webgl.vendor,
162
+ "webGl:renderer": webgl.renderer,
163
+ ...contextConfig("webGl", webgl, targetOs, backend),
164
+ webGl2Enabled: hasWebgl2,
165
+ };
166
+ if (hasWebgl2) {
167
+ const webgl2Backend = TEXTURE_NORM16_OSES.has(targetOs)
168
+ ? [...backend, TEXTURE_NORM16]
169
+ : backend;
170
+ Object.assign(config, contextConfig("webGl2", webgl2, targetOs, webgl2Backend));
171
+ // Firefox 156 creates WebGL1 on the same GL profile as WebGL2, so every
172
+ // parameter both report is one driver value (the line width range, the
173
+ // point size range...). 146 forced WebGL1 onto a compatibility profile,
174
+ // and fpgen recorded that profile's values. Only the version strings
175
+ // differ between the two.
176
+ const webgl1Parameters = config["webGl:parameters"];
177
+ for (const [key, value] of Object.entries(config["webGl2:parameters"])) {
178
+ if (key in webgl1Parameters && typeof value !== "string")
179
+ webgl1Parameters[key] = value;
180
+ }
181
+ const parameters = config["webGl2:parameters"];
182
+ if (MAX_UNIFORM_BLOCK_SIZE in parameters)
183
+ parameters[MAX_UNIFORM_BLOCK_SIZE] = Math.min(parameters[MAX_UNIFORM_BLOCK_SIZE], MAX_UNIFORM_BLOCK_SIZE_CAP);
184
+ }
185
+ // The values are the trace's cached objects; the caller gets its own copy.
186
+ return parsePyJson(orjsonDumps(config, false));
187
+ }
188
+ function webglConfig(targetOs, gpuText, rng) {
189
+ const gpuPin = pin("gpu", gpuText);
190
+ const webgl = choose(rng, trace("webgl", targetOs, [gpuPin]));
191
+ const webgl2 = choose(rng, trace("webgl2", targetOs, [gpuPin, pin("webgl", webgl.text)]));
192
+ return toConfig(parsePyJson(webgl.text), parsePyJson(webgl2.text), targetOs);
193
+ }
194
+ /**
195
+ * The WebGL config of a device with this GPU, as Firefox on `targetOs`
196
+ * reports it.
197
+ *
198
+ * @throws ValueError for a GPU fpgen has never seen Firefox report on that OS:
199
+ * it has no recorded parameters, and another device's would contradict it.
200
+ */
201
+ export function webglForGpu(targetOs, vendor, renderer, seed) {
202
+ const gpus = firefoxGpus(targetOs);
203
+ if (!gpus.some(([v, r]) => v === vendor && r === renderer)) {
204
+ const pairs = [...gpus]
205
+ .sort((a, b) => comparePyStr(a[0], b[0]) || comparePyStr(a[1], b[1]))
206
+ .map(([v, r]) => `(${pyStrRepr(v)}, ${pyStrRepr(r)})`);
207
+ throw new ValueError(`No recorded WebGL data for vendor ${pyStrRepr(vendor)} and renderer ${pyStrRepr(renderer)} ` +
208
+ `from Firefox on ${fpgenOs(targetOs)}. Possible pairs: [${pairs.join(", ")}]`);
209
+ }
210
+ return webglConfig(targetOs, orjsonDumps({ vendor, renderer }, false), new Random(seed));
211
+ }
212
+ /** The claimed CPU's [cpu:arch, cpu:manufacturer] (webgl._cpu_pair). */
213
+ function cpuPair(cpu) {
214
+ const c = cpu ?? {};
215
+ return [c["cpu:arch"] ?? null, c["cpu:manufacturer"] ?? null];
216
+ }
217
+ /**
218
+ * Draw a GPU for a synthetic identity, weighted as fpgen records Firefox on
219
+ * `targetOs`, and its WebGL config.
220
+ *
221
+ * Only GPUs the rest of the identity can stand beside are drawn: never a
222
+ * software rasteriser, a GPU the OS cannot report, the resistFingerprinting
223
+ * mask, a discrete GPU behind a netbook panel, or an Intel Mac GPU beside
224
+ * cores or a panel no Intel Mac has, or a GPU the claimed CPU cannot sit
225
+ * beside (cpu: cpu:arch and cpu:manufacturer, coherence.gpuFitsCpu). The
226
+ * screen is left alone:
227
+ * it has already been reconciled with the real display and the window (#499).
228
+ *
229
+ * @throws ValueError when no recorded GPU fits.
230
+ */
231
+ export function sampleWebglForScreen(targetOs, width, height, seed, cores, cpu) {
232
+ const [arch, maker] = cpuPair(cpu);
233
+ const fits = (result, software) => isSoftwareRenderer(result.value.renderer) === software &&
234
+ result.value.renderer !== RFP_RENDERER &&
235
+ gpuFitsOs(result.value.renderer, targetOs) &&
236
+ gpuFitsMachine(result.value.renderer, targetOs, cores, width, height) &&
237
+ gpuScreenIsPlausible(result.value.renderer, width, height) &&
238
+ gpuFitsCpu(result.value.renderer, targetOs, arch, maker);
239
+ let candidates = trace("gpu", targetOs).filter((r) => fits(r, false));
240
+ // Beside some CPUs fpgen records no hardware GPU at all: an ARM CPU in
241
+ // Firefox on Linux reports only llvmpipe. Such an identity draws what that
242
+ // population reports rather than nothing; any other draw still skips it.
243
+ if (!candidates.length &&
244
+ cpu &&
245
+ Object.keys(cpu).length &&
246
+ !trace("gpu", targetOs).some((r) => !isSoftwareRenderer(r.value.renderer) &&
247
+ gpuFitsCpu(r.value.renderer, targetOs, arch, maker))) {
248
+ candidates = trace("gpu", targetOs).filter((r) => fits(r, true));
249
+ }
250
+ if (!candidates.length) {
251
+ if (cpu &&
252
+ Object.keys(cpu).length &&
253
+ !trace("gpu", targetOs).some((r) => gpuFitsCpu(r.value.renderer, targetOs, arch, maker))) {
254
+ throw new ValueError(`No GPU fpgen has recorded from Firefox on ${targetOs} sits beside a ` +
255
+ `${[maker, arch]
256
+ .filter((v) => pyTruthy(v))
257
+ .map(pyStr)
258
+ .join(" ")} CPU`);
259
+ }
260
+ throw new ValueError(`No recorded ${targetOs} GPU fits a ${pyStr(width)}x${pyStr(height)} screen`);
261
+ }
262
+ const rng = new Random(seed);
263
+ return webglConfig(targetOs, choose(rng, candidates).text, rng);
264
+ }
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `camouwolf` CLI.
4
+ *
5
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/__main__.py. Every command is present,
6
+ * with the same arguments, output and config/cache files. The interactive
7
+ * pickers (`set`, `set --geoip`, `remove --select`) use a numbered
8
+ * prompt in place of inquirer's arrow-key list.
9
+ */
10
+ import "./node-floor.js";