camoucore 0.3.0 → 0.6.1

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 (168) 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/browser-pin.json +7 -0
  19. package/dist/camoufox/data-files/essential-fonts.json +5 -0
  20. package/dist/camoufox/data-files/fingerprint-presets-v150.json +14544 -0
  21. package/dist/camoufox/data-files/fingerprint-presets.json +5192 -0
  22. package/dist/camoufox/data-files/font-bases.json +1887 -0
  23. package/dist/camoufox/data-files/font-groups.json +716 -0
  24. package/dist/camoufox/data-files/fonts.json +240 -0
  25. package/dist/camoufox/data-files/fpgen.yml +44 -0
  26. package/dist/camoufox/data-files/launcher-constants.json +66 -0
  27. package/dist/camoufox/data-files/media-devices.json +148 -0
  28. package/dist/camoufox/data-files/repos.yml +40 -0
  29. package/dist/camoufox/data-files/voice-manifests.json +1864 -0
  30. package/dist/camoufox/data-files/voice-uris.json +188 -0
  31. package/dist/camoufox/data-files/warnings.yml +132 -0
  32. package/dist/camoufox/display_profile.d.ts +17 -0
  33. package/dist/camoufox/display_profile.js +72 -0
  34. package/dist/camoufox/driver_defaults.d.ts +25 -0
  35. package/dist/camoufox/driver_defaults.js +114 -0
  36. package/dist/camoufox/exceptions.d.ts +78 -0
  37. package/dist/camoufox/exceptions.js +135 -0
  38. package/dist/camoufox/fingerprints.d.ts +341 -0
  39. package/dist/camoufox/fingerprints.js +1682 -0
  40. package/dist/camoufox/gpudisplay.d.ts +158 -0
  41. package/dist/camoufox/gpudisplay.js +695 -0
  42. package/dist/camoufox/host_rendering.d.ts +38 -0
  43. package/dist/camoufox/host_rendering.js +180 -0
  44. package/dist/camoufox/humanize.d.ts +89 -0
  45. package/dist/camoufox/humanize.js +143 -0
  46. package/dist/camoufox/index.d.ts +21 -0
  47. package/dist/camoufox/index.js +21 -0
  48. package/dist/camoufox/ip.d.ts +45 -0
  49. package/dist/camoufox/ip.js +114 -0
  50. package/dist/camoufox/multiversion.d.ts +131 -0
  51. package/dist/camoufox/multiversion.js +489 -0
  52. package/dist/camoufox/node-floor.d.ts +5 -0
  53. package/dist/camoufox/node-floor.js +17 -0
  54. package/dist/camoufox/paths.d.ts +45 -0
  55. package/dist/camoufox/paths.js +59 -0
  56. package/dist/camoufox/pkgman.d.ts +331 -0
  57. package/dist/camoufox/pkgman.js +972 -0
  58. package/dist/camoufox/product.d.ts +8 -0
  59. package/dist/camoufox/product.js +8 -0
  60. package/dist/camoufox/pycompat.d.ts +97 -0
  61. package/dist/camoufox/pycompat.js +458 -0
  62. package/dist/camoufox/server.d.ts +36 -0
  63. package/dist/camoufox/server.js +82 -0
  64. package/dist/camoufox/sync_api.d.ts +77 -0
  65. package/dist/camoufox/sync_api.js +194 -0
  66. package/dist/camoufox/utils.d.ts +515 -0
  67. package/dist/camoufox/utils.js +1995 -0
  68. package/dist/camoufox/warnings.d.ts +16 -0
  69. package/dist/camoufox/warnings.js +65 -0
  70. package/dist/camoufox/webgl.d.ts +52 -0
  71. package/dist/camoufox/webgl.js +264 -0
  72. package/dist/camouwolf/__main__.d.ts +10 -0
  73. package/dist/camouwolf/__main__.js +1180 -0
  74. package/dist/camouwolf/__version__.d.ts +31 -0
  75. package/dist/camouwolf/__version__.js +32 -0
  76. package/dist/camouwolf/_humanize_playwright.d.ts +53 -0
  77. package/dist/camouwolf/_humanize_playwright.js +427 -0
  78. package/dist/camouwolf/addons.d.ts +42 -0
  79. package/dist/camouwolf/addons.js +113 -0
  80. package/dist/camouwolf/async_api.d.ts +9 -0
  81. package/dist/camouwolf/async_api.js +9 -0
  82. package/dist/camouwolf/browser-pin.d.ts +46 -0
  83. package/dist/camouwolf/browser-pin.js +96 -0
  84. package/dist/camouwolf/cli.d.ts +7 -0
  85. package/dist/camouwolf/cli.js +20 -0
  86. package/dist/camouwolf/clienthints.d.ts +61 -0
  87. package/dist/camouwolf/clienthints.js +176 -0
  88. package/dist/camouwolf/coherence.d.ts +152 -0
  89. package/dist/camouwolf/coherence.js +554 -0
  90. package/dist/camouwolf/data-files/browser-pin.json +7 -0
  91. package/dist/camouwolf/data-files/camouwolf.defaults.json +118 -0
  92. package/dist/camouwolf/data-files/data/bundle-fonts.json +1983 -0
  93. package/dist/camouwolf/data-files/data/chrome-languages.json +517 -0
  94. package/dist/camouwolf/data-files/data/properties.json +321 -0
  95. package/dist/camouwolf/data-files/data/system-colors.json +35 -0
  96. package/dist/camouwolf/data-files/data/ubo.json +6 -0
  97. package/dist/camouwolf/data-files/fpgen.yml +41 -0
  98. package/dist/camouwolf/data-files/launcher-constants.json +26 -0
  99. package/dist/camouwolf/data-files/repos.yml +23 -0
  100. package/dist/camouwolf/data-files/warnings.yml +96 -0
  101. package/dist/camouwolf/driver_defaults.d.ts +25 -0
  102. package/dist/camouwolf/driver_defaults.js +114 -0
  103. package/dist/camouwolf/exceptions.d.ts +95 -0
  104. package/dist/camouwolf/exceptions.js +150 -0
  105. package/dist/camouwolf/fingerprints.d.ts +227 -0
  106. package/dist/camouwolf/fingerprints.js +753 -0
  107. package/dist/camouwolf/gpudisplay.d.ts +171 -0
  108. package/dist/camouwolf/gpudisplay.js +711 -0
  109. package/dist/camouwolf/host_rendering.d.ts +18 -0
  110. package/dist/camouwolf/host_rendering.js +114 -0
  111. package/dist/camouwolf/humanize.d.ts +84 -0
  112. package/dist/camouwolf/humanize.js +128 -0
  113. package/dist/camouwolf/index.d.ts +22 -0
  114. package/dist/camouwolf/index.js +21 -0
  115. package/dist/camouwolf/multiversion.d.ts +131 -0
  116. package/dist/camouwolf/multiversion.js +491 -0
  117. package/dist/camouwolf/node-floor.d.ts +5 -0
  118. package/dist/camouwolf/node-floor.js +17 -0
  119. package/dist/camouwolf/paths.d.ts +34 -0
  120. package/dist/camouwolf/paths.js +58 -0
  121. package/dist/camouwolf/pkgman.d.ts +331 -0
  122. package/dist/camouwolf/pkgman.js +972 -0
  123. package/dist/camouwolf/product.d.ts +3 -0
  124. package/dist/camouwolf/product.js +3 -0
  125. package/dist/camouwolf/pycompat.d.ts +92 -0
  126. package/dist/camouwolf/pycompat.js +461 -0
  127. package/dist/camouwolf/server.d.ts +36 -0
  128. package/dist/camouwolf/server.js +81 -0
  129. package/dist/camouwolf/switches.d.ts +77 -0
  130. package/dist/camouwolf/switches.js +222 -0
  131. package/dist/camouwolf/sync_api.d.ts +84 -0
  132. package/dist/camouwolf/sync_api.js +173 -0
  133. package/dist/camouwolf/utils.d.ts +644 -0
  134. package/dist/camouwolf/utils.js +2057 -0
  135. package/dist/camouwolf/warnings.d.ts +14 -0
  136. package/dist/camouwolf/warnings.js +59 -0
  137. package/dist/camouwolf/webgl.d.ts +41 -0
  138. package/dist/camouwolf/webgl.js +198 -0
  139. package/dist/data.d.ts +1 -1
  140. package/dist/data.js +3 -3
  141. package/dist/download.js +1 -1
  142. package/dist/exceptions.d.ts +1 -1
  143. package/dist/exceptions.js +1 -1
  144. package/dist/geolocation.js +1 -1
  145. package/dist/host.js +1 -1
  146. package/dist/ip.js +1 -1
  147. package/dist/locales.js +1 -1
  148. package/dist/mcp/cli.d.ts +15 -0
  149. package/dist/mcp/cli.js +108 -0
  150. package/dist/mcp/index.d.ts +8 -0
  151. package/dist/mcp/index.js +8 -0
  152. package/dist/mcp/main.d.ts +2 -0
  153. package/dist/mcp/main.js +8 -0
  154. package/dist/mcp/secrets.d.ts +50 -0
  155. package/dist/mcp/secrets.js +193 -0
  156. package/dist/mcp/server.d.ts +48 -0
  157. package/dist/mcp/server.js +653 -0
  158. package/dist/mcp/tree.d.ts +10 -0
  159. package/dist/mcp/tree.js +36 -0
  160. package/dist/passthrough.d.ts +1 -1
  161. package/dist/product.js +1 -1
  162. package/dist/settings.js +1 -1
  163. package/dist/telemetry.d.ts +0 -1
  164. package/dist/telemetry.js +5 -4
  165. package/dist/virtdisplay.d.ts +1 -1
  166. package/dist/virtdisplay.js +1 -1
  167. package/dist/warnings.js +1 -1
  168. package/package.json +57 -13
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Extensions: the caller's unpacked ones, and the default uBlock Origin Lite.
3
+ *
4
+ * Chromium has no Manifest V2, so the default ad blocker is uBlock Origin Lite
5
+ * (Manifest V3) where Camoufox ships uBlock Origin. It is not vendored and not
6
+ * part of the browser bundle: `camouwolf fetch` downloads the release pinned in
7
+ * data/ubo.json (version, url, sha256) and unpacks it under the cache directory.
8
+ *
9
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/addons.py.
10
+ */
11
+ import * as fs from "node:fs";
12
+ import * as path from "node:path";
13
+ import { unzip, verifySha256, webdl } from "../download.js";
14
+ import { InvalidAddonPath } from "./exceptions.js";
15
+ import { INSTALL_DIR, loadDataFile } from "./paths.js";
16
+ import { loadWarnings, warn } from "./warnings.js";
17
+ /** Injection points (tests point the addon directory at a fixture). */
18
+ export const addonsDeps = {
19
+ addonsDir: path.join(INSTALL_DIR, "addons"),
20
+ };
21
+ /**
22
+ * Default addons. `camouwolf fetch` installs them, unpacked, under
23
+ * <cache>/addons/<name>/.
24
+ */
25
+ export const DefaultAddons = {
26
+ UBO: "UBO",
27
+ };
28
+ /** name -> the pin file under data/ that says what to download. */
29
+ export const ADDON_PINS = {
30
+ UBO: "ubo.json",
31
+ };
32
+ /** The pinned release of a default addon: name, version, url, sha256. */
33
+ export function addonPin(addon) {
34
+ return loadDataFile(`data/${ADDON_PINS[addon]}`);
35
+ }
36
+ /**
37
+ * Confirms that the addon paths are valid.
38
+ *
39
+ * Chromium treats an extension it cannot load as a warning on stderr and
40
+ * starts without it, so a mistyped path would otherwise launch a browser that
41
+ * just lacks the extension. --load-extension takes an unpacked directory; a
42
+ * .crx is ignored.
43
+ */
44
+ export function confirmPaths(paths) {
45
+ for (const addonPath of paths) {
46
+ if (!fs.existsSync(addonPath) || !fs.statSync(addonPath).isDirectory()) {
47
+ throw new InvalidAddonPath(`${addonPath} is not a directory. Addons are unpacked extension directories; ` +
48
+ "a .crx or .zip is not loaded.");
49
+ }
50
+ if (!fs.existsSync(path.join(addonPath, "manifest.json"))) {
51
+ throw new InvalidAddonPath(`${addonPath}: manifest.json is missing. Addon path must be a path to an extracted addon.`);
52
+ }
53
+ }
54
+ }
55
+ /** Returns the path a default addon is installed at. */
56
+ export function getAddonPath(addonName) {
57
+ return path.join(addonsDeps.addonsDir, addonName);
58
+ }
59
+ /** Whether the pinned version of a default addon is installed. */
60
+ export function isInstalled(addon) {
61
+ const dir = getAddonPath(addon);
62
+ let installed;
63
+ try {
64
+ installed = JSON.parse(fs.readFileSync(path.join(dir, ".camouwolf-addon.json"), "utf8"));
65
+ }
66
+ catch {
67
+ return false;
68
+ }
69
+ return (fs.existsSync(path.join(dir, "manifest.json")) &&
70
+ installed?.sha256 === addonPin(addon).sha256);
71
+ }
72
+ /** Download, verify and unpack every default addon. Returns their paths. */
73
+ export async function fetchDefaultAddons(replace = false) {
74
+ const paths = [];
75
+ for (const addon of Object.keys(DefaultAddons)) {
76
+ const dir = getAddonPath(addon);
77
+ if (replace || !isInstalled(addon)) {
78
+ const pin = addonPin(addon);
79
+ const archive = await webdl(pin.url, `Downloading ${pin.name} ${pin.version}`);
80
+ verifySha256(archive, pin.sha256, pin.name);
81
+ const staging = `${dir}.new`;
82
+ fs.rmSync(staging, { recursive: true, force: true });
83
+ fs.mkdirSync(staging, { recursive: true });
84
+ // Verified against the pinned sha256.
85
+ unzip(archive, staging, undefined, false);
86
+ fs.writeFileSync(path.join(staging, ".camouwolf-addon.json"), JSON.stringify({ version: pin.version, sha256: pin.sha256 }));
87
+ fs.rmSync(dir, { recursive: true, force: true });
88
+ fs.renameSync(staging, dir);
89
+ }
90
+ paths.push(dir);
91
+ }
92
+ return paths;
93
+ }
94
+ /**
95
+ * Adds the installed default addons, minus any specified in excludeList, to
96
+ * addonsList.
97
+ */
98
+ export function addDefaultAddons(addonsList, excludeList) {
99
+ for (const name of Object.keys(DefaultAddons)) {
100
+ if (excludeList?.includes(name))
101
+ continue;
102
+ const addonPath = getAddonPath(name);
103
+ // Installed by `camouwolf fetch`. Without it the browser still
104
+ // launches, but not as the browser asked for.
105
+ if (!fs.existsSync(path.join(addonPath, "manifest.json"))) {
106
+ warn(loadWarnings()
107
+ .addon_not_installed.replaceAll("{addon}", name)
108
+ .replaceAll("{path}", addonPath), "RuntimeWarning");
109
+ continue;
110
+ }
111
+ addonsList.push(addonPath);
112
+ }
113
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/async_api.py.
3
+ *
4
+ * playwright-core has a single, promise-based API, so the async entry points
5
+ * are the same functions as sync_api.ts under Python's async names. The
6
+ * behaviours async_api.py adds over sync_api.py (the per-driver pin lock) live
7
+ * there already.
8
+ */
9
+ export { Camouwolf as AsyncCamouwolf, NewBrowser as AsyncNewBrowser, type NewBrowserOptions, NewContext as AsyncNewContext, type NewContextOptions, } from "./sync_api.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/async_api.py.
3
+ *
4
+ * playwright-core has a single, promise-based API, so the async entry points
5
+ * are the same functions as sync_api.ts under Python's async names. The
6
+ * behaviours async_api.py adds over sync_api.py (the per-driver pin lock) live
7
+ * there already.
8
+ */
9
+ export { Camouwolf as AsyncCamouwolf, NewBrowser as AsyncNewBrowser, NewContext as AsyncNewContext, } from "./sync_api.js";
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The browser build this copy of the library was released with.
3
+ *
4
+ * Twin of python/camoucore/src/camoucore/camouwolf/browser_pin.py, reading the same
5
+ * `browser-pin.json` (a DATA_FILES entry). Every published package is stamped
6
+ * with the one browser release built from the same sources; by default the
7
+ * library fetches and launches exactly that build. An explicit user choice
8
+ * (`camouwolf set ...`) is kept, with a warning at launch. A development
9
+ * checkout carries `{}` and pins nothing.
10
+ *
11
+ * The browser repository's pin wins: its `camouwolf` npm package depends on
12
+ * exactly one release of this driver and ships `camouwolf_pin/browser-pin.json`
13
+ * (exported at that subpath), naming the browser released with it. Without
14
+ * that package the driver reads its own file, which camoucore's release
15
+ * stamps with the browser its CI tested.
16
+ */
17
+ /** Test seam, like pkgmanDeps: where the pin is read from. */
18
+ export declare const browserPinDeps: {
19
+ /** The driver's own pin, read without the browser repository's package. */
20
+ file: string;
21
+ /** Where the browser repository's package is resolved from. */
22
+ resolveFrom: string;
23
+ };
24
+ /** The browser repository's pin when its package is installed, else the driver's. */
25
+ export declare function pinFile(): string;
26
+ export interface BrowserPin {
27
+ tag: string;
28
+ repo: string;
29
+ repoName: string;
30
+ version: string;
31
+ build: string;
32
+ }
33
+ /** `<chromium version>-<release>`, the form `camouwolf set` and the cache use. */
34
+ export declare function pinSpec(pin: BrowserPin): string;
35
+ /** The stamped pin (pinFile()), or null for an unpinned (development) copy. */
36
+ export declare function loadPin(file?: string): BrowserPin | null;
37
+ /** The package pin, unless the user explicitly chose otherwise. */
38
+ export declare function effectivePin(config: {
39
+ channel?: string;
40
+ pinned?: string;
41
+ }): BrowserPin | null;
42
+ export declare function pinMatches(pin: BrowserPin, repoName: string, version: string, build: string): boolean;
43
+ /** Warn once when an explicitly chosen build is not the one this library pairs with. */
44
+ export declare function warnIfUnpaired(repoName: string, version: string, build: string): void;
45
+ /** Test hook: forget that the warning was already issued. */
46
+ export declare function resetUnpairedWarning(): void;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The browser build this copy of the library was released with.
3
+ *
4
+ * Twin of python/camoucore/src/camoucore/camouwolf/browser_pin.py, reading the same
5
+ * `browser-pin.json` (a DATA_FILES entry). Every published package is stamped
6
+ * with the one browser release built from the same sources; by default the
7
+ * library fetches and launches exactly that build. An explicit user choice
8
+ * (`camouwolf set ...`) is kept, with a warning at launch. A development
9
+ * checkout carries `{}` and pins nothing.
10
+ *
11
+ * The browser repository's pin wins: its `camouwolf` npm package depends on
12
+ * exactly one release of this driver and ships `camouwolf_pin/browser-pin.json`
13
+ * (exported at that subpath), naming the browser released with it. Without
14
+ * that package the driver reads its own file, which camoucore's release
15
+ * stamps with the browser its CI tested.
16
+ */
17
+ import * as fs from "node:fs";
18
+ import { createRequire } from "node:module";
19
+ import * as path from "node:path";
20
+ import { LOCAL_DATA } from "./paths.js";
21
+ import { warn } from "./warnings.js";
22
+ /** Test seam, like pkgmanDeps: where the pin is read from. */
23
+ export const browserPinDeps = {
24
+ /** The driver's own pin, read without the browser repository's package. */
25
+ file: path.join(LOCAL_DATA, "browser-pin.json"),
26
+ /** Where the browser repository's package is resolved from. */
27
+ resolveFrom: import.meta.url,
28
+ };
29
+ /** The browser repository's pin, in its `camouwolf` package. */
30
+ const WRAPPER_PIN = "camouwolf/camouwolf_pin/browser-pin.json";
31
+ /** The browser repository's pin when its package is installed, else the driver's. */
32
+ export function pinFile() {
33
+ try {
34
+ const wrapper = createRequire(browserPinDeps.resolveFrom).resolve(WRAPPER_PIN);
35
+ if (fs.statSync(wrapper).isFile())
36
+ return wrapper;
37
+ }
38
+ catch {
39
+ // Not installed, or it does not export the pin: the driver's own.
40
+ }
41
+ return browserPinDeps.file;
42
+ }
43
+ /** `<chromium version>-<release>`, the form `camouwolf set` and the cache use. */
44
+ export function pinSpec(pin) {
45
+ return `${pin.version}-${pin.build}`;
46
+ }
47
+ /** The stamped pin (pinFile()), or null for an unpinned (development) copy. */
48
+ export function loadPin(file = pinFile()) {
49
+ let data;
50
+ try {
51
+ data = JSON.parse(fs.readFileSync(file, "utf-8"));
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ if (!data?.tag)
57
+ return null;
58
+ return {
59
+ tag: data.tag,
60
+ repo: String(data.repo),
61
+ repoName: String(data.repo_name).toLowerCase(),
62
+ version: String(data.version),
63
+ build: String(data.build),
64
+ };
65
+ }
66
+ /** Whether the user chose a channel or a build themselves. */
67
+ function isExplicitChoice(config) {
68
+ return Boolean(config.channel || config.pinned);
69
+ }
70
+ /** The package pin, unless the user explicitly chose otherwise. */
71
+ export function effectivePin(config) {
72
+ const pin = loadPin();
73
+ return pin && !isExplicitChoice(config) ? pin : null;
74
+ }
75
+ export function pinMatches(pin, repoName, version, build) {
76
+ return (repoName.toLowerCase() === pin.repoName &&
77
+ version === pin.version &&
78
+ build === pin.build);
79
+ }
80
+ let warned = false;
81
+ /** Warn once when an explicitly chosen build is not the one this library pairs with. */
82
+ export function warnIfUnpaired(repoName, version, build) {
83
+ const pin = loadPin();
84
+ if (warned || pin === null || pinMatches(pin, repoName, version, build)) {
85
+ return;
86
+ }
87
+ warned = true;
88
+ warn(`Launching ${repoName.toLowerCase()} ${version}-${build}, which you selected explicitly. ` +
89
+ `This camouwolf release was built and tested with ${pin.repoName} ${pinSpec(pin)} ` +
90
+ `(${pin.tag}); other builds may not be compatible. ` +
91
+ "Run `camouwolf set --release` to go back to the paired build.");
92
+ }
93
+ /** Test hook: forget that the warning was already issued. */
94
+ export function resetUnpairedWarning() {
95
+ warned = false;
96
+ }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `camouwolf` command, the bin of the browser repository's `camouwolf` package
4
+ * (RELEASING.md, "The wrapper packages"). `camouwolf mcp ...` serves the browser
5
+ * over MCP; everything else is the CLI in __main__.ts.
6
+ */
7
+ import "./node-floor.js";
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `camouwolf` command, the bin of the browser repository's `camouwolf` package
4
+ * (RELEASING.md, "The wrapper packages"). `camouwolf mcp ...` serves the browser
5
+ * over MCP; everything else is the CLI in __main__.ts.
6
+ */
7
+ // First: fail with the Node.js floor before any module needs it.
8
+ import "./node-floor.js";
9
+ if (process.argv[2] === "mcp") {
10
+ // Imported only here, and before the launcher: the server takes stdout for
11
+ // the protocol before anything the launcher loads can print to it.
12
+ const { serve } = await import("../mcp/cli.js");
13
+ await serve(process.argv.slice(3), {
14
+ launcher: new URL("./index.js", import.meta.url).href,
15
+ program: "camouwolf mcp",
16
+ });
17
+ }
18
+ else {
19
+ await import("./__main__.js");
20
+ }
@@ -0,0 +1,61 @@
1
+ export type OsKey = "win" | "mac" | "lin";
2
+ /** Sec-CH-UA-Platform values. */
3
+ export declare const CH_PLATFORM: Readonly<Record<OsKey, string>>;
4
+ /** navigator.platform values, which are not the Sec-CH-UA-Platform ones. */
5
+ export declare const NAV_PLATFORM: Readonly<Record<OsKey, string>>;
6
+ /**
7
+ * The parenthesised part of the UA string. Frozen by Chrome's UA reduction
8
+ * since M100: macOS stays "10_15_7", Windows "10.0; Win64; x64" from 10 through
9
+ * 11, Linux "X11; Linux x86_64". The real OS version is in
10
+ * Sec-CH-UA-Platform-Version.
11
+ */
12
+ export declare const UA_PLATFORM_TOKEN: Readonly<Record<OsKey, string>>;
13
+ /**
14
+ * Sec-CH-UA-Platform-Version values Chrome reports, per OS. assertCoherent
15
+ * refuses any other.
16
+ * win: the UniversalApiContract ladder, not the marketing version: every
17
+ * Windows 10 reports 10.0.0, Windows 11 21H2/22H2 13.0.0/14.0.0/15.0.0,
18
+ * and 19.0.0 was measured on build 26200. 16-18 have not been seen on a
19
+ * shipping build, so they are absent.
20
+ * mac: macOS Sonoma and Sequoia point releases.
21
+ * lin: the kernel version.
22
+ */
23
+ export declare const PLATFORM_VERSIONS: Readonly<Record<OsKey, readonly string[]>>;
24
+ /** The version a generated identity claims when nothing names one. */
25
+ export declare const DEFAULT_PLATFORM_VERSION: Readonly<Record<OsKey, string>>;
26
+ export interface ChromeIdentity {
27
+ milestone: number;
28
+ fullVersion: string;
29
+ os: OsKey;
30
+ platformVersion?: string | null;
31
+ /** 'x86' | 'arm' */
32
+ arch?: string | null;
33
+ bitness?: string;
34
+ model?: string;
35
+ wow64?: boolean;
36
+ mobile?: boolean;
37
+ }
38
+ /** The OS a user agent claims, or null. */
39
+ export declare function uaOs(userAgent: string): OsKey | null;
40
+ export declare function buildUserAgent(identity: ChromeIdentity): string;
41
+ /**
42
+ * The user agent with its Chrome version set to `milestone`.0.0.0.
43
+ *
44
+ * fpgen's fingerprints were recorded on whatever Chrome the machine ran; a UA
45
+ * behind the binary disagrees with the brand list the browser builds.
46
+ */
47
+ export declare function retargetUserAgent(userAgent: string, milestone: number | string): string;
48
+ /** Every client-hint config key for one identity. */
49
+ export declare function clientHintConfig(identity: ChromeIdentity): Record<string, any>;
50
+ /**
51
+ * Set the client hints the identity's user agent implies, keeping any the
52
+ * config already holds.
53
+ */
54
+ export declare function fillClientHints(config: Record<string, any>, targetOs: OsKey, fullVersion: string): void;
55
+ /**
56
+ * The ways this config's user agent and client hints contradict each other.
57
+ *
58
+ * Run on every launch: the hints are derived from one identity, but a caller
59
+ * can set any of them through `config`. Empty means coherent.
60
+ */
61
+ export declare function assertCoherent(config: Record<string, any>): string[];
@@ -0,0 +1,176 @@
1
+ /**
2
+ * User-Agent Client Hints: the surface Firefox does not have.
3
+ *
4
+ * A Chrome identity is a set of values that must agree:
5
+ *
6
+ * navigator.userAgent "...Windows NT 10.0; Win64; x64...Chrome/158.0.0.0..."
7
+ * navigator.userAgentData.brands [{Chromium 158}, {GREASE}], built by Chromium itself
8
+ * Sec-CH-UA the same brand list, on every request
9
+ * Sec-CH-UA-Platform "Windows"
10
+ * Sec-CH-UA-Mobile ?0
11
+ * Sec-CH-UA-Arch / -Bitness / -Platform-Version / -Full-Version-List (high entropy)
12
+ *
13
+ * The low-entropy hints go out on every request with no opt-in, so a server
14
+ * sees them before any script runs. `--user-agent` moves the UA string and not
15
+ * the hints, which is why switches.ts refuses it and everything here is derived
16
+ * from one identity. The keys are read by
17
+ * browser/patches/0003-user-agent-client-hints.patch.
18
+ *
19
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/clienthints.py.
20
+ */
21
+ import { pyStr, pyTruthy } from "./pycompat.js";
22
+ /** Sec-CH-UA-Platform values. */
23
+ export const CH_PLATFORM = {
24
+ win: "Windows",
25
+ mac: "macOS",
26
+ lin: "Linux",
27
+ };
28
+ /** navigator.platform values, which are not the Sec-CH-UA-Platform ones. */
29
+ export const NAV_PLATFORM = {
30
+ win: "Win32",
31
+ mac: "MacIntel",
32
+ lin: "Linux x86_64",
33
+ };
34
+ /**
35
+ * The parenthesised part of the UA string. Frozen by Chrome's UA reduction
36
+ * since M100: macOS stays "10_15_7", Windows "10.0; Win64; x64" from 10 through
37
+ * 11, Linux "X11; Linux x86_64". The real OS version is in
38
+ * Sec-CH-UA-Platform-Version.
39
+ */
40
+ export const UA_PLATFORM_TOKEN = {
41
+ win: "Windows NT 10.0; Win64; x64",
42
+ mac: "Macintosh; Intel Mac OS X 10_15_7",
43
+ lin: "X11; Linux x86_64",
44
+ };
45
+ /**
46
+ * Sec-CH-UA-Platform-Version values Chrome reports, per OS. assertCoherent
47
+ * refuses any other.
48
+ * win: the UniversalApiContract ladder, not the marketing version: every
49
+ * Windows 10 reports 10.0.0, Windows 11 21H2/22H2 13.0.0/14.0.0/15.0.0,
50
+ * and 19.0.0 was measured on build 26200. 16-18 have not been seen on a
51
+ * shipping build, so they are absent.
52
+ * mac: macOS Sonoma and Sequoia point releases.
53
+ * lin: the kernel version.
54
+ */
55
+ export const PLATFORM_VERSIONS = {
56
+ win: ["10.0.0", "13.0.0", "14.0.0", "15.0.0", "19.0.0"],
57
+ mac: ["14.5.0", "14.6.1", "15.1.0", "15.2.0", "15.3.1"],
58
+ lin: ["6.8.0", "6.11.0", "6.12.0"],
59
+ };
60
+ /** The version a generated identity claims when nothing names one. */
61
+ export const DEFAULT_PLATFORM_VERSION = {
62
+ win: "15.0.0",
63
+ mac: "15.3.1",
64
+ lin: "6.12.0",
65
+ };
66
+ const CHROME_VERSION = /Chrome\/\d+(\.\d+)*/g;
67
+ /** The OS a user agent claims, or null. */
68
+ export function uaOs(userAgent) {
69
+ if (userAgent.includes("Windows NT"))
70
+ return "win";
71
+ if (userAgent.includes("Mac OS X"))
72
+ return "mac";
73
+ if (/Linux|X11|CrOS/.test(userAgent))
74
+ return "lin";
75
+ return null;
76
+ }
77
+ export function buildUserAgent(identity) {
78
+ return (`Mozilla/5.0 (${UA_PLATFORM_TOKEN[identity.os]}) ` +
79
+ "AppleWebKit/537.36 (KHTML, like Gecko) " +
80
+ `Chrome/${identity.milestone}.0.0.0 Safari/537.36`);
81
+ }
82
+ /**
83
+ * The user agent with its Chrome version set to `milestone`.0.0.0.
84
+ *
85
+ * fpgen's fingerprints were recorded on whatever Chrome the machine ran; a UA
86
+ * behind the binary disagrees with the brand list the browser builds.
87
+ */
88
+ export function retargetUserAgent(userAgent, milestone) {
89
+ return userAgent.replace(CHROME_VERSION, `Chrome/${Math.trunc(Number(milestone))}.0.0.0`);
90
+ }
91
+ /** Every client-hint config key for one identity. */
92
+ export function clientHintConfig(identity) {
93
+ return {
94
+ "navigator.userAgent": buildUserAgent(identity),
95
+ "navigator.platform": NAV_PLATFORM[identity.os],
96
+ "userAgentData.platform": CH_PLATFORM[identity.os],
97
+ "userAgentData.platformVersion": identity.platformVersion || DEFAULT_PLATFORM_VERSION[identity.os],
98
+ "userAgentData.architecture": identity.arch || (identity.os === "mac" ? "arm" : "x86"),
99
+ "userAgentData.bitness": identity.bitness ?? "64",
100
+ // Desktop Chrome sends an empty model; a populated one means Android.
101
+ "userAgentData.model": identity.model ?? "",
102
+ "userAgentData.uaFullVersion": identity.fullVersion,
103
+ // 32-bit Chrome on 64-bit Windows; false whenever bitness is 64.
104
+ "userAgentData.wow64": identity.wow64 ?? false,
105
+ "userAgentData.mobile": identity.mobile ?? false,
106
+ };
107
+ }
108
+ /**
109
+ * Set the client hints the identity's user agent implies, keeping any the
110
+ * config already holds.
111
+ */
112
+ export function fillClientHints(config, targetOs, fullVersion) {
113
+ const identity = {
114
+ milestone: Number.parseInt(fullVersion.split(".", 1)[0], 10),
115
+ fullVersion,
116
+ os: targetOs,
117
+ };
118
+ for (const [key, value] of Object.entries(clientHintConfig(identity))) {
119
+ if (key === "navigator.userAgent" || key === "navigator.platform")
120
+ continue;
121
+ if (!(key in config))
122
+ config[key] = value;
123
+ }
124
+ }
125
+ /**
126
+ * The ways this config's user agent and client hints contradict each other.
127
+ *
128
+ * Run on every launch: the hints are derived from one identity, but a caller
129
+ * can set any of them through `config`. Empty means coherent.
130
+ */
131
+ export function assertCoherent(config) {
132
+ const problems = [];
133
+ const ua = config["navigator.userAgent"];
134
+ if (!ua || typeof ua !== "string")
135
+ return problems;
136
+ const chPlatform = config["userAgentData.platform"];
137
+ const navPlatform = config["navigator.platform"];
138
+ const osKey = uaOs(ua);
139
+ if (osKey && pyTruthy(chPlatform) && CH_PLATFORM[osKey] !== chPlatform) {
140
+ problems.push(`navigator.userAgent claims ${CH_PLATFORM[osKey]} but Sec-CH-UA-Platform says ` +
141
+ `"${pyStr(chPlatform)}"; every request carries this hint.`);
142
+ }
143
+ if (osKey && pyTruthy(navPlatform) && NAV_PLATFORM[osKey] !== navPlatform) {
144
+ problems.push(`navigator.userAgent claims ${CH_PLATFORM[osKey]} but navigator.platform is ` +
145
+ `"${pyStr(navPlatform)}" (expected "${NAV_PLATFORM[osKey]}").`);
146
+ }
147
+ const platformVersion = config["userAgentData.platformVersion"];
148
+ if (osKey &&
149
+ pyTruthy(platformVersion) &&
150
+ !PLATFORM_VERSIONS[osKey].includes(platformVersion)) {
151
+ problems.push(`Sec-CH-UA-Platform-Version "${pyStr(platformVersion)}" is not a value Chrome reports on ` +
152
+ `${CH_PLATFORM[osKey]} (one of ${PLATFORM_VERSIONS[osKey].join(", ")}). On Windows ` +
153
+ "this is the UA-CH ladder, not the marketing version.");
154
+ }
155
+ if (config["userAgentData.mobile"] === true && !ua.includes("Mobile")) {
156
+ problems.push("Sec-CH-UA-Mobile is ?1 but the user agent has no 'Mobile' token.");
157
+ }
158
+ if (config["userAgentData.wow64"] === true &&
159
+ config["userAgentData.bitness"] === "64") {
160
+ problems.push("Sec-CH-UA-WoW64 is ?1 with 64-bit bitness; WoW64 is a 32-bit Chrome on 64-bit " +
161
+ 'Windows, so bitness must be "32".');
162
+ }
163
+ const model = config["userAgentData.model"];
164
+ if (pyTruthy(model) && !/Android|Mobile/.test(ua)) {
165
+ problems.push(`Sec-CH-UA-Model is "${pyStr(model)}" on a desktop user agent; desktop Chrome sends "".`);
166
+ }
167
+ const fullVersion = config["userAgentData.uaFullVersion"];
168
+ const uaMajor = /Chrome\/(\d+)/.exec(ua);
169
+ if (pyTruthy(fullVersion) &&
170
+ uaMajor &&
171
+ pyStr(fullVersion).split(".", 1)[0] !== uaMajor[1]) {
172
+ problems.push(`navigator.userAgent says Chrome/${uaMajor[1]} but ` +
173
+ `Sec-CH-UA-Full-Version-List says ${pyStr(fullVersion)}.`);
174
+ }
175
+ return problems;
176
+ }