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,77 @@
1
+ /**
2
+ * Switches Playwright and Puppeteer add that mark the browser as automated.
3
+ * Dropped from the caller's args.
4
+ */
5
+ export declare const AUTOMATION_SWITCHES: ReadonlySet<string>;
6
+ /**
7
+ * Playwright's own default arguments that are left out of the launch
8
+ * (`ignoreDefaultArgs`). --enable-automation drives the "controlled by
9
+ * automated test software" infobar and upstream's navigator.webdriver;
10
+ * --disable-extensions would stop `addons` from loading; and
11
+ * --disable-popup-blocking lets a page open a window without a user gesture,
12
+ * which stock Chrome blocks and a page can test.
13
+ */
14
+ export declare const IGNORED_DEFAULT_ARGS: readonly string[];
15
+ /**
16
+ * What Playwright's headless launch tells Blink about the pointer: a mouse
17
+ * alone. The launcher drops it, because the browser states each context's
18
+ * identity's pointer (patch 0024) and a command-line one would answer for all.
19
+ */
20
+ export declare const PLAYWRIGHT_HEADLESS_BLINK_SETTINGS = "--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4";
21
+ /**
22
+ * The features Playwright's Chromium launch disables (playwright-core
23
+ * chromiumSwitches.ts, 1.59-1.62). Chromium reads only the last
24
+ * --disable-features on a command line, so when the launcher needs one of its
25
+ * own (extensions), it restates this list with it rather than silently turning
26
+ * Playwright's back on.
27
+ */
28
+ export declare const PLAYWRIGHT_DISABLED_FEATURES: readonly string[];
29
+ /**
30
+ * Disabled by Playwright after 1.62 (microsoft/playwright#43877). Chromium 158
31
+ * auto-enables HTTPS-First balanced mode, which upgrades an http:// navigation
32
+ * and fails it with ERR_BLOCKED_BY_CLIENT when the upgrade does not connect.
33
+ * The launcher restates the list with these on every launch.
34
+ */
35
+ export declare const LAUNCHER_DISABLED_FEATURES: readonly string[];
36
+ /**
37
+ * Switches that change web-visible behaviour: cross-origin reads without CORS,
38
+ * no site isolation, and so on. A page can test for each directly.
39
+ */
40
+ export declare const BEHAVIOR_CHANGING_SWITCHES: ReadonlySet<string>;
41
+ /**
42
+ * Switches whose value would contradict the CAMOU_CONFIG identity, with the
43
+ * option to use instead. Refused rather than dropped: a caller passing
44
+ * --user-agent believes the user agent is set.
45
+ */
46
+ export declare const CONFLICTING_SWITCHES: Readonly<Record<string, string>>;
47
+ /**
48
+ * Switches every Camouwolf launch adds. Each removes something a fresh
49
+ * automated profile shows and a person's does not, or a request to Google a
50
+ * datacenter launch should not make. Nothing here changes rendering or what a
51
+ * page can do.
52
+ */
53
+ export declare const BASE_SWITCHES: readonly string[];
54
+ /**
55
+ * Switches whose value is a comma-separated list. Chromium reads only the last
56
+ * occurrence of a repeated switch, so several are merged into one.
57
+ */
58
+ export declare const LIST_SWITCHES: ReadonlySet<string>;
59
+ export interface SwitchAudit {
60
+ /** The arguments to launch with. */
61
+ args: string[];
62
+ /** [argument, reason] for each one dropped. */
63
+ dropped: Array<[string, string]>;
64
+ }
65
+ export declare function flagName(arg: string): string;
66
+ /**
67
+ * Merge repeated list-valued switches (--disable-features=A and
68
+ * --disable-features=B) into one, at the position of the first.
69
+ */
70
+ export declare function mergeListSwitches(args: Iterable<string>): string[];
71
+ /**
72
+ * Filter the caller's arguments and add the base switches.
73
+ *
74
+ * `strict` throws ValueError on a switch that conflicts with the identity
75
+ * instead of dropping it.
76
+ */
77
+ export declare function auditSwitches(args: Iterable<string>, strict?: boolean): SwitchAudit;
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Chromium command-line hygiene.
3
+ *
4
+ * Camoufox has no counterpart: Firefox's automation surface is Juggler,
5
+ * compiled in. Chromium's is the command line, which holds three kinds of
6
+ * problem:
7
+ *
8
+ * 1. Switches that mark the process as automated (`--enable-automation`, which
9
+ * Playwright adds to every launch).
10
+ * 2. Switches that change behaviour a page can measure (`--disable-web-security`).
11
+ * 3. Switches whose value contradicts the identity. `--user-agent` moves
12
+ * navigator.userAgent without the client hints (see clienthints.ts), so it
13
+ * is refused and the caller pointed at `config`.
14
+ *
15
+ * The identity itself travels in the environment (CAMOU_CONFIG_*), never in
16
+ * argv: argv is readable in /proc/<pid>/cmdline and `ps`, and Chromium copies
17
+ * much of it to its renderers' command lines.
18
+ *
19
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/switches.py.
20
+ */
21
+ import { ValueError } from "./exceptions.js";
22
+ /**
23
+ * Switches Playwright and Puppeteer add that mark the browser as automated.
24
+ * Dropped from the caller's args.
25
+ */
26
+ export const AUTOMATION_SWITCHES = new Set([
27
+ "--enable-automation",
28
+ "--enable-blink-features=IdleDetection",
29
+ "--remote-debugging-pipe-log",
30
+ "--test-type",
31
+ "--no-service-autorun",
32
+ "--password-store=basic",
33
+ "--use-mock-keychain",
34
+ ]);
35
+ /**
36
+ * Playwright's own default arguments that are left out of the launch
37
+ * (`ignoreDefaultArgs`). --enable-automation drives the "controlled by
38
+ * automated test software" infobar and upstream's navigator.webdriver;
39
+ * --disable-extensions would stop `addons` from loading; and
40
+ * --disable-popup-blocking lets a page open a window without a user gesture,
41
+ * which stock Chrome blocks and a page can test.
42
+ */
43
+ export const IGNORED_DEFAULT_ARGS = [
44
+ "--enable-automation",
45
+ "--disable-extensions",
46
+ "--disable-popup-blocking",
47
+ ];
48
+ /**
49
+ * What Playwright's headless launch tells Blink about the pointer: a mouse
50
+ * alone. The launcher drops it, because the browser states each context's
51
+ * identity's pointer (patch 0024) and a command-line one would answer for all.
52
+ */
53
+ export const PLAYWRIGHT_HEADLESS_BLINK_SETTINGS = "--blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4";
54
+ /**
55
+ * The features Playwright's Chromium launch disables (playwright-core
56
+ * chromiumSwitches.ts, 1.59-1.62). Chromium reads only the last
57
+ * --disable-features on a command line, so when the launcher needs one of its
58
+ * own (extensions), it restates this list with it rather than silently turning
59
+ * Playwright's back on.
60
+ */
61
+ export const PLAYWRIGHT_DISABLED_FEATURES = [
62
+ "AvoidUnnecessaryBeforeUnloadCheckSync",
63
+ "BoundaryEventDispatchTracksNodeRemoval",
64
+ "DestroyProfileOnBrowserClose",
65
+ "DialMediaRouteProvider",
66
+ "GlobalMediaControls",
67
+ "HttpsUpgrades",
68
+ "LensOverlay",
69
+ "MediaRouter",
70
+ "PaintHolding",
71
+ "ThirdPartyStoragePartitioning",
72
+ "BlockOriginHeaderModificationOnRedirect",
73
+ "Translate",
74
+ "AutoDeElevate",
75
+ "OptimizationHints",
76
+ "msForceBrowserSignIn",
77
+ "msEdgeUpdateLaunchServicesPreferredVersion",
78
+ ];
79
+ /**
80
+ * Disabled by Playwright after 1.62 (microsoft/playwright#43877). Chromium 158
81
+ * auto-enables HTTPS-First balanced mode, which upgrades an http:// navigation
82
+ * and fails it with ERR_BLOCKED_BY_CLIENT when the upgrade does not connect.
83
+ * The launcher restates the list with these on every launch.
84
+ */
85
+ export const LAUNCHER_DISABLED_FEATURES = [
86
+ "HttpsFirstBalancedModeAutoEnable",
87
+ ];
88
+ /**
89
+ * Switches that change web-visible behaviour: cross-origin reads without CORS,
90
+ * no site isolation, and so on. A page can test for each directly.
91
+ */
92
+ export const BEHAVIOR_CHANGING_SWITCHES = new Set([
93
+ "--disable-web-security",
94
+ "--disable-site-isolation-trials",
95
+ "--disable-features=IsolateOrigins,site-per-process",
96
+ "--allow-running-insecure-content",
97
+ "--disable-popup-blocking",
98
+ "--ignore-certificate-errors",
99
+ ]);
100
+ /**
101
+ * Switches whose value would contradict the CAMOU_CONFIG identity, with the
102
+ * option to use instead. Refused rather than dropped: a caller passing
103
+ * --user-agent believes the user agent is set.
104
+ */
105
+ export const CONFLICTING_SWITCHES = {
106
+ "--user-agent": "Setting --user-agent moves navigator.userAgent but not the Sec-CH-UA-* client hints, " +
107
+ "so the two disagree on every request. Pass the identity through `config` or " +
108
+ "`fingerprint` instead; Camouwolf derives the user agent and the hints from it together.",
109
+ "--lang": "Setting --lang moves the UI language but not navigator.languages or the " +
110
+ "Accept-Language header. Use the `locale` option, which sets all three.",
111
+ "--accept-lang": "Setting --accept-lang moves the Accept-Language header but not the UI language or " +
112
+ "navigator.languages. Use the `locale` option, which sets all three.",
113
+ "--window-size": "Setting --window-size moves the real window without the screen the identity claims. " +
114
+ "Use the `window` option.",
115
+ "--window-position": "Setting --window-position moves the real window without the screen the identity " +
116
+ "claims. Set window.screenX and window.screenY in `config`.",
117
+ "--force-device-scale-factor": "Setting the device scale factor here separates it from the identity's screen. " +
118
+ "Use the `screen` option.",
119
+ "--proxy-server": "Use the `proxy` option, which also sends the geoip lookup through the proxy.",
120
+ "--headless": "Use the `headless` option. The switch bypasses headless='virtual' and 'virtual-gpu'.",
121
+ "--user-data-dir": "Use `persistent_context=True` with `user_data_dir`.",
122
+ };
123
+ /**
124
+ * Switches every Camouwolf launch adds. Each removes something a fresh
125
+ * automated profile shows and a person's does not, or a request to Google a
126
+ * datacenter launch should not make. Nothing here changes rendering or what a
127
+ * page can do.
128
+ */
129
+ export const BASE_SWITCHES = [
130
+ "--no-first-run",
131
+ "--no-default-browser-check",
132
+ "--disable-background-networking",
133
+ "--disable-component-update",
134
+ "--disable-domain-reliability",
135
+ "--metrics-recording-only",
136
+ "--disable-breakpad",
137
+ "--disable-blink-features=AutomationControlled",
138
+ ];
139
+ /**
140
+ * Switches whose value is a comma-separated list. Chromium reads only the last
141
+ * occurrence of a repeated switch, so several are merged into one.
142
+ */
143
+ export const LIST_SWITCHES = new Set([
144
+ "--enable-features",
145
+ "--disable-features",
146
+ "--enable-blink-features",
147
+ "--disable-blink-features",
148
+ "--load-extension",
149
+ "--blink-settings",
150
+ ]);
151
+ /** str.split('=', 1): the part before the first `=`, and the rest (or undefined). */
152
+ function splitOnce(arg) {
153
+ const at = arg.indexOf("=");
154
+ return at === -1 ? [arg, undefined] : [arg.slice(0, at), arg.slice(at + 1)];
155
+ }
156
+ export function flagName(arg) {
157
+ return splitOnce(arg)[0];
158
+ }
159
+ /**
160
+ * Merge repeated list-valued switches (--disable-features=A and
161
+ * --disable-features=B) into one, at the position of the first.
162
+ */
163
+ export function mergeListSwitches(args) {
164
+ const merged = [];
165
+ const position = new Map();
166
+ for (const arg of args) {
167
+ const [name, value] = splitOnce(arg);
168
+ if (!LIST_SWITCHES.has(name) || value === undefined) {
169
+ merged.push(arg);
170
+ continue;
171
+ }
172
+ const values = value.split(",").filter((v) => v);
173
+ const at = position.get(name);
174
+ if (at !== undefined) {
175
+ const current = splitOnce(merged[at])[1].split(",");
176
+ merged[at] =
177
+ `${name}=${[...current, ...values.filter((v) => !current.includes(v))].join(",")}`;
178
+ }
179
+ else {
180
+ position.set(name, merged.length);
181
+ merged.push(`${name}=${[...new Set(values)].join(",")}`);
182
+ }
183
+ }
184
+ return merged;
185
+ }
186
+ /**
187
+ * Filter the caller's arguments and add the base switches.
188
+ *
189
+ * `strict` throws ValueError on a switch that conflicts with the identity
190
+ * instead of dropping it.
191
+ */
192
+ export function auditSwitches(args, strict = true) {
193
+ const dropped = [];
194
+ const kept = [];
195
+ for (const arg of args) {
196
+ const name = flagName(arg);
197
+ const conflict = Object.hasOwn(CONFLICTING_SWITCHES, name)
198
+ ? CONFLICTING_SWITCHES[name]
199
+ : undefined;
200
+ if (conflict) {
201
+ if (strict) {
202
+ throw new ValueError(`Camouwolf refuses '${name}'. ${conflict}`);
203
+ }
204
+ dropped.push([arg, conflict]);
205
+ }
206
+ else if (AUTOMATION_SWITCHES.has(arg) || AUTOMATION_SWITCHES.has(name)) {
207
+ dropped.push([arg, "automation marker"]);
208
+ }
209
+ else if (BEHAVIOR_CHANGING_SWITCHES.has(arg) ||
210
+ BEHAVIOR_CHANGING_SWITCHES.has(name)) {
211
+ dropped.push([arg, "changes web-visible behavior"]);
212
+ }
213
+ else {
214
+ kept.push(arg);
215
+ }
216
+ }
217
+ // Base switches first; a caller's list-valued switch of the same name is
218
+ // merged with it, and any other repeat is the caller's (Chromium reads the last).
219
+ const seen = new Set(kept.map(flagName).filter((name) => !LIST_SWITCHES.has(name)));
220
+ const base = BASE_SWITCHES.filter((s) => !seen.has(flagName(s)));
221
+ return { args: mergeListSwitches([...base, ...kept]), dropped };
222
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The launcher entry points: Camouwolf(), NewBrowser(), NewContext().
3
+ *
4
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/sync_api.py (and async_api.py, whose
5
+ * names async_api.ts re-exports). The Python library ships a sync and an
6
+ * async variant because Playwright-Python has two APIs; playwright-core has
7
+ * only one (promise-based), so the behaviours of both live here: the context
8
+ * defaults, CPU-core pinning with its launch lock (async_api), and
9
+ * virtual-display teardown.
10
+ */
11
+ import { type Browser, type BrowserContext, type BrowserType } from "playwright-core";
12
+ import type { ProxyConfig } from "../ip.js";
13
+ import { type ContextIdentityOptions, type GeolocationOption, type GpuDisplayOptions, type Headless, type LaunchOptions } from "./utils.js";
14
+ export type { Headless } from "./utils.js";
15
+ export interface NewBrowserOptions extends Omit<LaunchOptions, "headless">, GpuDisplayOptions {
16
+ /** True for Chromium headless. On Linux, `"virtual"` runs a headed browser
17
+ * on an Xvfb display, and `"virtual-gpu"` on a headless Xorg server bound
18
+ * to the GPU `gpu` (or CAMOUWOLF_GPU) names; `require_gpu: false` warns
19
+ * instead of failing when the browser does not render on it. */
20
+ headless?: Headless;
21
+ /** A set of launch options generated by `launchOptions()` to use as-is. */
22
+ from_options?: Record<string, any>;
23
+ /** Whether to use a persistent context. */
24
+ persistent_context?: boolean;
25
+ /** Directory for the persistent profile (Playwright's user_data_dir). */
26
+ user_data_dir?: string;
27
+ }
28
+ /**
29
+ * Launches a Camouwolf browser and returns it (Python: `with Camouwolf(...) as
30
+ * browser`). Close it with `browser.close()`; a virtual display, if one was
31
+ * spawned, is torn down with it.
32
+ */
33
+ export declare function Camouwolf(options: NewBrowserOptions & {
34
+ persistent_context: true;
35
+ }): Promise<BrowserContext>;
36
+ export declare function Camouwolf(options?: NewBrowserOptions): Promise<Browser>;
37
+ /**
38
+ * Launches a new browser instance for Camouwolf given a set of launch options.
39
+ *
40
+ * `playwright` is Playwright's `chromium` browser type (Python passes the
41
+ * Playwright object and reads `.chromium` from it; an object with a `chromium`
42
+ * member is accepted too). `from_options`: a set of launch options generated
43
+ * by `launchOptions()` to use. `persistent_context`: whether to use a
44
+ * persistent context. Every other option is passed to `launchOptions()`.
45
+ */
46
+ export declare function NewBrowser(playwright: BrowserType | {
47
+ chromium: BrowserType;
48
+ }, options: NewBrowserOptions & {
49
+ persistent_context: true;
50
+ }): Promise<BrowserContext>;
51
+ export declare function NewBrowser(playwright: BrowserType | {
52
+ chromium: BrowserType;
53
+ }, options?: NewBrowserOptions): Promise<Browser>;
54
+ export interface NewContextOptions extends ContextIdentityOptions, Record<string, any> {
55
+ /** Per-context proxy, in Playwright's format. */
56
+ proxy?: ProxyConfig;
57
+ /** Per-context geolocation; the permission is granted with it. */
58
+ geolocation?: GeolocationOption;
59
+ }
60
+ /** snake_case -> camelCase, as camouwolf.server.camel_case does. */
61
+ export declare function camelCase(snake: string): string;
62
+ /**
63
+ * Creates a new browser context with an identity of its own.
64
+ *
65
+ * The context is another machine than the rest of the browser: its pages,
66
+ * workers, request headers, WebRTC, GPU and fonts answer with an identity
67
+ * drawn for it. It shares the browser's OS, screen, window and core count,
68
+ * which one browser process cannot vary. A plain browser.newContext() keeps
69
+ * the launch's identity.
70
+ *
71
+ * A `proxy` places the context where it exits: its timezone, locale, position
72
+ * and WebRTC address are the exit IP's, looked up through the proxy (needs the
73
+ * geoip database); InvalidIP is thrown if the lookup fails. Without one, the
74
+ * context leaves from the browser's address and keeps its place. `os` must be
75
+ * the launch's; `fingerprint`, `config`, `webgl_config`, `fonts` and
76
+ * `custom_fonts_only` are as at launch, for this context; `webrtc_ip`,
77
+ * `locale` and `timezoneId` are this context's.
78
+ *
79
+ * Other keys are Playwright newContext() options. Options that would make the
80
+ * pages disagree with the identity (userAgent, screen, deviceScaleFactor,
81
+ * isMobile, hasTouch) throw IncoherentIdentity; Camoufox's preset, ff_version
82
+ * and chrome_version throw NotImplementedError.
83
+ */
84
+ export declare function NewContext(browser: Browser, { proxy, geolocation, os, fingerprint, config, webgl_config, webrtc_ip, fonts, custom_fonts_only, locale, timezoneId, i_know_what_im_doing, ...contextOptions }?: NewContextOptions): Promise<BrowserContext>;
@@ -0,0 +1,173 @@
1
+ /**
2
+ * The launcher entry points: Camouwolf(), NewBrowser(), NewContext().
3
+ *
4
+ * TypeScript twin of python/camoucore/src/camoucore/camouwolf/sync_api.py (and async_api.py, whose
5
+ * names async_api.ts re-exports). The Python library ships a sync and an
6
+ * async variant because Playwright-Python has two APIs; playwright-core has
7
+ * only one (promise-based), so the behaviours of both live here: the context
8
+ * defaults, CPU-core pinning with its launch lock (async_api), and
9
+ * virtual-display teardown.
10
+ */
11
+ import { chromium, } from "playwright-core";
12
+ import * as cpuAffinity from "../cpu_affinity.js";
13
+ import { attach } from "./_humanize_playwright.js";
14
+ import { attachDriverDefaults } from "./driver_defaults.js";
15
+ import { normalize } from "./humanize.js";
16
+ import { attachContextDefaults, attachVirtualDisplay, contextIdentity, createdContextId, driverPid, launchDefaults, launchOptions, launchOptionsOf, launchOs, newContextOptions, persistentContextOptions, pinnedCoreCount, refuseContextOptions, setContextIdentityParams, startTelemetry, startVirtualDisplay, warnAddonsWithoutProfile, } from "./utils.js";
17
+ export async function Camouwolf(options = {}) {
18
+ return NewBrowser(chromium, options);
19
+ }
20
+ export async function NewBrowser(playwright, options = {}) {
21
+ // The defaults file fills what the caller left unset; options read here
22
+ // (headless, humanize, telemetry) need it before launchOptions runs.
23
+ const { headless, from_options, persistent_context, debug, ...kwargs } = launchDefaults(options);
24
+ const browserType = "chromium" in playwright ? playwright.chromium : playwright;
25
+ // humanize runs in this process: checked before the launch, attached to
26
+ // the browser after it (also with from_options).
27
+ normalize(kwargs.humanize);
28
+ const [virtualDisplay, headlessBool] = await startVirtualDisplay(headless, debug, kwargs);
29
+ // Everything after the display exists can fail (bad proxy, missing binary,
30
+ // unsatisfiable constraints) before attachVirtualDisplay wires kill() into
31
+ // close.
32
+ try {
33
+ let fromOptions = from_options;
34
+ if (!fromOptions || !Object.keys(fromOptions).length) {
35
+ // Opt-in. Pinning keeps the identity's core count by constraining the
36
+ // browser to that many cores; it costs real CPU, needs a launch lock,
37
+ // and does nothing on macOS. Off, the host's own snapped count is
38
+ // reported, so reported and measurable still agree.
39
+ kwargs.pin_cpu_cores ??= false;
40
+ fromOptions = await launchOptions({
41
+ ...kwargs,
42
+ headless: headlessBool,
43
+ debug,
44
+ });
45
+ }
46
+ const options = fromOptions;
47
+ // Pin the driver (and so the browser it is about to spawn) to as many
48
+ // cores as the identity reports, so measurable parallelism matches
49
+ // navigator.hardwareConcurrency; the driver gets its cores back
50
+ // afterwards.
51
+ const pinTo = kwargs.pin_cpu_cores ? pinnedCoreCount(options) : null;
52
+ const launch = () => launchWith(browserType, options, Boolean(persistent_context), virtualDisplay, kwargs.telemetry);
53
+ let browser;
54
+ if (!pinTo) {
55
+ browser = await cpuAffinity.withUnpinnedLaunch(launch);
56
+ }
57
+ else {
58
+ const pid = driverPid();
59
+ // The browser inherits the driver's mask at spawn, so two concurrent
60
+ // launches must not interleave pin/restore.
61
+ browser = await cpuAffinity.withPinLock(async () => {
62
+ const previous = cpuAffinity.pin(pid, pinTo);
63
+ try {
64
+ return await launch();
65
+ }
66
+ finally {
67
+ cpuAffinity.restore(pid, previous);
68
+ }
69
+ });
70
+ }
71
+ return attach(browser, kwargs.humanize, launchOs(options), kwargs.i_know_what_im_doing);
72
+ }
73
+ catch (error) {
74
+ virtualDisplay?.kill();
75
+ throw error;
76
+ }
77
+ }
78
+ async function launchWith(browserType, fromOptions, persistentContext, virtualDisplay, telemetry) {
79
+ const userDataDir = fromOptions.user_data_dir ?? fromOptions.userDataDir;
80
+ if (persistentContext) {
81
+ // Python passes user_data_dir inside the options; the JS API takes it
82
+ // positionally.
83
+ const options = persistentContextOptions(fromOptions);
84
+ delete options.user_data_dir;
85
+ delete options.userDataDir;
86
+ const context = await browserType.launchPersistentContext(userDataDir ?? "", options);
87
+ attachDriverDefaults(context);
88
+ startTelemetry(context, fromOptions, telemetry, true);
89
+ return attachVirtualDisplay(context, virtualDisplay);
90
+ }
91
+ if (userDataDir !== undefined) {
92
+ // Playwright-Python refuses the keyword; playwright-core would ignore
93
+ // it and launch a throwaway profile.
94
+ throw new TypeError("BrowserType.launch() got an unexpected keyword argument 'user_data_dir'");
95
+ }
96
+ warnAddonsWithoutProfile(fromOptions);
97
+ const browser = await browserType.launch(fromOptions);
98
+ attachContextDefaults(browser, fromOptions);
99
+ startTelemetry(browser, fromOptions, telemetry, false);
100
+ return attachVirtualDisplay(browser, virtualDisplay);
101
+ }
102
+ /** snake_case -> camelCase, as camouwolf.server.camel_case does. */
103
+ export function camelCase(snake) {
104
+ if (snake.length < 2)
105
+ return snake;
106
+ const parts = snake.toLowerCase().split("_");
107
+ const joined = parts
108
+ .map((x) => (x ? x[0].toUpperCase() + x.slice(1) : ""))
109
+ .join("");
110
+ return ((snake[0] === "_" ? "_" : "") + joined[0].toLowerCase() + joined.slice(1));
111
+ }
112
+ /**
113
+ * Creates a new browser context with an identity of its own.
114
+ *
115
+ * The context is another machine than the rest of the browser: its pages,
116
+ * workers, request headers, WebRTC, GPU and fonts answer with an identity
117
+ * drawn for it. It shares the browser's OS, screen, window and core count,
118
+ * which one browser process cannot vary. A plain browser.newContext() keeps
119
+ * the launch's identity.
120
+ *
121
+ * A `proxy` places the context where it exits: its timezone, locale, position
122
+ * and WebRTC address are the exit IP's, looked up through the proxy (needs the
123
+ * geoip database); InvalidIP is thrown if the lookup fails. Without one, the
124
+ * context leaves from the browser's address and keeps its place. `os` must be
125
+ * the launch's; `fingerprint`, `config`, `webgl_config`, `fonts` and
126
+ * `custom_fonts_only` are as at launch, for this context; `webrtc_ip`,
127
+ * `locale` and `timezoneId` are this context's.
128
+ *
129
+ * Other keys are Playwright newContext() options. Options that would make the
130
+ * pages disagree with the identity (userAgent, screen, deviceScaleFactor,
131
+ * isMobile, hasTouch) throw IncoherentIdentity; Camoufox's preset, ff_version
132
+ * and chrome_version throw NotImplementedError.
133
+ */
134
+ export async function NewContext(browser, { proxy, geolocation, os, fingerprint, config, webgl_config, webrtc_ip, fonts, custom_fonts_only, locale, timezoneId, i_know_what_im_doing, ...contextOptions } = {}) {
135
+ refuseContextOptions(contextOptions);
136
+ const { identity, languages } = await contextIdentity(launchOptionsOf(browser), {
137
+ proxy,
138
+ os,
139
+ fingerprint,
140
+ config,
141
+ webgl_config,
142
+ webrtc_ip,
143
+ fonts,
144
+ custom_fonts_only,
145
+ locale,
146
+ timezoneId,
147
+ i_know_what_im_doing,
148
+ });
149
+ const options = newContextOptions(contextOptions, identity, proxy, geolocation);
150
+ // The new context is the one getBrowserContexts gains, and it takes its
151
+ // identity before its first renderer.
152
+ return serialized(browser, async () => {
153
+ const session = await browser.newBrowserCDPSession();
154
+ try {
155
+ const before = await session.send("Target.getBrowserContexts");
156
+ const context = await browser.newContext(options);
157
+ const contextId = createdContextId(before, await session.send("Target.getBrowserContexts"));
158
+ await session.send("Target.setBrowserContextIdentity", setContextIdentityParams(contextId, identity, languages));
159
+ return context;
160
+ }
161
+ finally {
162
+ await session.detach();
163
+ }
164
+ });
165
+ }
166
+ const contextQueues = new WeakMap();
167
+ /** Run `task` after every earlier one queued on `browser`. */
168
+ function serialized(browser, task) {
169
+ const previous = contextQueues.get(browser) ?? Promise.resolve();
170
+ const run = previous.then(task, task);
171
+ contextQueues.set(browser, run.catch(() => undefined));
172
+ return run;
173
+ }