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,14 @@
1
+ export { LeakWarning, type RecordedWarning, recordWarnings, warn, } from "../warnings.js";
2
+ /** warnings.yml, loaded once. */
3
+ export declare function loadWarnings(): Record<string, string>;
4
+ /**
5
+ * Emitted when part of an identity could not be drawn and a substitute was used.
6
+ */
7
+ export declare class FallbackWarning extends Error {
8
+ constructor(message: string);
9
+ /**
10
+ * Warns that `what` failed with `error` and the identity uses `instead`,
11
+ * with a block of versions and the error for the user to paste into an issue.
12
+ */
13
+ static warn(what: string, instead: string, error: unknown, identity?: string | null): void;
14
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Camouwolf's warning messages (warnings.yml) and FallbackWarning.
3
+ *
4
+ * The channel itself (warn, recordWarnings, LeakWarning) is camoucore's, so
5
+ * one recorder catches what the core and this launcher emit.
6
+ */
7
+ import * as os from "node:os";
8
+ import { warn } from "../warnings.js";
9
+ import { LIBRARY_VERSION } from "./__version__.js";
10
+ import { CamouwolfNotInstalled } from "./exceptions.js";
11
+ import { loadDataFile } from "./paths.js";
12
+ import { installedVerStr } from "./pkgman.js";
13
+ export { LeakWarning, recordWarnings, warn, } from "../warnings.js";
14
+ let warningsData;
15
+ /** warnings.yml, loaded once. */
16
+ export function loadWarnings() {
17
+ warningsData ??= loadDataFile("warnings.yml");
18
+ return warningsData;
19
+ }
20
+ function browserVersion() {
21
+ try {
22
+ return installedVerStr();
23
+ }
24
+ catch (error) {
25
+ if (error instanceof CamouwolfNotInstalled)
26
+ return "not installed";
27
+ throw error;
28
+ }
29
+ }
30
+ /**
31
+ * Emitted when part of an identity could not be drawn and a substitute was used.
32
+ */
33
+ export class FallbackWarning extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = "FallbackWarning";
37
+ }
38
+ /**
39
+ * Warns that `what` failed with `error` and the identity uses `instead`,
40
+ * with a block of versions and the error for the user to paste into an issue.
41
+ */
42
+ static warn(what, instead, error, identity) {
43
+ const lines = [
44
+ `camouwolf: ${LIBRARY_VERSION} (npm)`,
45
+ `browser: ${browserVersion()}`,
46
+ `os: ${os.type()}-${os.release()}-${os.arch()}`,
47
+ `node: ${process.versions.node}`,
48
+ `error: ${error instanceof Error ? `${error.name}: ${error.message}` : String(error)}`,
49
+ ];
50
+ if (identity)
51
+ lines.push(`identity: ${identity}`);
52
+ const values = {
53
+ what,
54
+ instead,
55
+ report: lines.map((line) => ` ${line}`).join("\n"),
56
+ };
57
+ warn(loadWarnings().fallback.replace(/\{(what|instead|report)\}/g, (_, key) => values[key]), "FallbackWarning");
58
+ }
59
+ }
@@ -0,0 +1,41 @@
1
+ import { PyFloat } from "./pycompat.js";
2
+ export type Scalar = number | PyFloat | bigint;
3
+ /**
4
+ * Whether Chrome on `targetOs` ('win', 'mac', 'lin', or the OS name) can
5
+ * report this renderer.
6
+ */
7
+ export declare function backendMatchesOs(renderer: string | null | undefined, targetOs: string): boolean;
8
+ /**
9
+ * Whether an identity may claim fpgen's `gpu` value: a real device, on a
10
+ * backend the OS uses.
11
+ */
12
+ export declare function usableGpu(gpu: unknown, targetOs?: string | null): boolean;
13
+ /** The device limits one recorded context reports: pname -> value. */
14
+ export declare function webglParameters(context: unknown): Record<string, Scalar | Scalar[]>;
15
+ type PrecisionFormat = {
16
+ rangeMin: number;
17
+ rangeMax: number;
18
+ precision: number;
19
+ };
20
+ /** A recorded getShaderPrecisionFormat table, keyed "<shaderType>,<precisionType>". */
21
+ export declare function shaderPrecisionFormats(context: unknown): Record<string, PrecisionFormat>;
22
+ /**
23
+ * Whether the record's WebGL1 and WebGL2 readouts are both of `renderer`.
24
+ * fpgen occasionally pairs one device's GPU with another's readout, or with
25
+ * none; an identity drawn from such a record has no limits for its renderer.
26
+ */
27
+ export declare function readoutNames(fingerprint: Record<string, any>, renderer: unknown): boolean;
28
+ /**
29
+ * The webGl:* and webGl2:* keys of the record's WebGL1 and WebGL2 contexts,
30
+ * claimed only from a readout of `renderer` (readoutNames).
31
+ */
32
+ export declare function webglIdentity(fingerprint: Record<string, any>, renderer: unknown): Record<string, unknown>;
33
+ /**
34
+ * Every [vendor, renderer] fpgen has seen Chrome report on this OS, that an
35
+ * identity may claim.
36
+ *
37
+ * A GPU outside this set has no recorded device behind it, so an identity
38
+ * naming it could only borrow another machine's limits, screen and fonts.
39
+ */
40
+ export declare function chromeGpus(targetOs: string): Array<[string, string]>;
41
+ export {};
@@ -0,0 +1,198 @@
1
+ /**
2
+ * WebGL identities, from the Chrome devices fpgen has recorded.
3
+ *
4
+ * Chrome reports its GPU through ANGLE, and the renderer string names the
5
+ * ANGLE backend: Direct3D 11 on Windows, Metal (or OpenGL 4.1 on older Macs)
6
+ * on macOS, desktop OpenGL or Vulkan on Linux. A renderer whose backend the
7
+ * claimed OS never uses is a contradiction a page reads in one call, so every
8
+ * identity's renderer is checked against its OS (backendMatchesOs).
9
+ *
10
+ * A device's WebGL identity is more than its renderer string: the limits, the
11
+ * shader precision table and the extension lists are the backend's signature
12
+ * (Direct3D 11 reports ALIASED_LINE_WIDTH_RANGE [1, 1] and MAX_VIEWPORT_DIMS
13
+ * [32767, 32767] whatever the card), so they are claimed from the same record
14
+ * (webglIdentity). The browser answers them before its own lookup
15
+ * (browser/patches/0007-webgl-spoofing.patch); an extension it lacks cannot be
16
+ * added, only one the claimed device lacks hidden.
17
+ *
18
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/webgl.py.
19
+ */
20
+ import { trace } from "fpgen-js";
21
+ import { FPGEN_OS, isSoftwareRenderer, OS_KEYS } from "./fingerprints.js";
22
+ import { isPlainObject, KeyError, PyFloat, pyStrRepr } from "./pycompat.js";
23
+ /** The ANGLE backends Chrome uses on each OS, as they appear in the renderer. */
24
+ const BACKENDS = {
25
+ win: /Direct3D11|D3D11/i,
26
+ mac: /Metal|OpenGL 4\.1/i,
27
+ lin: /OpenGL|Mesa|Vulkan/i,
28
+ };
29
+ function osKey(targetOs) {
30
+ const lowered = targetOs.toLowerCase();
31
+ return Object.hasOwn(OS_KEYS, lowered) ? OS_KEYS[lowered] : lowered;
32
+ }
33
+ function backend(targetOs) {
34
+ const key = osKey(targetOs);
35
+ if (!Object.hasOwn(BACKENDS, key))
36
+ throw new KeyError(pyStrRepr(key));
37
+ return BACKENDS[key];
38
+ }
39
+ /**
40
+ * Whether Chrome on `targetOs` ('win', 'mac', 'lin', or the OS name) can
41
+ * report this renderer.
42
+ */
43
+ export function backendMatchesOs(renderer, targetOs) {
44
+ if (!renderer)
45
+ return true;
46
+ return backend(targetOs).test(renderer);
47
+ }
48
+ /**
49
+ * Whether an identity may claim fpgen's `gpu` value: a real device, on a
50
+ * backend the OS uses.
51
+ */
52
+ export function usableGpu(gpu, targetOs) {
53
+ if (!isPlainObject(gpu) || !gpu.renderer || !gpu.vendor)
54
+ return false;
55
+ if (isSoftwareRenderer(gpu.renderer))
56
+ return false;
57
+ return (targetOs === null ||
58
+ targetOs === undefined ||
59
+ backendMatchesOs(gpu.renderer, targetOs));
60
+ }
61
+ // The GL spec's implementation-dependent values: fixed per device, never state
62
+ // a page sets. Extension limits are left out, because the browser answers a
63
+ // configured pname whether or not its extension is enabled.
64
+ const LIMIT_PREFIXES = ["MAX_", "MIN_", "ALIASED_"];
65
+ const LIMITS = new Set(["SUBPIXEL_BITS", "UNIFORM_BUFFER_OFFSET_ALIGNMENT"]);
66
+ const EXTENSION_SUFFIXES = ["_EXT", "_WEBGL", "_OES"];
67
+ function isNumber(value) {
68
+ return (typeof value === "number" ||
69
+ typeof value === "bigint" ||
70
+ value instanceof PyFloat);
71
+ }
72
+ /** The value of one recorded parameter if it is a device limit, or null. */
73
+ function limit(entry) {
74
+ if (!isPlainObject(entry))
75
+ return null;
76
+ const name = entry.name ?? "";
77
+ if (typeof name !== "string" ||
78
+ EXTENSION_SUFFIXES.some((suffix) => name.endsWith(suffix)) ||
79
+ !(LIMIT_PREFIXES.some((prefix) => name.startsWith(prefix)) ||
80
+ LIMITS.has(name))) {
81
+ return null;
82
+ }
83
+ const value = entry.value;
84
+ if (entry.type === "Number" && isNumber(value)) {
85
+ // fpgen-js parses an integer beyond 2**53 (MAX_SERVER_WAIT_TIMEOUT) into
86
+ // a double; Python's fpgen keeps the recorded digits as an int.
87
+ return typeof value === "number" &&
88
+ Number.isInteger(value) &&
89
+ !Number.isSafeInteger(value)
90
+ ? BigInt(String(value))
91
+ : value;
92
+ }
93
+ if ((entry.type === "Float32Array" || entry.type === "Int32Array") &&
94
+ Array.isArray(value) &&
95
+ value.length >= 2 &&
96
+ value.length <= 4 &&
97
+ value.every(isNumber)) {
98
+ return [...value];
99
+ }
100
+ return null;
101
+ }
102
+ /** The device limits one recorded context reports: pname -> value. */
103
+ export function webglParameters(context) {
104
+ const params = isPlainObject(context) ? context.params : null;
105
+ if (!isPlainObject(params))
106
+ return {};
107
+ const result = {};
108
+ for (const [pname, entry] of Object.entries(params)) {
109
+ const value = limit(entry);
110
+ if (value !== null && /^\d+$/.test(pname))
111
+ result[pname] = value;
112
+ }
113
+ return result;
114
+ }
115
+ /** A recorded getShaderPrecisionFormat table, keyed "<shaderType>,<precisionType>". */
116
+ export function shaderPrecisionFormats(context) {
117
+ const formats = isPlainObject(context)
118
+ ? context.shaderPrecisionFormats
119
+ : null;
120
+ const table = {};
121
+ for (const item of Array.isArray(formats) ? formats : []) {
122
+ const spf = isPlainObject(item) ? item.shaderPrecisionFormat : null;
123
+ if (isPlainObject(spf) &&
124
+ ["rangeMin", "rangeMax", "precision"].every((k) => Number.isInteger(spf[k]))) {
125
+ table[`${item.shaderType},${item.precisionType}`] = {
126
+ rangeMin: spf.rangeMin,
127
+ rangeMax: spf.rangeMax,
128
+ precision: spf.precision,
129
+ };
130
+ }
131
+ }
132
+ return table;
133
+ }
134
+ /**
135
+ * Whether the record's WebGL1 and WebGL2 readouts are both of `renderer`.
136
+ * fpgen occasionally pairs one device's GPU with another's readout, or with
137
+ * none; an identity drawn from such a record has no limits for its renderer.
138
+ */
139
+ export function readoutNames(fingerprint, renderer) {
140
+ return (Boolean(renderer) &&
141
+ [fingerprint.webgl, fingerprint.webgl2].every((r) => isPlainObject(r) && r.renderer === renderer));
142
+ }
143
+ /**
144
+ * The webGl:* and webGl2:* keys of the record's WebGL1 and WebGL2 contexts,
145
+ * claimed only from a readout of `renderer` (readoutNames).
146
+ */
147
+ export function webglIdentity(fingerprint, renderer) {
148
+ if (!readoutNames(fingerprint, renderer))
149
+ return {};
150
+ const { webgl, webgl2 } = fingerprint;
151
+ const claimed = {
152
+ "webGl:parameters": webglParameters(webgl),
153
+ "webGl2:parameters": webglParameters(webgl2),
154
+ "webGl:shaderPrecisionFormats": shaderPrecisionFormats(webgl),
155
+ "webGl2:shaderPrecisionFormats": shaderPrecisionFormats(webgl2),
156
+ "webGl:supportedExtensions": webgl.supportedExtensions,
157
+ "webGl2:supportedExtensions": webgl2.supportedExtensions,
158
+ };
159
+ return Object.fromEntries(Object.entries(claimed).filter(([, value]) => Array.isArray(value)
160
+ ? value.length > 0
161
+ : isPlainObject(value) && Object.keys(value).length > 0));
162
+ }
163
+ const traceCache = new Map();
164
+ function traceGpus(targetOs) {
165
+ let results = traceCache.get(targetOs);
166
+ if (!results) {
167
+ if (!Object.hasOwn(FPGEN_OS, targetOs))
168
+ throw new KeyError(pyStrRepr(targetOs));
169
+ results = trace("gpu", {
170
+ browser: "Chrome",
171
+ os: FPGEN_OS[targetOs],
172
+ });
173
+ traceCache.set(targetOs, results);
174
+ }
175
+ return results;
176
+ }
177
+ /**
178
+ * Every [vendor, renderer] fpgen has seen Chrome report on this OS, that an
179
+ * identity may claim.
180
+ *
181
+ * A GPU outside this set has no recorded device behind it, so an identity
182
+ * naming it could only borrow another machine's limits, screen and fonts.
183
+ */
184
+ export function chromeGpus(targetOs) {
185
+ const key = osKey(targetOs);
186
+ const seen = new Set();
187
+ const pairs = [];
188
+ for (const result of traceGpus(key)) {
189
+ if (!usableGpu(result.value, key))
190
+ continue;
191
+ const id = JSON.stringify([result.value.vendor, result.value.renderer]);
192
+ if (seen.has(id))
193
+ continue;
194
+ seen.add(id);
195
+ pairs.push([result.value.vendor, result.value.renderer]);
196
+ }
197
+ return pairs;
198
+ }
package/dist/data.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare const DATA_FILES: readonly string[];
2
- /** dist/data-files/ in a built package, else python/src/camoucore/ itself. */
2
+ /** dist/data-files/ in a built package, else python/camoucore/src/camoucore/ itself. */
3
3
  export declare const LOCAL_DATA: string;
