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,31 @@
1
+ /**
2
+ * Camoufox version constants.
3
+ *
4
+ * TypeScript twin of python/camoucore/src/camoucore/camoufox/__version__.py.
5
+ */
6
+ export declare class CONSTRAINTS {
7
+ /**
8
+ * The minimum and maximum supported versions of the Camoufox browser.
9
+ */
10
+ static readonly MIN_VERSION: string;
11
+ static readonly MAX_VERSION: string;
12
+ /**
13
+ * [playwrightVersion, browserBuild]: from that Playwright on, the browser must
14
+ * be at least that build (1.61 sends viewport fields beta.29 rejects). Keyed on
15
+ * Playwright so only users who would break are moved to a newer browser.
16
+ */
17
+ static readonly PLAYWRIGHT_BROWSER_FLOORS: ReadonlyArray<readonly [readonly number[], string]>;
18
+ /**
19
+ * The browser interface built from this tree. Every browser release
20
+ * declares it in its manifest.json (ci/release.py reads it from the Python
21
+ * twin), and this library accepts browsers from MIN_INTERFACE up to it.
22
+ * Raise it when a browser change would break released libraries; raise
23
+ * MIN_INTERFACE when this library can no longer drive older browsers.
24
+ * Releases from before manifests carried the field are interface 1.
25
+ */
26
+ static readonly INTERFACE: number;
27
+ static readonly MIN_INTERFACE: number;
28
+ }
29
+ /** Version of this launcher library. Kept in step with package.json and
30
+ * pythonlib's pyproject.toml. */
31
+ export declare const LIBRARY_VERSION = "0.6.0";
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Camoufox version constants.
3
+ *
4
+ * TypeScript twin of python/camoucore/src/camoucore/camoufox/__version__.py.
5
+ */
6
+ // biome-ignore lint/complexity/noStaticOnlyClass: mirrors the Python twin's CONSTRAINTS class so both launchers read the same
7
+ export class CONSTRAINTS {
8
+ /**
9
+ * The minimum and maximum supported versions of the Camoufox browser.
10
+ */
11
+ static MIN_VERSION = "alpha.1";
12
+ static MAX_VERSION = "1";
13
+ /**
14
+ * [playwrightVersion, browserBuild]: from that Playwright on, the browser must
15
+ * be at least that build (1.61 sends viewport fields beta.29 rejects). Keyed on
16
+ * Playwright so only users who would break are moved to a newer browser.
17
+ */
18
+ static PLAYWRIGHT_BROWSER_FLOORS = [[[1, 61], "beta.30"]];
19
+ /**
20
+ * The browser interface built from this tree. Every browser release
21
+ * declares it in its manifest.json (ci/release.py reads it from the Python
22
+ * twin), and this library accepts browsers from MIN_INTERFACE up to it.
23
+ * Raise it when a browser change would break released libraries; raise
24
+ * MIN_INTERFACE when this library can no longer drive older browsers.
25
+ * Releases from before manifests carried the field are interface 1.
26
+ */
27
+ static INTERFACE = 1;
28
+ static MIN_INTERFACE = 1;
29
+ }
30
+ /** Version of this launcher library. Kept in step with package.json and
31
+ * pythonlib's pyproject.toml. */
32
+ export const LIBRARY_VERSION = "0.6.0";
@@ -0,0 +1,54 @@
1
+ /**
2
+ * myuri's smart actions on Playwright pages. The TypeScript twin of
3
+ * python/camoucore/src/camoucore/camoufox/_humanize_playwright.py; both are held to the sequence
4
+ * in browser/tests/humanize/sequence.json.
5
+ *
6
+ * Each page of the browser (or persistent context) a humanize setting is
7
+ * attached to gets one myuri `Actions`. It owns the timing and motion of the
8
+ * page's input and the decisions around a click: scroll the element into
9
+ * view, choose the point, check that a press there lands, and try again when
10
+ * it does not. The host below sends each event through Playwright's own input
11
+ * methods, so the page sees the same trusted events as from any Playwright
12
+ * call, and the browser runs every channel raw.
13
+ *
14
+ * A raw() channel's parts are Playwright's: its moves are one event, its
15
+ * scroll into view is Playwright's. A part passed to myuri() is called with
16
+ * the page in place of the host. Inside it, Playwright calls are Playwright's
17
+ * own, so page.mouse.move in a move part moves the mouse once.
18
+ *
19
+ * What is wrapped, per page, and the channel that drives it:
20
+ *
21
+ * mouse Mouse.move / click / dblclick; Page/Frame/Locator click,
22
+ * dblclick, hover, check and uncheck, and the click that focuses
23
+ * a field before fill
24
+ * keyboard Keyboard.type / press; Page/Frame/Locator fill, type, press,
25
+ * and Locator.pressSequentially
26
+ * scroll Mouse.wheel; Locator.scrollIntoViewIfNeeded, and the scroll
27
+ * into view before a pointer action, fill, type or
28
+ * pressSequentially
29
+ *
30
+ * ElementHandle methods, tap, dragAndDrop and dragTo are Playwright's own. An
31
+ * ElementHandle cannot be measured and moved to as a Locator can, and a drag's
32
+ * moves happen inside Playwright's server.
33
+ */
34
+ import { type HumanizeSetting } from "./humanize.js";
35
+ import type { OsName } from "./utils.js";
36
+ export declare const VIEWPORT = "() => [innerWidth, innerHeight]";
37
+ export declare const FRAME_ORIGIN = "e => { if (window === window.top) return null; const r = e.getBoundingClientRect(); return [r.x, r.y]; }";
38
+ /** The clock myuri's waits are on. */
39
+ export declare const clock: {
40
+ now: () => number;
41
+ sleep: (ms: number) => Promise<unknown>;
42
+ };
43
+ /**
44
+ * Run myuri on every page of `target`, a Browser or BrowserContext, including
45
+ * pages and contexts opened later, as the `humanize` setting says. Other
46
+ * browsers in this process are untouched. `os` ("macos", "windows" or
47
+ * "linux") is the launch identity's, whose people myuri plans for.
48
+ * Camoufox()/NewBrowser() call this themselves; for one from `connect()`,
49
+ * launch it without humanize.
50
+ *
51
+ * Every draw comes from one stream, of `humanize.seed` or a random seed, and
52
+ * the seed draws the person myuri plays around `humanize.settings`.
53
+ */
54
+ export declare function attach<T>(target: T, humanize: HumanizeSetting, os: OsName, iKnowWhatImDoing?: boolean): T;
@@ -0,0 +1,429 @@
1
+ /**
2
+ * myuri's smart actions on Playwright pages. The TypeScript twin of
3
+ * python/camoucore/src/camoucore/camoufox/_humanize_playwright.py; both are held to the sequence
4
+ * in browser/tests/humanize/sequence.json.
5
+ *
6
+ * Each page of the browser (or persistent context) a humanize setting is
7
+ * attached to gets one myuri `Actions`. It owns the timing and motion of the
8
+ * page's input and the decisions around a click: scroll the element into
9
+ * view, choose the point, check that a press there lands, and try again when
10
+ * it does not. The host below sends each event through Playwright's own input
11
+ * methods, so the page sees the same trusted events as from any Playwright
12
+ * call, and the browser runs every channel raw.
13
+ *
14
+ * A raw() channel's parts are Playwright's: its moves are one event, its
15
+ * scroll into view is Playwright's. A part passed to myuri() is called with
16
+ * the page in place of the host. Inside it, Playwright calls are Playwright's
17
+ * own, so page.mouse.move in a move part moves the mouse once.
18
+ *
19
+ * What is wrapped, per page, and the channel that drives it:
20
+ *
21
+ * mouse Mouse.move / click / dblclick; Page/Frame/Locator click,
22
+ * dblclick, hover, check and uncheck, and the click that focuses
23
+ * a field before fill
24
+ * keyboard Keyboard.type / press; Page/Frame/Locator fill, type, press,
25
+ * and Locator.pressSequentially
26
+ * scroll Mouse.wheel; Locator.scrollIntoViewIfNeeded, and the scroll
27
+ * into view before a pointer action, fill, type or
28
+ * pressSequentially
29
+ *
30
+ * ElementHandle methods, tap, dragAndDrop and dragTo are Playwright's own. An
31
+ * ElementHandle cannot be measured and moved to as a Locator can, and a drag's
32
+ * moves happen inside Playwright's server.
33
+ */
34
+ import { AsyncLocalStorage } from "node:async_hooks";
35
+ import { randomBytes } from "node:crypto";
36
+ import { Actions, generateProfile, HIT_TEST_JS, Missed, makeRng, } from "@jwriter20/myuri";
37
+ import { errors } from "playwright-core";
38
+ import { FILL_NEEDS_CLICK, pageFunction, patchFrameFill, } from "./driver_defaults.js";
39
+ import { CHANNELS, normalize, } from "./humanize.js";
40
+ import { LeakWarning, loadWarnings } from "./warnings.js";
41
+ const scope = new AsyncLocalStorage();
42
+ const within = (change, fn) => scope.run({ inPart: false, inPlaywright: false, ...scope.getStore(), ...change }, fn);
43
+ const SETUP = Symbol.for("camoufox.humanize");
44
+ const ACTIONS = Symbol.for("camoufox.humanize-actions");
45
+ const ROUTED_FRAMES = Symbol.for("camoufox.humanize-routed");
46
+ const DISPATCH_ISOLATED = Symbol.for("camoufox.humanize-dispatch");
47
+ // Byte-identical to the Python constants (tests/package-parity.test.ts).
48
+ export const VIEWPORT = "() => [innerWidth, innerHeight]";
49
+ // The element's client origin in its frame, or null in the top window, whose
50
+ // viewport is the page's.
51
+ export const FRAME_ORIGIN = "e => { if (window === window.top) return null; const r = e.getBoundingClientRect(); return [r.x, r.y]; }";
52
+ /** The clock myuri's waits are on. */
53
+ export const clock = {
54
+ now: () => performance.now(),
55
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
56
+ };
57
+ /** `fn` as Playwright's own: a call it makes on a wrapped method passes through. */
58
+ function direct(fn) {
59
+ return ((...args) => within({ inPlaywright: true }, () => fn(...args)));
60
+ }
61
+ /** myuri's host on one page: every event is a Playwright input call. */
62
+ function host(page) {
63
+ const { mouse, keyboard } = page;
64
+ const down = direct(mouse.down.bind(mouse));
65
+ const up = direct(mouse.up.bind(mouse));
66
+ const timeout = () => scope.getStore()?.timeout;
67
+ return {
68
+ move: direct(mouse.move.bind(mouse)),
69
+ click: async (button, clickCount, holdMs) => {
70
+ await down({ button, clickCount });
71
+ await clock.sleep(holdMs);
72
+ await up({ button, clickCount });
73
+ },
74
+ down: (button) => down({ button }),
75
+ up: (button) => up({ button }),
76
+ wheel: direct(mouse.wheel.bind(mouse)),
77
+ keyDown: direct(keyboard.down.bind(keyboard)),
78
+ keyUp: direct(keyboard.up.bind(keyboard)),
79
+ insertText: direct(keyboard.insertText.bind(keyboard)),
80
+ evaluate: (target, fn, arg) => target.evaluate(fn, arg, { timeout: timeout() }),
81
+ offset: async (target) => {
82
+ const origin = await target.evaluate(pageFunction(FRAME_ORIGIN), undefined, { timeout: timeout() });
83
+ if (origin === null)
84
+ return [0, 0];
85
+ const box = await target.boundingBox({ timeout: timeout() });
86
+ return box ? [box.x - origin[0], box.y - origin[1]] : null;
87
+ },
88
+ viewport: () => page.evaluate(pageFunction(VIEWPORT)),
89
+ now: () => clock.now(),
90
+ sleep: (ms) => clock.sleep(ms),
91
+ };
92
+ }
93
+ // ---- parts -----------------------------------------------------------------
94
+ const LOCATOR_ORIGINALS = new WeakMap();
95
+ function locatorOriginal(locator, name) {
96
+ return LOCATOR_ORIGINALS.get(locator.constructor)[name];
97
+ }
98
+ // What myuri calls for a raw() channel: the parts its other channels' flows use.
99
+ const RAW_PARTS = {
100
+ mouse: { move: (_host, x, y, { play }) => play([["move", x, y, 0]]) },
101
+ keyboard: {},
102
+ scroll: {
103
+ intoView: (_host, locator) => locatorOriginal(locator, "scrollIntoViewIfNeeded")(locator, {
104
+ timeout: scope.getStore()?.timeout,
105
+ }),
106
+ },
107
+ };
108
+ class Setup {
109
+ engines;
110
+ os;
111
+ // One stream for every page, so two pages never replay the same draws.
112
+ rng;
113
+ // One person for the whole browser, drawn from the seed around the settings.
114
+ settings;
115
+ constructor(engines, seed, settings, os) {
116
+ this.engines = engines;
117
+ this.os = os;
118
+ this.rng = makeRng(seed);
119
+ // Camoufox identities point with a mouse unless told otherwise.
120
+ const scroll = { device: "mouse", ...settings.scroll };
121
+ this.settings = generateProfile(seed, { ...settings, scroll }, os);
122
+ }
123
+ /** Whether myuri drives the channel for the call being made. */
124
+ drives(channel) {
125
+ const current = scope.getStore();
126
+ return (this.engines[channel].engine === "myuri" &&
127
+ !current?.inPart &&
128
+ !current?.inPlaywright);
129
+ }
130
+ actions(page) {
131
+ const parts = {};
132
+ for (const channel of CHANNELS) {
133
+ const { engine, options } = this.engines[channel];
134
+ if (engine === "raw")
135
+ Object.assign(parts, RAW_PARTS[channel]);
136
+ // A part of the caller's, called with the page in place of the host;
137
+ // one that throws rejects, as Playwright's methods do.
138
+ else
139
+ for (const [name, fn] of Object.entries(options))
140
+ parts[name] = async (_host, ...args) => within({ inPart: true }, () => fn(page, ...args));
141
+ }
142
+ return new Actions(host(page), this.rng, {
143
+ os: this.os,
144
+ settings: this.settings,
145
+ parts,
146
+ });
147
+ }
148
+ }
149
+ // ---- flows -----------------------------------------------------------------
150
+ const timed = (timeout, fn) => within({ timeout }, fn);
151
+ function timeoutOf(locator, options) {
152
+ return options.timeout ?? locator.page()._timeoutSettings.timeout({}).timeout;
153
+ }
154
+ /** myuri's click (or, for hover, its move) onto the locator, failing as
155
+ * Playwright's action does: a timeout naming why the point was never reached. */
156
+ async function reach(actions, locator, name, options, timeout) {
157
+ try {
158
+ await actions.click(locator, {
159
+ button: options.button ?? "left",
160
+ clickCount: options.clickCount ?? (name === "dblclick" ? 2 : 1),
161
+ modifiers: options.modifiers ?? [],
162
+ position: options.position,
163
+ force: Boolean(options.force),
164
+ press: name !== "hover",
165
+ // 0 is no timeout, as in Playwright.
166
+ timeout,
167
+ });
168
+ }
169
+ catch (error) {
170
+ if (!(error instanceof Missed))
171
+ throw error;
172
+ throw new errors.TimeoutError(`Timeout ${timeout}ms exceeded: ${name} ${error.message}`);
173
+ }
174
+ }
175
+ /** click / dblclick / hover / check / uncheck. */
176
+ function pointer(name) {
177
+ return (setup, actions, locator, original, [options = {}]) => {
178
+ if (options.trial || !(setup.drives("mouse") || setup.drives("scroll")))
179
+ return null;
180
+ const timeout = timeoutOf(locator, options);
181
+ const mouse = setup.drives("mouse");
182
+ return timed(timeout, async () => {
183
+ if (!mouse) {
184
+ await actions.intoView(locator);
185
+ return original(locator, options);
186
+ }
187
+ const checkbox = name === "check" || name === "uncheck";
188
+ if (checkbox &&
189
+ (await locator.isChecked({ timeout })) === (name === "check"))
190
+ return;
191
+ await reach(actions, locator, name, options, timeout);
192
+ if (checkbox &&
193
+ (await locator.isChecked({ timeout })) !== (name === "check"))
194
+ throw new Error(`Clicking the checkbox did not change its state (${name})`);
195
+ });
196
+ };
197
+ }
198
+ /** The click before a fill (driver_defaults), with myuri's move when it drives
199
+ * the mouse. The fill then finds the field focused. */
200
+ async function clickToFocus(setup, actions, locator, options) {
201
+ const timeout = timeoutOf(locator, options);
202
+ if (!(await locator.evaluate(pageFunction(FILL_NEEDS_CLICK), undefined, {
203
+ timeout,
204
+ })))
205
+ return;
206
+ await actions.intoView(locator);
207
+ if ((await locator.evaluate(HIT_TEST_JS, null, { timeout })) !== null)
208
+ return;
209
+ if (setup.drives("mouse"))
210
+ await reach(actions, locator, "click", { force: options.force }, timeout);
211
+ else
212
+ await locatorOriginal(locator, "click")(locator, {
213
+ timeout,
214
+ force: options.force,
215
+ });
216
+ }
217
+ /** fill / type / pressSequentially / press on a locator. */
218
+ function keys(kind) {
219
+ return (setup, actions, locator, original, [text, options = {}]) => {
220
+ const keyboard = setup.drives("keyboard");
221
+ const scroll = kind !== "press" && setup.drives("scroll");
222
+ const mouse = kind === "fill" && setup.drives("mouse");
223
+ if (!(keyboard || mouse || scroll))
224
+ return null;
225
+ return timed(options.timeout, async () => {
226
+ if (scroll)
227
+ await actions.intoView(locator);
228
+ if (kind === "fill")
229
+ await clickToFocus(setup, actions, locator, options);
230
+ if (!keyboard || text === "")
231
+ return original(locator, text, options);
232
+ const { timeout, force } = options;
233
+ // Typing then replaces what the field held, as fill() does.
234
+ if (kind === "fill")
235
+ await locator.selectText({ force, timeout });
236
+ else
237
+ await locator.focus({ timeout });
238
+ return kind === "press" ? actions.key(text) : actions.type(text);
239
+ });
240
+ };
241
+ }
242
+ const scrollLocator = (setup, actions, locator, _original, [options = {}]) => setup.drives("scroll")
243
+ ? timed(options.timeout, () => actions.intoView(locator))
244
+ : null;
245
+ const LOCATOR_FLOWS = {
246
+ click: pointer("click"),
247
+ dblclick: pointer("dblclick"),
248
+ hover: pointer("hover"),
249
+ check: pointer("check"),
250
+ uncheck: pointer("uncheck"),
251
+ fill: keys("fill"),
252
+ type: keys("type"),
253
+ pressSequentially: keys("type"),
254
+ press: keys("press"),
255
+ scrollIntoViewIfNeeded: scrollLocator,
256
+ };
257
+ /** Route a Locator class's input methods through myuri on the locator's page.
258
+ * A page with no humanize setting (any other browser) gets the original. */
259
+ function patchLocatorClass(cls) {
260
+ if (LOCATOR_ORIGINALS.has(cls))
261
+ return;
262
+ const originals = {};
263
+ LOCATOR_ORIGINALS.set(cls, originals);
264
+ for (const [name, flow] of Object.entries(LOCATOR_FLOWS)) {
265
+ const original = cls.prototype[name];
266
+ originals[name] = direct((locator, ...args) => original.apply(locator, args));
267
+ cls.prototype[name] = function (...args) {
268
+ const page = this.page();
269
+ const setup = page?.[SETUP];
270
+ if (!setup)
271
+ return original.apply(this, args);
272
+ return (flow(setup, page[ACTIONS], this, originals[name], args) ??
273
+ originals[name](this, ...args));
274
+ };
275
+ }
276
+ }
277
+ // Page and Frame methods that take a selector, routed to the Locator method of
278
+ // the same name when myuri drives one of these channels.
279
+ const PAGE_ROUTES = {
280
+ click: ["mouse", "scroll"],
281
+ dblclick: ["mouse", "scroll"],
282
+ hover: ["mouse", "scroll"],
283
+ check: ["mouse", "scroll"],
284
+ uncheck: ["mouse", "scroll"],
285
+ fill: ["mouse", "keyboard", "scroll"],
286
+ type: ["keyboard", "scroll"],
287
+ press: ["keyboard"],
288
+ };
289
+ const ROUTES_WITH_TEXT = ["fill", "type", "press"];
290
+ const myuriOn = (setup, channels) => channels.some((channel) => setup?.engines[channel].engine === "myuri");
291
+ function routed(owner, name) {
292
+ const texts = ROUTES_WITH_TEXT.includes(name) ? 1 : 0;
293
+ return (selector, ...rest) => {
294
+ const { strict, ...options } = rest[texts] ?? {};
295
+ const locator = owner.locator(selector);
296
+ // Without strict, Page and Frame methods act on the first match.
297
+ return (strict ? locator : locator.first())[name](...rest.slice(0, texts), options);
298
+ };
299
+ }
300
+ function attachPage(page, setup) {
301
+ if (page[SETUP])
302
+ return;
303
+ const actions = setup.actions(page);
304
+ page[ACTIONS] = actions;
305
+ page[SETUP] = setup;
306
+ patchLocatorClass(page.locator("html").constructor);
307
+ const { mouse, keyboard } = page;
308
+ const o = {
309
+ move: direct(mouse.move.bind(mouse)),
310
+ click: direct(mouse.click.bind(mouse)),
311
+ dblclick: direct(mouse.dblclick.bind(mouse)),
312
+ wheel: direct(mouse.wheel.bind(mouse)),
313
+ type: direct(keyboard.type.bind(keyboard)),
314
+ press: direct(keyboard.press.bind(keyboard)),
315
+ };
316
+ mouse.move = (x, y, options) => {
317
+ if (setup.drives("mouse"))
318
+ return actions.move(x, y);
319
+ actions.moved(x, y);
320
+ return o.move(x, y, options);
321
+ };
322
+ const clicking = (original, double) => (x, y, options = {}) => {
323
+ if (!setup.drives("mouse")) {
324
+ actions.moved(x, y);
325
+ return original(x, y, options);
326
+ }
327
+ const count = double ? 2 : (options.clickCount ?? 1);
328
+ return actions.clickAt(x, y, options.button ?? "left", count);
329
+ };
330
+ mouse.click = clicking(o.click, false);
331
+ mouse.dblclick = clicking(o.dblclick, true);
332
+ // A delay is myuri's to plan.
333
+ mouse.wheel = (dx, dy) => setup.drives("scroll") ? actions.wheel(dx, dy) : o.wheel(dx, dy);
334
+ keyboard.type = (text, options) => setup.drives("keyboard") ? actions.type(text) : o.type(text, options);
335
+ keyboard.press = (key, options) => setup.drives("keyboard") ? actions.key(key) : o.press(key, options);
336
+ // page.click(selector) and friends: the same flow as the locator's.
337
+ for (const [name, channels] of Object.entries(PAGE_ROUTES))
338
+ if (myuriOn(setup, channels))
339
+ page[name] = routed(page, name);
340
+ patchFrameClass(Object.getPrototypeOf(page.mainFrame()));
341
+ }
342
+ /** Route a Frame class's input methods as a page's are, for frames of a page
343
+ * where myuri drives one of the channels. */
344
+ function patchFrameClass(prototype) {
345
+ if (Object.hasOwn(prototype, ROUTED_FRAMES))
346
+ return;
347
+ prototype[ROUTED_FRAMES] = true;
348
+ // Fill's click-first hook stays inside this routing, whichever came first,
349
+ // so myuri plans a fill's click once.
350
+ patchFrameFill(prototype);
351
+ for (const [name, channels] of Object.entries(PAGE_ROUTES)) {
352
+ const original = prototype[name];
353
+ prototype[name] = function (...args) {
354
+ if (scope.getStore()?.inPlaywright ||
355
+ !myuriOn(this.page()?.[SETUP], channels))
356
+ return original.apply(this, args);
357
+ return routed(this, name)(...args);
358
+ };
359
+ }
360
+ }
361
+ function attachContext(context, setup) {
362
+ if (context[SETUP])
363
+ return;
364
+ context[SETUP] = setup;
365
+ context.on("page", (page) => attachPage(page, setup));
366
+ for (const page of context.pages())
367
+ attachPage(page, setup);
368
+ }
369
+ /**
370
+ * In process, Playwright's server answers inside the caller's async context, so
371
+ * an event handler (a popup's, say) would inherit the scope of whichever wrapped
372
+ * call was in flight.
373
+ */
374
+ function isolateDispatch(connection) {
375
+ if (!connection || connection[DISPATCH_ISOLATED])
376
+ return;
377
+ connection[DISPATCH_ISOLATED] = true;
378
+ const { dispatch } = connection;
379
+ connection.dispatch = function (...args) {
380
+ return scope.exit(() => dispatch.apply(this, args));
381
+ };
382
+ }
383
+ /**
384
+ * Run myuri on every page of `target`, a Browser or BrowserContext, including
385
+ * pages and contexts opened later, as the `humanize` setting says. Other
386
+ * browsers in this process are untouched. `os` ("macos", "windows" or
387
+ * "linux") is the launch identity's, whose people myuri plans for.
388
+ * Camoufox()/NewBrowser() call this themselves; for one from `connect()`,
389
+ * launch it without humanize.
390
+ *
391
+ * Every draw comes from one stream, of `humanize.seed` or a random seed, and
392
+ * the seed draws the person myuri plays around `humanize.settings`.
393
+ */
394
+ export function attach(target, humanize, os, iKnowWhatImDoing) {
395
+ const { engines, seed, settings } = normalize(humanize);
396
+ if (CHANNELS.every((channel) => engines[channel].engine === "raw"))
397
+ return target;
398
+ const owner = target;
399
+ if (owner[SETUP])
400
+ throw new Error("humanize is already attached to this browser");
401
+ if (owner._connection?.isRemote())
402
+ LeakWarning.warn(loadWarnings().humanize_remote, iKnowWhatImDoing);
403
+ isolateDispatch(owner._connection);
404
+ const setup = new Setup(engines, seed ?? randomBytes(4).readUInt32BE(), settings, os);
405
+ if (typeof owner.newContext !== "function") {
406
+ // A BrowserContext (a persistent context).
407
+ attachContext(owner, setup);
408
+ return target;
409
+ }
410
+ owner[SETUP] = setup;
411
+ for (const context of owner.contexts())
412
+ attachContext(context, setup);
413
+ const then = {
414
+ newContext: (context) => {
415
+ attachContext(context, setup);
416
+ return context;
417
+ },
418
+ newPage: (page) => {
419
+ attachContext(page.context(), setup);
420
+ attachPage(page, setup);
421
+ return page;
422
+ },
423
+ };
424
+ for (const [name, attach] of Object.entries(then)) {
425
+ const original = owner[name];
426
+ owner[name] = async (...args) => attach(await original.apply(owner, args));
427
+ }
428
+ return target;
429
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Default addons. Each browser release bundles them, extracted, under
3
+ * addons/<name>/ beside its binary (browser/scripts/fetch-ubo.py).
4
+ */
5
+ export declare const DefaultAddons: {
6
+ readonly UBO: "UBO";
7
+ };
8
+ export type DefaultAddon = keyof typeof DefaultAddons;
9
+ /**
10
+ * Confirms that the addon paths are valid.
11
+ */
12
+ export declare function confirmPaths(paths: string[]): void;
13
+ /**
14
+ * Returns the path to the addon the build at executablePath bundles.
15
+ */
16
+ export declare function getAddonPath(addonName: string, executablePath: string): string;
17
+ /**
18
+ * Adds the default addons the build at executablePath bundles, minus any
19
+ * specified in excludeList, to addonsList.
20
+ */
21
+ export declare function addDefaultAddons(addonsList: string[], excludeList: DefaultAddon[] | undefined, executablePath: string): void;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Default Firefox addons: the ones each browser release bundles.
3
+ *
4
+ * TypeScript twin of python/camoucore/src/camoucore/camoufox/addons.py.
5
+ */
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+ import { InvalidAddonPath } from "./exceptions.js";
9
+ import { buildFile } from "./pkgman.js";
10
+ import { loadWarnings, warn } from "./warnings.js";
11
+ /**
12
+ * Default addons. Each browser release bundles them, extracted, under
13
+ * addons/<name>/ beside its binary (browser/scripts/fetch-ubo.py).
14
+ */
15
+ export const DefaultAddons = {
16
+ UBO: "UBO",
17
+ };
18
+ /**
19
+ * Confirms that the addon paths are valid.
20
+ */
21
+ export function confirmPaths(paths) {
22
+ for (const addonPath of paths) {
23
+ if (!fs.existsSync(addonPath) || !fs.statSync(addonPath).isDirectory()) {
24
+ throw new InvalidAddonPath(addonPath);
25
+ }
26
+ if (!fs.existsSync(path.join(addonPath, "manifest.json"))) {
27
+ throw new InvalidAddonPath("manifest.json is missing. Addon path must be a path to an extracted addon.");
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * Returns the path to the addon the build at executablePath bundles.
33
+ */
34
+ export function getAddonPath(addonName, executablePath) {
35
+ return buildFile(executablePath, path.join("addons", addonName));
36
+ }
37
+ /**
38
+ * Adds the default addons the build at executablePath bundles, minus any
39
+ * specified in excludeList, to addonsList.
40
+ */
41
+ export function addDefaultAddons(addonsList, excludeList, executablePath) {
42
+ for (const name of Object.keys(DefaultAddons)) {
43
+ if (excludeList?.includes(name))
44
+ continue;
45
+ const addonPath = getAddonPath(name, executablePath);
46
+ // A build released before the addons were bundled, or an unpackaged
47
+ // one, has none. It still launches, but not as the browser asked for.
48
+ if (!fs.existsSync(path.join(addonPath, "manifest.json"))) {
49
+ warn(loadWarnings()
50
+ .addon_not_bundled.replaceAll("{addon}", name)
51
+ .replace("{path}", addonPath));
52
+ continue;
53
+ }
54
+ addonsList.push(addonPath);
55
+ }
56
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * TypeScript twin of python/camoucore/src/camoucore/camoufox/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 { Camoufox as AsyncCamoufox, 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/camoufox/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 { Camoufox as AsyncCamoufox, NewBrowser as AsyncNewBrowser, NewContext as AsyncNewContext, } from "./sync_api.js";