4
4
  /** A data file, parsed as YAML or JSON by its extension. */
5
5
  export declare function loadDataFile<T = any>(file: string): T;
package/dist/data.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The data files camoucore ships. They live in python/src/camoucore/, the one
2
+ * The data files camoucore ships. They live in python/camoucore/src/camoucore/, the one
3
3
  * copy in the repository; `pnpm build` copies them into dist/data-files/.
4
4
  */
5
5
  import * as fs from "node:fs";
@@ -12,10 +12,10 @@ export const DATA_FILES = [
12
12
  "territoryInfo.xml",
13
13
  "warnings.yml",
14
14
  ];
15
- /** dist/data-files/ in a built package, else python/src/camoucore/ itself. */
15
+ /** dist/data-files/ in a built package, else python/camoucore/src/camoucore/ itself. */
16
16
  export const LOCAL_DATA = fs.existsSync(path.join(import.meta.dirname, "data-files"))
17
17
  ? path.join(import.meta.dirname, "data-files")
18
- : path.resolve(import.meta.dirname, "..", "..", "python", "src", "camoucore");
18
+ : path.resolve(import.meta.dirname, "..", "..", "..", "python", "camoucore", "src", "camoucore");
19
19
  /** A data file, parsed as YAML or JSON by its extension. */
20
20
  export function loadDataFile(file) {
21
21
  const text = fs.readFileSync(path.join(LOCAL_DATA, file), "utf-8");
package/dist/download.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Downloads, checksums and archives, for every launcher's browser and the
3
3
  * GeoIP databases.
4
4
  *
5
- * TypeScript twin of python/src/camoucore/download.py.
5
+ * TypeScript twin of python/camoucore/src/camoucore/download.py.
6
6
  */
7
7
  import { createHash } from "node:crypto";
8
8
  import { once } from "node:events";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TypeScript twin of python/src/camoucore/exceptions.py.
2
+ * TypeScript twin of python/camoucore/src/camoucore/exceptions.py.
3
3
  */
4
4
  export declare class CorruptedDownload extends Error {
5
5
  constructor(message?: string);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TypeScript twin of python/src/camoucore/exceptions.py.
2
+ * TypeScript twin of python/camoucore/src/camoucore/exceptions.py.
3
3
  */
4
4
  export class CorruptedDownload extends Error {
5
5
  constructor(message) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Helpers to fetch geolocation, timezone, and locale data given an IP.
3
3
  *
4
- * TypeScript twin of python/src/camoucore/geolocation.py. The on-disk layout
4
+ * TypeScript twin of python/camoucore/src/camoucore/geolocation.py. The on-disk layout
5
5
  * (geoip/mmdb/<name>-<ipver>.mmdb and geoip/config.yml under the camoucore
6
6
  * cache dir) is the Python package's, so both launchers share one database.
7
7
  */
package/dist/host.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The host this process runs on, in the names release assets use.
3
3
  *
4
- * TypeScript twin of python/src/camoucore/host.py.
4
+ * TypeScript twin of python/camoucore/src/camoucore/host.py.
5
5
  */
6
6
  import * as os from "node:os";
7
7
  import * as path from "node:path";
package/dist/ip.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Helpers to find the user's public IP address for geolocation.
3
3
  *
4
- * TypeScript twin of python/src/camoucore/ip.py. Python sends the lookup with
4
+ * TypeScript twin of python/camoucore/src/camoucore/ip.py. Python sends the lookup with
5
5
  * `requests`; here it goes through node:https, tunnelled by hand through an
6
6
  * HTTP(S) CONNECT or SOCKS5 proxy, so the package needs no HTTP client.
7
7
  */
package/dist/locales.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Locale data structures, validation and the statistical locale selector.
3
3
  *
4
- * TypeScript twin of python/src/camoucore/locales.py.
4
+ * TypeScript twin of python/camoucore/src/camoucore/locales.py.
5
5
  */
6
6
  import * as fs from "node:fs";
7
7
  import * as path from "node:path";
@@ -0,0 +1,15 @@
1
+ export interface ServeOptions {
2
+ /**
3
+ * The launcher module to drive (a specifier or file URL). Without it the
4
+ * first positional argument names it.
5
+ */
6
+ launcher?: string;
7
+ /** The command as the user typed it, for the usage line. */
8
+ program?: string;
9
+ }
10
+ /**
11
+ * Serve a launcher's browser over MCP on stdio until the client goes away.
12
+ * Bad arguments print the usage and exit 2. Call it before the launcher is
13
+ * imported anywhere: launchers print as they load, and stdout is the protocol.
14
+ */
15
+ export declare function serve(argv: string[], options?: ServeOptions): Promise<void>;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * The MCP server as a command: serve(argv, options) runs the stdio server
3
+ * for one launcher. Each launcher's bin runs it as `<launcher> mcp`
4
+ * (src/<launcher>/cli.ts); main.ts runs it for any launcher module named on
5
+ * the command line.
6
+ */
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { Writable } from "node:stream";
10
+ import { parseArgs } from "node:util";
11
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
+ import { Secrets } from "./secrets.js";
13
+ import { createServer, loadLauncher } from "./server.js";
14
+ /**
15
+ * Serve a launcher's browser over MCP on stdio until the client goes away.
16
+ * Bad arguments print the usage and exit 2. Call it before the launcher is
17
+ * imported anywhere: launchers print as they load, and stdout is the protocol.
18
+ */
19
+ export async function serve(argv, options = {}) {
20
+ // stdout is the protocol, and launchers print to it, so everything but the
21
+ // transport goes to stderr. This comes before the launcher is imported, since
22
+ // importing it can print too.
23
+ const protocolWrite = process.stdout.write.bind(process.stdout);
24
+ process.stdout.write = process.stderr.write.bind(process.stderr);
25
+ const protocolStream = new Writable({
26
+ write: (chunk, encoding, done) => void protocolWrite(chunk, encoding, done),
27
+ });
28
+ const program = options.program ?? "camoucore-mcp";
29
+ const flags = "[--secrets <file>] [--allowed-domains <pattern,...>] [--profile <dir>] [--uploads <dir>]";
30
+ const USAGE = (options.launcher
31
+ ? `usage: ${program} ${flags}\n`
32
+ : `usage: ${program} <launcher> ${flags}\n` +
33
+ " <launcher> the launcher module to drive: camoucore/camoufox or camoucore/camouwolf\n") +
34
+ " --profile your own browser profile, which session_open { profile: true } runs a copy of\n" +
35
+ " --uploads the one directory upload_file may attach files from";
36
+ let parsed;
37
+ function parse() {
38
+ return parseArgs({
39
+ args: argv,
40
+ allowPositionals: true,
41
+ options: {
42
+ secrets: { type: "string" },
43
+ "allowed-domains": { type: "string" },
44
+ profile: { type: "string" },
45
+ uploads: { type: "string" },
46
+ },
47
+ });
48
+ }
49
+ try {
50
+ parsed = parse();
51
+ }
52
+ catch (error) {
53
+ console.error(`${error.message}\n${USAGE}`);
54
+ process.exit(2);
55
+ }
56
+ const positionals = options.launcher
57
+ ? [options.launcher, ...parsed.positionals]
58
+ : parsed.positionals;
59
+ const [specifier] = positionals;
60
+ if (!specifier || positionals.length > 1) {
61
+ console.error(USAGE);
62
+ process.exit(2);
63
+ }
64
+ // Read before anything launches, so a bad file stops the server at start.
65
+ const secrets = parsed.values.secrets
66
+ ? Secrets.load(parsed.values.secrets)
67
+ : undefined;
68
+ const profile = parsed.values.profile
69
+ ? path.resolve(parsed.values.profile)
70
+ : undefined;
71
+ if (profile &&
72
+ !fs.statSync(profile, { throwIfNoEntry: false })?.isDirectory()) {
73
+ console.error(`--profile ${profile} is not a directory.`);
74
+ process.exit(2);
75
+ }
76
+ const uploads = parsed.values.uploads
77
+ ? path.resolve(parsed.values.uploads)
78
+ : undefined;
79
+ if (uploads &&
80
+ !fs.statSync(uploads, { throwIfNoEntry: false })?.isDirectory()) {
81
+ console.error(`--uploads ${uploads} is not a directory.`);
82
+ process.exit(2);
83
+ }
84
+ const allowedDomains = parsed.values["allowed-domains"]
85
+ ?.split(",")
86
+ .map((pattern) => pattern.trim())
87
+ .filter(Boolean);
88
+ const { launcher, browserType } = await loadLauncher(specifier);
89
+ const { server, closeAll } = createServer(launcher, browserType, {
90
+ secrets,
91
+ allowedDomains,
92
+ profile,
93
+ uploads,
94
+ });
95
+ /** A client going away must not leave its browsers running. */
96
+ let shuttingDown = false;
97
+ async function shutdown() {
98
+ if (shuttingDown)
99
+ return;
100
+ shuttingDown = true;
101
+ await closeAll();
102
+ process.exit(0);
103
+ }
104
+ process.on("SIGINT", shutdown);
105
+ process.on("SIGTERM", shutdown);
106
+ process.stdin.on("close", shutdown);
107
+ await server.connect(new StdioServerTransport(process.stdin, protocolStream));
108
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * camoucore/mcp: an MCP server that drives a launcher's browser. serve() is
3
+ * the stdio server as each launcher's `mcp` command runs it; createServer()
4
+ * and loadLauncher() build one for a transport of your own.
5
+ */
6
+ export { type ServeOptions, serve } from "./cli.js";
7
+ export { Secrets } from "./secrets.js";
8
+ export { createServer, type Launcher, loadLauncher, type ServerOptions, } from "./server.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * camoucore/mcp: an MCP server that drives a launcher's browser. serve() is
3
+ * the stdio server as each launcher's `mcp` command runs it; createServer()
4
+ * and loadLauncher() build one for a transport of your own.
5
+ */
6
+ export { serve } from "./cli.js";
7
+ export { Secrets } from "./secrets.js";
8
+ export { createServer, loadLauncher, } from "./server.js";
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `node dist/mcp/main.js <launcher> [options]`: the MCP server for any
4
+ * launcher module, named on the command line. Users run it through their
5
+ * launcher instead (`npx camoufox mcp`).
6
+ */
7
+ import { serve } from "./cli.js";
8
+ await serve(process.argv.slice(2));
@@ -0,0 +1,50 @@
1
+ /**
2
+ * A URL pattern: `[scheme://]host[:port][/path]`. The scheme is `https`,
3
+ * `http` or `http*` (both), and `https` when left out. `*.example.com` is
4
+ * example.com and its subdomains. A port must match when given. A path is a
5
+ * glob on the URL's path, where `*` is any run of characters.
6
+ */
7
+ export declare class UrlPattern {
8
+ readonly source: string;
9
+ private readonly schemes;
10
+ private readonly host;
11
+ private readonly subdomains;
12
+ private readonly port;
13
+ private readonly path;
14
+ constructor(source: string);
15
+ matches(url: string): boolean;
16
+ }
17
+ /** RFC 6238 with the defaults every authenticator app uses: SHA-1, 30 s, 6 digits. */
18
+ export declare function totp(seed: string, at?: number): string;
19
+ type Value = string | {
20
+ totp: string;
21
+ };
22
+ export declare class Secrets {
23
+ private readonly entries;
24
+ /** Each literal value with its name, longest first, for redaction. */
25
+ private readonly literals;
26
+ /**
27
+ * `byPattern` maps a URL pattern to that domain's secrets: a name to its
28
+ * value, or to `{ totp: "<base32 seed>" }` for a one-time code.
29
+ */
30
+ constructor(byPattern: Record<string, Record<string, Value>>);
31
+ /** Reads a JSON secrets file that only its owner can read. */
32
+ static load(file: string): Secrets;
33
+ get empty(): boolean;
34
+ /** Every pattern and the names under it; neither is secret. */
35
+ names(): Record<string, string[]>;
36
+ /** The names usable on a page at `url`. */
37
+ namesFor(url: string): string[];
38
+ /** The text to type for `name` in a frame at `url`; refuses anywhere else. */
39
+ valueFor(name: string, url: string): string;
40
+ /** Whether `text` holds any secret value, in any case. */
41
+ contains(text: string): boolean;
42
+ /** `text` with every secret value, in every form, as `<secret:name>`. */
43
+ redact(text: string): string;
44
+ }
45
+ /**
46
+ * `text` with `value`, and the escaped and encoded forms it takes in markup,
47
+ * JSON, URLs and headers, in any case, replaced by `replacement`.
48
+ */
49
+ export declare function redactValue(text: string, value: string, replacement: string): string;
50
+ export {};