ant0-browser 0.0.0-stage → 0.1.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.
- package/LICENSE +35 -0
- package/README.md +100 -2
- package/dist/chromium-version.d.ts +22 -0
- package/dist/chromium-version.d.ts.map +1 -0
- package/dist/chromium-version.js +22 -0
- package/dist/chromium-version.js.map +1 -0
- package/dist/download.d.ts +22 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +219 -0
- package/dist/download.js.map +1 -0
- package/dist/fingerprint.d.ts +213 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +375 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/fontpack.d.ts +13 -0
- package/dist/fontpack.d.ts.map +1 -0
- package/dist/fontpack.js +149 -0
- package/dist/fontpack.js.map +1 -0
- package/dist/fonts.d.ts +15 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +86 -0
- package/dist/fonts.js.map +1 -0
- package/dist/geoip.d.ts +45 -0
- package/dist/geoip.d.ts.map +1 -0
- package/dist/geoip.js +289 -0
- package/dist/geoip.js.map +1 -0
- package/dist/geometry.d.ts +28 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +79 -0
- package/dist/geometry.js.map +1 -0
- package/dist/humanize.d.ts +20 -0
- package/dist/humanize.d.ts.map +1 -0
- package/dist/humanize.js +921 -0
- package/dist/humanize.js.map +1 -0
- package/dist/identity-persistence.d.ts +51 -0
- package/dist/identity-persistence.d.ts.map +1 -0
- package/dist/identity-persistence.js +301 -0
- package/dist/identity-persistence.js.map +1 -0
- package/dist/identity.d.ts +43 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +197 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +234 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +593 -0
- package/dist/index.js.map +1 -0
- package/dist/launch-ticket.d.ts +87 -0
- package/dist/launch-ticket.d.ts.map +1 -0
- package/dist/launch-ticket.js +233 -0
- package/dist/launch-ticket.js.map +1 -0
- package/dist/launchopts.d.ts +133 -0
- package/dist/launchopts.d.ts.map +1 -0
- package/dist/launchopts.js +204 -0
- package/dist/launchopts.js.map +1 -0
- package/dist/motion.d.ts +106 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +311 -0
- package/dist/motion.js.map +1 -0
- package/dist/motionscore.d.ts +57 -0
- package/dist/motionscore.d.ts.map +1 -0
- package/dist/motionscore.js +215 -0
- package/dist/motionscore.js.map +1 -0
- package/dist/persona-migration.d.ts +51 -0
- package/dist/persona-migration.d.ts.map +1 -0
- package/dist/persona-migration.js +95 -0
- package/dist/persona-migration.js.map +1 -0
- package/dist/persona-profile-v2.d.ts +155 -0
- package/dist/persona-profile-v2.d.ts.map +1 -0
- package/dist/persona-profile-v2.js +421 -0
- package/dist/persona-profile-v2.js.map +1 -0
- package/dist/population-model.d.ts +42 -0
- package/dist/population-model.d.ts.map +1 -0
- package/dist/population-model.js +224 -0
- package/dist/population-model.js.map +1 -0
- package/dist/release-fetch.d.ts +70 -0
- package/dist/release-fetch.d.ts.map +1 -0
- package/dist/release-fetch.js +392 -0
- package/dist/release-fetch.js.map +1 -0
- package/dist/release.d.ts +16 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +26 -0
- package/dist/release.js.map +1 -0
- package/dist/render.d.ts +38 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +104 -0
- package/dist/render.js.map +1 -0
- package/dist/shaderdialect.d.ts +33 -0
- package/dist/shaderdialect.d.ts.map +1 -0
- package/dist/shaderdialect.js +46 -0
- package/dist/shaderdialect.js.map +1 -0
- package/dist/template-selection.d.ts +14 -0
- package/dist/template-selection.d.ts.map +1 -0
- package/dist/template-selection.js +65 -0
- package/dist/template-selection.js.map +1 -0
- package/dist/warnings.d.ts +19 -0
- package/dist/warnings.d.ts.map +1 -0
- package/dist/warnings.js +159 -0
- package/dist/warnings.js.map +1 -0
- package/dist/widevine.d.ts +44 -0
- package/dist/widevine.d.ts.map +1 -0
- package/dist/widevine.js +202 -0
- package/dist/widevine.js.map +1 -0
- package/package.json +56 -4
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Launch-time option helpers that are NOT fingerprint switches: unpacked-extension loading and
|
|
2
|
+
// proxy resolution. Pure (input -> switches / cleaned proxy) so they're unit-testable and mirror
|
|
3
|
+
// the Python SDK exactly.
|
|
4
|
+
/** Privacy Sandbox + intrusive web APIs a de-Googled stealth build should not expose (a build that
|
|
5
|
+
* claims de-Googled while still answering document.browsingTopics()/navigator.runAdAuction is a
|
|
6
|
+
* self-contradictory, pivotable fingerprint). All are runtime base::Features, so disabling needs
|
|
7
|
+
* no rebuild.
|
|
8
|
+
*
|
|
9
|
+
* WebUSB is deliberately NOT in this list. It is not a Privacy Sandbox feature - it is a device
|
|
10
|
+
* API that ships alongside Web Serial, WebHID and Web Bluetooth under identical secure-context
|
|
11
|
+
* gating. Disabling only WebUSB left navigator.usb absent while serial/hid/bluetooth stayed
|
|
12
|
+
* present, a combination no real Chromium produces; measured against stock Chrome on the same
|
|
13
|
+
* host, that split was the single flagged difference in the device-API family. Presence leaks
|
|
14
|
+
* nothing on its own - the API is permission-gated and enumerates no device without a user
|
|
15
|
+
* gesture - so exposing it costs no privacy and removes a hard coherence tell. */
|
|
16
|
+
export const PRIVACY_SANDBOX_FEATURES = [
|
|
17
|
+
"BrowsingTopics", "BrowsingTopicsDocumentAPI", "Fledge", "InterestGroupStorage",
|
|
18
|
+
"PrivateAggregationApi", "SharedStorageAPI", "FencedFrames",
|
|
19
|
+
];
|
|
20
|
+
/** Chromium honors only the LAST --enable-features / --disable-features on the command line (they
|
|
21
|
+
* do NOT concatenate), so multiple occurrences clobber each other. Collapse all of each into a
|
|
22
|
+
* single flag (order-preserving, de-duped) so defaults from different layers + the user's own flags
|
|
23
|
+
* coexist. */
|
|
24
|
+
export function mergeFeatureFlags(args) {
|
|
25
|
+
const enabled = [];
|
|
26
|
+
const disabled = [];
|
|
27
|
+
const rest = [];
|
|
28
|
+
for (const a of args) {
|
|
29
|
+
if (a.startsWith("--enable-features="))
|
|
30
|
+
enabled.push(...a.slice(18).split(",").filter(Boolean));
|
|
31
|
+
else if (a.startsWith("--disable-features="))
|
|
32
|
+
disabled.push(...a.slice(19).split(",").filter(Boolean));
|
|
33
|
+
else
|
|
34
|
+
rest.push(a);
|
|
35
|
+
}
|
|
36
|
+
const dedupe = (xs) => [...new Set(xs)];
|
|
37
|
+
if (enabled.length)
|
|
38
|
+
rest.push(`--enable-features=${dedupe(enabled).join(",")}`);
|
|
39
|
+
if (disabled.length)
|
|
40
|
+
rest.push(`--disable-features=${dedupe(disabled).join(",")}`);
|
|
41
|
+
return rest;
|
|
42
|
+
}
|
|
43
|
+
/** Disable Privacy Sandbox + intrusive APIs (runtime, no rebuild). */
|
|
44
|
+
export function privacySandboxArgs() {
|
|
45
|
+
return [`--disable-features=${PRIVACY_SANDBOX_FEATURES.join(",")}`];
|
|
46
|
+
}
|
|
47
|
+
/** Behind a proxy, real Chrome cannot use QUIC/HTTP3 (a SOCKS5/HTTP proxy carries only TCP), so it
|
|
48
|
+
* falls back to TCP. Disable QUIC when a proxy is configured so no HTTP/3 UDP is attempted —
|
|
49
|
+
* coherent with proxied Chrome, and a guarantee no UDP egresses around the proxy. No proxy -> leave
|
|
50
|
+
* QUIC on (real Chrome uses it). */
|
|
51
|
+
export function quicArgs(proxy) {
|
|
52
|
+
return proxy && proxy.server ? ["--disable-quic"] : [];
|
|
53
|
+
}
|
|
54
|
+
/** Carry WebRTC's UDP through the SOCKS5 proxy with UDP ASSOCIATE (RFC 1928 §7) instead of letting
|
|
55
|
+
* it egress on the host's own path.
|
|
56
|
+
*
|
|
57
|
+
* This is the transport the {@link webrtcDefaultDenyArgs} note asks for. That default sets
|
|
58
|
+
* `disable_non_proxied_udp`, which on stock Chromium means "no UDP at all", because stock Chromium
|
|
59
|
+
* has no way to proxy a datagram — so peer connections that genuinely need UDP simply fail. With
|
|
60
|
+
* this option the engine opens a UDP association through the proxy and relays every datagram over
|
|
61
|
+
* it, so UDP works AND still leaves from the proxy's address. The two compose: measured against the
|
|
62
|
+
* proxy's own log, the association is established with the deny policy in force, so enabling this
|
|
63
|
+
* does not require weakening the policy.
|
|
64
|
+
*
|
|
65
|
+
* Emitted only for a `socks5://` proxy. UDP ASSOCIATE is a SOCKS5 command — SOCKS4 has no
|
|
66
|
+
* equivalent, and an HTTP proxy carries only TCP — so with any other scheme the switch would be
|
|
67
|
+
* accepted and silently do nothing, which is worse than not sending it.
|
|
68
|
+
*
|
|
69
|
+
* Requires engine support; older binaries ignore the switch. Off by default: it is a real
|
|
70
|
+
* behaviour change (UDP starts flowing where the deny policy previously stopped it), and a proxy
|
|
71
|
+
* that advertises SOCKS5 but refuses ASSOCIATE — common among cheap residential pools — leaves the
|
|
72
|
+
* connection no worse off but no better either. */
|
|
73
|
+
export function socks5UdpArgs(socks5Udp, proxy) {
|
|
74
|
+
if (socks5Udp !== true)
|
|
75
|
+
return [];
|
|
76
|
+
const server = (proxy?.server ?? "").trim();
|
|
77
|
+
return /^socks5/i.test(server) ? ["--socks5-udp"] : [];
|
|
78
|
+
}
|
|
79
|
+
/** Default WebRTC to disable_non_proxied_udp, so no UDP can egress around the proxy.
|
|
80
|
+
*
|
|
81
|
+
* This used to be skipped whenever `webrtcIp` was set, on the theory that the engine's srflx
|
|
82
|
+
* fabrication already covered WebRTC. It does not — the two defend different things:
|
|
83
|
+
*
|
|
84
|
+
* - fabrication rewrites what the browser *reports*, which beats a page that reads the candidate;
|
|
85
|
+
* - this policy stops UDP *leaving the machine*, which beats a server that watches where packets
|
|
86
|
+
* arrive from.
|
|
87
|
+
*
|
|
88
|
+
* A page that sets `iceTransportPolicy: "relay"` forces the browser to talk to its own TURN server.
|
|
89
|
+
* TURN prefers UDP and an HTTP/SOCKS proxy carries only TCP, so that UDP left on the host's own
|
|
90
|
+
* path and the TURN server read the real public address straight off the packet — no candidate
|
|
91
|
+
* involved, so fabricating one changed nothing. Reported by a customer whose session was flagged
|
|
92
|
+
* for location spoofing with an otherwise perfectly coherent persona.
|
|
93
|
+
*
|
|
94
|
+
* Worse, `geoip: true` sets `webrtcIp` for you, so the more carefully a caller configured for
|
|
95
|
+
* coherence the more likely they had silently lost this. Now only an explicit policy from the
|
|
96
|
+
* caller suppresses it.
|
|
97
|
+
*
|
|
98
|
+
* Note this is a real trade-off, not a free win: denying non-proxied UDP means peer connections
|
|
99
|
+
* that genuinely need UDP will not establish. Callers who need working WebRTC through a proxy want
|
|
100
|
+
* a transport that actually carries UDP (SOCKS5 with UDP ASSOCIATE, or a full tunnel) and can set
|
|
101
|
+
* their own policy to opt out. */
|
|
102
|
+
/**
|
|
103
|
+
* Switches to expose `navigator.bluetooth` on Linux hosts (empty elsewhere).
|
|
104
|
+
*
|
|
105
|
+
* Web Bluetooth is compiled into the engine but runtime-disabled on Linux only:
|
|
106
|
+
* Chromium's runtime_enabled_features.json5 gives WebBluetooth status "stable" on Win/Mac/Android/
|
|
107
|
+
* ChromeOS and lets Linux fall through to "default": "experimental", and content_features.cc
|
|
108
|
+
* declares kWebBluetooth FEATURE_DISABLED_BY_DEFAULT. So a Linux host serving a Windows persona
|
|
109
|
+
* reports navigator.usb, navigator.serial and navigator.hid but NOT navigator.bluetooth - a
|
|
110
|
+
* combination no real Windows Chrome produces, and an OS-origin tell that survives every string
|
|
111
|
+
* spoof. One flag restores it on the shipped binary; no rebuild is involved.
|
|
112
|
+
*
|
|
113
|
+
* Verified against Chromium 150's bluetooth.idl: getDevices() is gated on WebBluetoothGetDevices
|
|
114
|
+
* and requestLEScan()/onadvertisementreceived on WebBluetoothScanning, both "experimental", so
|
|
115
|
+
* real stable Chrome exposes exactly {constructor, getAvailability, requestDevice} - which is what
|
|
116
|
+
* this flag produces. getAvailability() resolves false and requestDevice() rejects NotFoundError
|
|
117
|
+
* on a machine with no adapter, matching a real desktop without Bluetooth hardware.
|
|
118
|
+
*/
|
|
119
|
+
export function webBluetoothArgs() {
|
|
120
|
+
if (process.platform !== "linux")
|
|
121
|
+
return []; // Win/Mac ship it stable
|
|
122
|
+
return ["--enable-features=WebBluetooth"];
|
|
123
|
+
}
|
|
124
|
+
export function webrtcDefaultDenyArgs(args, _webrtcIp) {
|
|
125
|
+
if (args.some((a) => a.startsWith("--webrtc-ip-handling-policy") || a.startsWith("--force-webrtc-ip-handling-policy"))) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
return ["--webrtc-ip-handling-policy=disable_non_proxied_udp"];
|
|
129
|
+
}
|
|
130
|
+
/** Switches to load unpacked extensions. Chromium needs BOTH --load-extension=<dirs> and
|
|
131
|
+
* --disable-extensions-except=<dirs> (the latter keeps the listed extensions enabled while
|
|
132
|
+
* everything else stays off). `paths` is a list of unpacked-extension directories. */
|
|
133
|
+
export function extensionArgs(paths) {
|
|
134
|
+
if (!paths || paths.length === 0)
|
|
135
|
+
return [];
|
|
136
|
+
const joined = paths.join(",");
|
|
137
|
+
return [`--load-extension=${joined}`, `--disable-extensions-except=${joined}`];
|
|
138
|
+
}
|
|
139
|
+
/** First-run/UX hygiene switches for a DIRECT launch (`serve()` / `launchPlan()`).
|
|
140
|
+
*
|
|
141
|
+
* Playwright adds these itself on `launch()`, so a Playwright-driven browser never shows the
|
|
142
|
+
* first-run UI. A direct spawn gets none of that, and the ungoogled-chromium base then opens
|
|
143
|
+
* `chrome://ungoogled-first-run` ("ungoogled-chromium first run page", empty body) in the first
|
|
144
|
+
* tab whenever the caller passes no start URL, plus the default-browser prompt and the search
|
|
145
|
+
* engine choice screen in headed mode. These are plain UI switches, not `base::Feature` toggles:
|
|
146
|
+
* they change nothing a page can observe, so the identity layer (which owns
|
|
147
|
+
* `--enable-features`/`--disable-features`) is not affected and the coherence checker does not
|
|
148
|
+
* flag them. */
|
|
149
|
+
export const FIRST_RUN_HYGIENE_ARGS = [
|
|
150
|
+
"--no-first-run",
|
|
151
|
+
"--no-default-browser-check",
|
|
152
|
+
"--disable-search-engine-choice-screen",
|
|
153
|
+
];
|
|
154
|
+
/** True when `args` carries a positional (non-switch) argument, which Chromium opens as a URL.
|
|
155
|
+
* Everything after a literal `--` is positional by Chromium's command-line rules. */
|
|
156
|
+
export function hasUrlPositional(args) {
|
|
157
|
+
let afterSeparator = false;
|
|
158
|
+
for (const a of args) {
|
|
159
|
+
if (afterSeparator)
|
|
160
|
+
return true;
|
|
161
|
+
if (a === "--") {
|
|
162
|
+
afterSeparator = true;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (!a.startsWith("-"))
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
/** The neutral start page for a direct launch with no caller URL: `about:blank` as the final
|
|
171
|
+
* positional, so the first tab is blank instead of the ungoogled first-run page. Empty when the
|
|
172
|
+
* caller already supplied a URL positional (Chromium would open both otherwise). */
|
|
173
|
+
export function defaultStartUrlArgs(args) {
|
|
174
|
+
return hasUrlPositional(args) ? [] : ["about:blank"];
|
|
175
|
+
}
|
|
176
|
+
/** Message thrown for a SOCKS proxy descriptor that carries `username`/`password`. Exported so the
|
|
177
|
+
* tests and the Python SDK's mirror can assert on the same wording. */
|
|
178
|
+
export const SOCKS_CREDENTIALS_UNSUPPORTED = "SOCKS proxy with username/password is not supported: the engine does not authenticate to " +
|
|
179
|
+
"SOCKS5 proxies (Chromium has no RFC 1929 username/password client), and Playwright rejects " +
|
|
180
|
+
"credentials in a SOCKS proxy descriptor. Either use an http(s):// proxy with credentials " +
|
|
181
|
+
"(Playwright handles those), a SOCKS5 proxy that allows this client's IP without credentials, " +
|
|
182
|
+
"or run a local relay (as ant0d does) that authenticates upstream and point `proxy.server` at " +
|
|
183
|
+
"it without credentials.";
|
|
184
|
+
/** Resolve a Playwright proxy descriptor into `{ args, proxy }`.
|
|
185
|
+
*
|
|
186
|
+
* Every proxy shape is left to Playwright unchanged, except a SOCKS proxy WITH credentials, which
|
|
187
|
+
* throws: neither Playwright (it rejects credentials in a SOCKS descriptor) nor the engine (stock
|
|
188
|
+
* Chromium has no RFC 1929 client, and no ant0-browser patch adds one) can authenticate to it, so
|
|
189
|
+
* a launch would silently produce a proxy that refuses every connection. Callers needing a
|
|
190
|
+
* credentialed SOCKS5 upstream run a local relay and hand the SDK its unauthenticated loopback
|
|
191
|
+
* address instead. Userinfo inside the URL (`socks5://user:pass@host:port`) counts as credentials
|
|
192
|
+
* too: Chromium would drop it silently. */
|
|
193
|
+
export function resolveProxy(proxy) {
|
|
194
|
+
if (!proxy || typeof proxy !== "object")
|
|
195
|
+
return { args: [], proxy };
|
|
196
|
+
const server = (proxy.server ?? "").trim();
|
|
197
|
+
// Credentials as fields, or as userinfo inside the URL: Chromium ignores the latter silently.
|
|
198
|
+
const hasCreds = !!(proxy.username || proxy.password) || /^[a-zA-Z0-9+.-]+:\/\/[^/@]*@/.test(server);
|
|
199
|
+
if (server && /^socks/i.test(server) && hasCreds) {
|
|
200
|
+
throw new Error(SOCKS_CREDENTIALS_UNSUPPORTED);
|
|
201
|
+
}
|
|
202
|
+
return { args: [], proxy };
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=launchopts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchopts.js","sourceRoot":"","sources":["../src/launchopts.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,iGAAiG;AACjG,0BAA0B;AAU1B;;;;;;;;;;;kFAWkF;AAClF,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,gBAAgB,EAAE,2BAA2B,EAAE,QAAQ,EAAE,sBAAsB;IAC/E,uBAAuB,EAAE,kBAAkB,EAAE,cAAc;CACnD,CAAC;AAEX;;;cAGc;AACd,MAAM,UAAU,iBAAiB,CAAC,IAAc;IAC9C,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAa,E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AAC;IACrG,IAAI,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/motion.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** A deterministic 0..1 RNG (mulberry32). Same seed ⇒ same stream, so a persona/trajectory is
|
|
2
|
+
* reproducible in tests; production paths pass a fresh unseeded RNG for live micro-variation. */
|
|
3
|
+
export type Rng = () => number;
|
|
4
|
+
export declare function mulberry32(seedInt: number): Rng;
|
|
5
|
+
/** FNV-1a hash of an arbitrary seed (string or number) to a 32-bit int for the persona RNG. */
|
|
6
|
+
export declare function hashSeed(seed: string | number | undefined): number;
|
|
7
|
+
/** Standard-normal sample (Box–Muller) from a given RNG. */
|
|
8
|
+
export declare function gaussFrom(rng: Rng): number;
|
|
9
|
+
/** The per-identity motor signature. All ranges are chosen to sit inside measured human envelopes. */
|
|
10
|
+
export interface Persona {
|
|
11
|
+
seed: number;
|
|
12
|
+
/** Cursor sampling cadence (Hz) → step spacing ≈ 1000/deviceHz ms (real mice: 125–1000 Hz). */
|
|
13
|
+
deviceHz: number;
|
|
14
|
+
/** Physiological tremor frequency (Hz), band 8–12. */
|
|
15
|
+
tremorHz: number;
|
|
16
|
+
/** Tremor amplitude (px). */
|
|
17
|
+
tremorAmp: number;
|
|
18
|
+
/** OU drift amplitude (px) — slow low-frequency wander. */
|
|
19
|
+
driftAmp: number;
|
|
20
|
+
/** OU drift correlation time (ms). */
|
|
21
|
+
driftTau: number;
|
|
22
|
+
/** Base per-sample gaussian jitter (px). */
|
|
23
|
+
jitter: number;
|
|
24
|
+
/** Fitts intercept a (ms) and slope b (ms/bit). */
|
|
25
|
+
fittsA: number;
|
|
26
|
+
fittsB: number;
|
|
27
|
+
/** Fraction of the gap the primary ballistic submovement covers (0.84–0.94). */
|
|
28
|
+
primaryFrac: number;
|
|
29
|
+
/** Overshoot scale as a fraction of distance for the primary landing. */
|
|
30
|
+
overshoot: number;
|
|
31
|
+
/** Max corrective submovements after the primary (1–2, occasionally 3). */
|
|
32
|
+
maxCorrections: number;
|
|
33
|
+
/** Handedness/approach curvature bias (signed, radians-ish) applied to path bow. */
|
|
34
|
+
approachBias: number;
|
|
35
|
+
/** Grab hesitation window after mouse.down (ms). */
|
|
36
|
+
grabMinMs: number;
|
|
37
|
+
grabMaxMs: number;
|
|
38
|
+
/** Pre-release settle window before mouse.up (ms). */
|
|
39
|
+
releaseMinMs: number;
|
|
40
|
+
releaseMaxMs: number;
|
|
41
|
+
/** Click press-hold window — mousedown→mouseup (ms). Human ~60–150; a scripted click is ~2 ms. */
|
|
42
|
+
clickHoldMinMs: number;
|
|
43
|
+
clickHoldMaxMs: number;
|
|
44
|
+
/** Per-key dwell window — keydown→keyup (ms). Human ~45–120 (right-skewed); scripted typing ~2–3 ms. */
|
|
45
|
+
keyDwellMinMs: number;
|
|
46
|
+
keyDwellMaxMs: number;
|
|
47
|
+
}
|
|
48
|
+
/** Derive a stable motor persona from a fingerprint seed (or random when unseeded). */
|
|
49
|
+
export declare function makePersona(seed?: string | number): Persona;
|
|
50
|
+
/** A human mousedown→mouseup click hold (ms), right-skewed (most clicks brief, some linger). Fixes
|
|
51
|
+
* the ~2 ms instant-press tell shared by clicks. */
|
|
52
|
+
export declare function clickHold(p: Persona, rng?: Rng): number;
|
|
53
|
+
/** A human per-key keydown→keyup dwell (ms), right-skewed (a floor + occasional longer holds — the
|
|
54
|
+
* empirical human dwell shape). Fixes the ~2–3 ms instant-keystroke tell. */
|
|
55
|
+
export declare function keyDwell(p: Persona, rng?: Rng): number;
|
|
56
|
+
export interface Point {
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
59
|
+
}
|
|
60
|
+
/** One dispatched sample: move the cursor to (x,y), then sleep `sleepMs` before the next. */
|
|
61
|
+
export interface Step {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
sleepMs: number;
|
|
65
|
+
}
|
|
66
|
+
export interface PlanOpts {
|
|
67
|
+
/** Target width/height (px) for the Fitts duration + click-point spread. Defaults ~24. */
|
|
68
|
+
targetW?: number;
|
|
69
|
+
targetH?: number;
|
|
70
|
+
/** Append a tiny 1–2 px settling jiggle at the end (used for slider/drag seating). */
|
|
71
|
+
settle?: boolean;
|
|
72
|
+
/** RNG for live micro-variation. Defaults to Math.random (non-reproducible). Pass a seeded Rng in tests. */
|
|
73
|
+
rng?: Rng;
|
|
74
|
+
}
|
|
75
|
+
/** Minimum-jerk easing s(τ)=10τ³−15τ⁴+6τ⁵ (position fraction; speed 30τ²(1−τ)²). */
|
|
76
|
+
export declare function minJerk(tau: number): number;
|
|
77
|
+
/**
|
|
78
|
+
* Plan a free cursor move `from`→`to` as a sum of minimum-jerk submovements (primary + corrections)
|
|
79
|
+
* with Fitts-scaled duration and colored noise. Returns the samples to dispatch.
|
|
80
|
+
*/
|
|
81
|
+
export declare function planMove(from: Point, to: Point, p: Persona, opts?: PlanOpts): Step[];
|
|
82
|
+
/** Grab/release dwell times (ms) for a held-button drag, drawn from the persona window. */
|
|
83
|
+
export declare function dragDwell(p: Persona, rng?: Rng): {
|
|
84
|
+
grabMs: number;
|
|
85
|
+
releaseMs: number;
|
|
86
|
+
};
|
|
87
|
+
export interface Box {
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
width: number;
|
|
91
|
+
height: number;
|
|
92
|
+
}
|
|
93
|
+
/** A human click point inside `box`: a 2D gaussian around center, nudged toward the approach side
|
|
94
|
+
* (people undershoot toward where the cursor came from), clamped a couple px inside the edges. */
|
|
95
|
+
export declare function clickPoint(box: Box, from: Point, p: Persona, rng?: Rng): Point;
|
|
96
|
+
export interface Viewport {
|
|
97
|
+
width: number;
|
|
98
|
+
height: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Plan ambient / pre-challenge cursor activity: idle drift + a few non-goal moves within the viewport,
|
|
102
|
+
* so a behavioral collector sees non-zero pointer entropy BEFORE the first goal action (the single
|
|
103
|
+
* biggest reason a challenge/slider is shown to headless automation). Returns ~`ms` of samples.
|
|
104
|
+
*/
|
|
105
|
+
export declare function planAmbient(from: Point, vp: Viewport, p: Persona, ms: number, rng?: Rng): Step[];
|
|
106
|
+
//# sourceMappingURL=motion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion.d.ts","sourceRoot":"","sources":["../src/motion.ts"],"names":[],"mappings":"AA6BA;iGACiG;AACjG,MAAM,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC;AAE/B,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAQ/C;AAED,+FAA+F;AAC/F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAUlE;AAED,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAK1C;AAED,sGAAsG;AACtG,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,+FAA+F;IAC/F,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,WAAW,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,SAAS,EAAE,MAAM,CAAC;IAClB,2EAA2E;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gB,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,GAAE,QAAa,GAAG,IAAI,EAAE,CAwExF;AAED,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,GAAE,GAAiB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAKnG;AAED,MAAM,WAAW,GAAG;IAAG,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;CAAE;AAE7E;kGACkG;AAClG,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,GAAE,GAAiB,GAAG,KAAK,CAe3F;AAED,MAAM,WAAW,QAAQ;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;CAAE;AAE5D;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAE,GAAiB,GAAG,IAAI,EAAE,CAiC7G"}
|
package/dist/motion.js
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Human motion core — the trajectory/timing model shared by every humanized input path.
|
|
2
|
+
//
|
|
3
|
+
// PURE (no Playwright, no I/O): given a start point, a target, and a seeded `Persona`, it returns a
|
|
4
|
+
// list of `Step`s (absolute cursor coordinates + a post-step sleep). The wrapper (humanize.ts)
|
|
5
|
+
// walks the steps with the engine's NATIVE mouse.move + an off-protocol sleep, so the whole path is
|
|
6
|
+
// trusted input. Keeping the math here (a) unifies Node/Python so they can't drift, (b) makes it
|
|
7
|
+
// unit-testable offline, and (c) lets motionscore.ts score generated paths without a browser.
|
|
8
|
+
//
|
|
9
|
+
// Model — why these choices (mapped to what behavioral collectors actually measure):
|
|
10
|
+
// • Minimum-jerk submovements. A human reach is a primary ballistic submovement plus 1–2 corrective
|
|
11
|
+
// ones (Meyer's optimized-submovement model), each following the minimum-jerk profile
|
|
12
|
+
// s(τ)=10τ³−15τ⁴+6τ⁵ (speed 30τ²(1−τ)², peaking at τ=0.5). Composing them yields the mid-path
|
|
13
|
+
// velocity peak, the decelerating Fitts homing phase, and natural overshoot→correction reversals —
|
|
14
|
+
// none of which a single ease curve produces. (A single bezier peaks at the wrong place and has
|
|
15
|
+
// exactly one submovement — a structural tell.)
|
|
16
|
+
// • Fitts's law duration. Movement time = a + b·log2(D/W+1), not ∝ distance, so duration is
|
|
17
|
+
// statistically human across short-big vs long-small targets (a distribution detectors check).
|
|
18
|
+
// • Colored noise. Sub-pixel jitter = slow Ornstein–Uhlenbeck drift + a band-limited 8–12 Hz
|
|
19
|
+
// physiological tremor, not flat white gauss (whose flat spectrum is itself detectable).
|
|
20
|
+
// • Seeded persona. One motor signature (mean speed, tremor, overshoot, handedness bias, cadence)
|
|
21
|
+
// is drawn per identity from the fingerprint seed, so behavior is consistent WITHIN a session and
|
|
22
|
+
// unlinkable across seeds — the same coherence model as the rest of the persona.
|
|
23
|
+
// • Endpoint dwells. Grab hesitation after mouse.down and a pre-release settle before mouse.up (the
|
|
24
|
+
// two worst slider tells: real ~130–360 ms grab / ~90–230 ms release vs a scripted few ms).
|
|
25
|
+
//
|
|
26
|
+
// NOTE on the 2/3 power law: it governs continuous CURVED drawing, not discrete point-to-point
|
|
27
|
+
// reaches, so imposing it on a reach would corrupt the min-jerk profile. We deliberately do NOT apply
|
|
28
|
+
// it during generation; motionscore.ts reports power-law residual only as a diagnostic.
|
|
29
|
+
export function mulberry32(seedInt) {
|
|
30
|
+
let a = seedInt >>> 0;
|
|
31
|
+
return () => {
|
|
32
|
+
a = (a + 0x6d2b79f5) | 0;
|
|
33
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
34
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
35
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** FNV-1a hash of an arbitrary seed (string or number) to a 32-bit int for the persona RNG. */
|
|
39
|
+
export function hashSeed(seed) {
|
|
40
|
+
if (seed === undefined || seed === null)
|
|
41
|
+
return (Math.random() * 0xffffffff) >>> 0;
|
|
42
|
+
if (typeof seed === "number" && Number.isFinite(seed))
|
|
43
|
+
return (Math.abs(seed) * 2654435761) >>> 0;
|
|
44
|
+
const s = String(seed);
|
|
45
|
+
let h = 0x811c9dc5;
|
|
46
|
+
for (let i = 0; i < s.length; i++) {
|
|
47
|
+
h ^= s.charCodeAt(i);
|
|
48
|
+
h = Math.imul(h, 0x01000193);
|
|
49
|
+
}
|
|
50
|
+
return h >>> 0;
|
|
51
|
+
}
|
|
52
|
+
/** Standard-normal sample (Box–Muller) from a given RNG. */
|
|
53
|
+
export function gaussFrom(rng) {
|
|
54
|
+
let u = 0, v = 0;
|
|
55
|
+
while (u === 0)
|
|
56
|
+
u = rng();
|
|
57
|
+
while (v === 0)
|
|
58
|
+
v = rng();
|
|
59
|
+
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
|
|
60
|
+
}
|
|
61
|
+
const lerp = (a, b, t) => a + (b - a) * t;
|
|
62
|
+
/** Derive a stable motor persona from a fingerprint seed (or random when unseeded). */
|
|
63
|
+
export function makePersona(seed) {
|
|
64
|
+
const seedInt = hashSeed(seed);
|
|
65
|
+
const r = mulberry32(seedInt);
|
|
66
|
+
return {
|
|
67
|
+
seed: seedInt,
|
|
68
|
+
deviceHz: Math.round(lerp(110, 155, r())),
|
|
69
|
+
tremorHz: lerp(8, 12, r()),
|
|
70
|
+
tremorAmp: lerp(0.12, 0.5, r()),
|
|
71
|
+
driftAmp: lerp(0.1, 0.4, r()),
|
|
72
|
+
driftTau: lerp(60, 160, r()),
|
|
73
|
+
jitter: lerp(0.25, 0.7, r()),
|
|
74
|
+
fittsA: lerp(90, 150, r()),
|
|
75
|
+
fittsB: lerp(120, 190, r()),
|
|
76
|
+
primaryFrac: lerp(0.84, 0.94, r()),
|
|
77
|
+
overshoot: lerp(0.03, 0.08, r()),
|
|
78
|
+
maxCorrections: r() < 0.15 ? 3 : r() < 0.6 ? 2 : 1,
|
|
79
|
+
approachBias: (r() - 0.5) * 0.5,
|
|
80
|
+
grabMinMs: 130,
|
|
81
|
+
grabMaxMs: 360,
|
|
82
|
+
releaseMinMs: 90,
|
|
83
|
+
releaseMaxMs: 230,
|
|
84
|
+
clickHoldMinMs: 60,
|
|
85
|
+
clickHoldMaxMs: 150,
|
|
86
|
+
keyDwellMinMs: 45,
|
|
87
|
+
keyDwellMaxMs: 120,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** A human mousedown→mouseup click hold (ms), right-skewed (most clicks brief, some linger). Fixes
|
|
91
|
+
* the ~2 ms instant-press tell shared by clicks. */
|
|
92
|
+
export function clickHold(p, rng = Math.random) {
|
|
93
|
+
return p.clickHoldMinMs + Math.min(1, Math.abs(gaussFrom(rng)) * 0.5) * (p.clickHoldMaxMs - p.clickHoldMinMs);
|
|
94
|
+
}
|
|
95
|
+
/** A human per-key keydown→keyup dwell (ms), right-skewed (a floor + occasional longer holds — the
|
|
96
|
+
* empirical human dwell shape). Fixes the ~2–3 ms instant-keystroke tell. */
|
|
97
|
+
export function keyDwell(p, rng = Math.random) {
|
|
98
|
+
return p.keyDwellMinMs + Math.min(1, Math.abs(gaussFrom(rng)) * 0.45) * (p.keyDwellMaxMs - p.keyDwellMinMs);
|
|
99
|
+
}
|
|
100
|
+
const log2 = (x) => Math.log(x) / Math.LN2;
|
|
101
|
+
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
|
|
102
|
+
/** Cubic bezier point at parameter e (0..1). */
|
|
103
|
+
function bez(p0, c1, c2, p1, e) {
|
|
104
|
+
const m = 1 - e;
|
|
105
|
+
return m * m * m * p0 + 3 * m * m * e * c1 + 3 * m * e * e * c2 + e * e * e * p1;
|
|
106
|
+
}
|
|
107
|
+
/** Minimum-jerk easing s(τ)=10τ³−15τ⁴+6τ⁵ (position fraction; speed 30τ²(1−τ)²). */
|
|
108
|
+
export function minJerk(tau) {
|
|
109
|
+
const t = clamp(tau, 0, 1);
|
|
110
|
+
return t * t * t * (10 + t * (-15 + 6 * t));
|
|
111
|
+
}
|
|
112
|
+
/** Sample ONE min-jerk submovement a→b along a slightly bowed path, adding colored noise. Appends to
|
|
113
|
+
* `out`. `t0` is the absolute clock (ms) at the start (for tremor phase continuity). Returns the
|
|
114
|
+
* absolute clock at the end. `land` = put the final sample exactly on b with no noise. */
|
|
115
|
+
function sampleSubmove(out, a, b, durMs, p, rng, t0, drift, jit, tremorPhase, land) {
|
|
116
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
117
|
+
const dist = Math.hypot(dx, dy) || 1e-6;
|
|
118
|
+
const stepMs = 1000 / p.deviceHz;
|
|
119
|
+
// Cap the sample count so a very long move can't emit thousands of steps (defends the Fitts cap).
|
|
120
|
+
const n = Math.min(180, Math.max(4, Math.round(durMs / stepMs)));
|
|
121
|
+
// perpendicular unit for the path bow; sign follows the persona's handedness bias
|
|
122
|
+
const nx = -dy / dist, ny = dx / dist;
|
|
123
|
+
const bowSign = p.approachBias >= 0 ? 1 : -1;
|
|
124
|
+
const bow = bowSign * (0.04 + Math.abs(gaussFrom(rng)) * 0.05) * Math.min(dist, 260) * (0.5 + Math.abs(p.approachBias));
|
|
125
|
+
const c1x = a.x + dx * 0.33 + nx * bow, c1y = a.y + dy * 0.33 + ny * bow;
|
|
126
|
+
const c2x = a.x + dx * 0.66 + nx * bow, c2y = a.y + dy * 0.66 + ny * bow;
|
|
127
|
+
let t = t0;
|
|
128
|
+
for (let i = 1; i <= n; i++) {
|
|
129
|
+
const e = minJerk(i / n);
|
|
130
|
+
let px = bez(a.x, c1x, c2x, b.x, e);
|
|
131
|
+
let py = bez(a.y, c1y, c2y, b.y, e);
|
|
132
|
+
const last = i === n;
|
|
133
|
+
if (!(last && land)) {
|
|
134
|
+
// Ornstein–Uhlenbeck drift (colored, low-frequency)
|
|
135
|
+
const k = stepMs / p.driftTau;
|
|
136
|
+
drift.x += -k * drift.x + Math.sqrt(2 * k) * p.driftAmp * gaussFrom(rng);
|
|
137
|
+
drift.y += -k * drift.y + Math.sqrt(2 * k) * p.driftAmp * gaussFrom(rng);
|
|
138
|
+
// 8–12 Hz physiological tremor: absolute-clock phase (continuous across submovements), a slow
|
|
139
|
+
// amplitude "breathing", and a slightly DETUNED/phase-offset y axis — real tremor is not a
|
|
140
|
+
// fixed-amplitude tone locked in exact 90° quadrature.
|
|
141
|
+
const tAmp = p.tremorAmp * (0.7 + 0.3 * Math.sin((2 * Math.PI * t) / 850 + tremorPhase));
|
|
142
|
+
const trX = tAmp * Math.sin(tremorPhase + (2 * Math.PI * p.tremorHz * t) / 1000);
|
|
143
|
+
const trY = tAmp * Math.sin(tremorPhase + 1.0 + (2 * Math.PI * (p.tremorHz * 0.93) * t) / 1000);
|
|
144
|
+
// Sub-pixel jitter as a COLORED AR(1) process, not i.i.d. white noise — white noise adds a fresh
|
|
145
|
+
// speed reversal every sample, manufacturing spurious "submovements" and a flat noise spectrum.
|
|
146
|
+
jit.x = 0.7 * jit.x + gaussFrom(rng) * p.jitter * 0.22;
|
|
147
|
+
jit.y = 0.7 * jit.y + gaussFrom(rng) * p.jitter * 0.22;
|
|
148
|
+
px += drift.x + trX + jit.x;
|
|
149
|
+
py += drift.y + trY + jit.y;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
px = b.x;
|
|
153
|
+
py = b.y;
|
|
154
|
+
}
|
|
155
|
+
// device sampling is quite regular (a sharp cadence mode); keep per-sample jitter small so the
|
|
156
|
+
// dt distribution has a mode, unlike a rand(a,b) band. Pauses come from the inter-submovement gap.
|
|
157
|
+
const sleepMs = stepMs * lerp(0.88, 1.12, rng());
|
|
158
|
+
out.push({ x: px, y: py, sleepMs });
|
|
159
|
+
t += sleepMs;
|
|
160
|
+
}
|
|
161
|
+
return t;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Plan a free cursor move `from`→`to` as a sum of minimum-jerk submovements (primary + corrections)
|
|
165
|
+
* with Fitts-scaled duration and colored noise. Returns the samples to dispatch.
|
|
166
|
+
*/
|
|
167
|
+
export function planMove(from, to, p, opts = {}) {
|
|
168
|
+
const rng = opts.rng ?? Math.random;
|
|
169
|
+
const W = Math.max(6, opts.targetW ?? 24);
|
|
170
|
+
const D = Math.hypot(to.x - from.x, to.y - from.y);
|
|
171
|
+
const out = [];
|
|
172
|
+
if (D < 1.5) {
|
|
173
|
+
out.push({ x: to.x, y: to.y, sleepMs: 1000 / p.deviceHz });
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
// Fitts movement time (ms) + a little log-normal-ish noise; short hops get a small floor. The floor
|
|
177
|
+
// is itself capped at the 1700 ms ceiling so a very long move can't invert the clamp (lo > hi) and
|
|
178
|
+
// silently blow past the cap.
|
|
179
|
+
const id = log2(D / W + 1);
|
|
180
|
+
const mtLo = Math.min(1700, Math.max(70, 40 + D * 0.6));
|
|
181
|
+
const mt = clamp((p.fittsA + p.fittsB * id) * (0.85 + 0.3 * rng()), mtLo, 1700);
|
|
182
|
+
// Submovement targets: primary lands near `to` with a small over/undershoot; corrections close the
|
|
183
|
+
// residual error, each covering ~55–80% of what's left.
|
|
184
|
+
const targets = [];
|
|
185
|
+
if (D >= 40) {
|
|
186
|
+
const f = p.primaryFrac;
|
|
187
|
+
const spread = Math.min(16, D * p.overshoot);
|
|
188
|
+
targets.push({
|
|
189
|
+
x: from.x + (to.x - from.x) * f + gaussFrom(rng) * spread,
|
|
190
|
+
y: from.y + (to.y - from.y) * f + gaussFrom(rng) * spread,
|
|
191
|
+
});
|
|
192
|
+
// 1 correction usually, occasionally 2 (a 3rd is rare) — keeps the corrective-submovement count
|
|
193
|
+
// in the human 1–3 band rather than over-generating homing bumps.
|
|
194
|
+
const nCorr = rng() < 0.08 * p.maxCorrections ? 2 : 1;
|
|
195
|
+
let cur = targets[0];
|
|
196
|
+
for (let i = 0; i < nCorr; i++) {
|
|
197
|
+
const close = lerp(0.55, 0.8, rng());
|
|
198
|
+
const nx = { x: cur.x + (to.x - cur.x) * close, y: cur.y + (to.y - cur.y) * close };
|
|
199
|
+
// tiny lateral error so corrections aren't perfectly collinear
|
|
200
|
+
nx.x += gaussFrom(rng) * 1.2;
|
|
201
|
+
nx.y += gaussFrom(rng) * 1.2;
|
|
202
|
+
targets.push(nx);
|
|
203
|
+
cur = nx;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
targets.push({ x: to.x, y: to.y });
|
|
207
|
+
// Allocate MT: primary ~62%, remaining split across corrections (each shorter).
|
|
208
|
+
const segDur = [];
|
|
209
|
+
if (targets.length === 1) {
|
|
210
|
+
segDur.push(mt);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
// Primary gets ~78% of the time (min-jerk peaks at its own mid-point ⇒ global peak lands ~0.35–0.4,
|
|
214
|
+
// the human sweet spot slightly before the whole-gesture midpoint), corrections share the rest.
|
|
215
|
+
segDur.push(mt * 0.78);
|
|
216
|
+
const rest = mt * 0.22;
|
|
217
|
+
const nc = targets.length - 1;
|
|
218
|
+
for (let i = 0; i < nc; i++)
|
|
219
|
+
segDur.push((rest / nc) * lerp(0.8, 1.2, rng()));
|
|
220
|
+
}
|
|
221
|
+
const drift = { x: 0, y: 0 };
|
|
222
|
+
const jit = { x: 0, y: 0 };
|
|
223
|
+
const tremorPhase = rng() * 2 * Math.PI;
|
|
224
|
+
let a = from, t = 0;
|
|
225
|
+
for (let s = 0; s < targets.length; s++) {
|
|
226
|
+
const b = targets[s];
|
|
227
|
+
const last = s === targets.length - 1;
|
|
228
|
+
t = sampleSubmove(out, a, b, Math.max(20, segDur[s]), p, rng, t, drift, jit, tremorPhase, last && !opts.settle);
|
|
229
|
+
if (!last && out.length)
|
|
230
|
+
out[out.length - 1].sleepMs += lerp(40, 120, rng()); // motor re-planning gap
|
|
231
|
+
a = b;
|
|
232
|
+
}
|
|
233
|
+
if (opts.settle) {
|
|
234
|
+
// A couple of tiny sub-pixel seating jiggles, then land exactly (slider handle "clunk" into place).
|
|
235
|
+
const jig = 1 + Math.floor(rng() * 2);
|
|
236
|
+
for (let i = 0; i < jig; i++) {
|
|
237
|
+
out.push({ x: to.x + gaussFrom(rng) * 1.4, y: to.y + gaussFrom(rng) * 1.4, sleepMs: lerp(30, 90, rng()) });
|
|
238
|
+
}
|
|
239
|
+
out.push({ x: to.x, y: to.y, sleepMs: 1000 / p.deviceHz });
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
/** Grab/release dwell times (ms) for a held-button drag, drawn from the persona window. */
|
|
244
|
+
export function dragDwell(p, rng = Math.random) {
|
|
245
|
+
return {
|
|
246
|
+
grabMs: lerp(p.grabMinMs, p.grabMaxMs, rng()),
|
|
247
|
+
releaseMs: lerp(p.releaseMinMs, p.releaseMaxMs, rng()),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/** A human click point inside `box`: a 2D gaussian around center, nudged toward the approach side
|
|
251
|
+
* (people undershoot toward where the cursor came from), clamped a couple px inside the edges. */
|
|
252
|
+
export function clickPoint(box, from, p, rng = Math.random) {
|
|
253
|
+
const cx = box.x + box.width / 2, cy = box.y + box.height / 2;
|
|
254
|
+
const dx = cx - from.x, dy = cy - from.y;
|
|
255
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
256
|
+
// undershoot bias: pull ~12% of the half-width back toward the approach direction
|
|
257
|
+
const ux = -dx / d, uy = -dy / d;
|
|
258
|
+
const bx = ux * box.width * 0.12, by = uy * box.height * 0.12;
|
|
259
|
+
const x = cx + bx + gaussFrom(rng) * box.width * 0.16;
|
|
260
|
+
const y = cy + by + gaussFrom(rng) * box.height * 0.16;
|
|
261
|
+
// For a box narrower/shorter than the 4 px inset the clamp bounds would invert (lo > hi) and return
|
|
262
|
+
// a point OUTSIDE the element — just use the center for such tiny targets.
|
|
263
|
+
return {
|
|
264
|
+
x: box.width >= 4 ? clamp(x, box.x + 2, box.x + box.width - 2) : cx,
|
|
265
|
+
y: box.height >= 4 ? clamp(y, box.y + 2, box.y + box.height - 2) : cy,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Plan ambient / pre-challenge cursor activity: idle drift + a few non-goal moves within the viewport,
|
|
270
|
+
* so a behavioral collector sees non-zero pointer entropy BEFORE the first goal action (the single
|
|
271
|
+
* biggest reason a challenge/slider is shown to headless automation). Returns ~`ms` of samples.
|
|
272
|
+
*/
|
|
273
|
+
export function planAmbient(from, vp, p, ms, rng = Math.random) {
|
|
274
|
+
const out = [];
|
|
275
|
+
let cur = from;
|
|
276
|
+
let elapsed = 0;
|
|
277
|
+
const budget = Math.max(200, ms);
|
|
278
|
+
// keep motion inside a comfortable central band (people don't fling the cursor to the extremes)
|
|
279
|
+
const bx0 = vp.width * 0.12, bx1 = vp.width * 0.88;
|
|
280
|
+
const by0 = vp.height * 0.14, by1 = vp.height * 0.8;
|
|
281
|
+
while (elapsed < budget && out.length < 4000) {
|
|
282
|
+
const target = { x: lerp(bx0, bx1, rng()), y: lerp(by0, by1, rng()) };
|
|
283
|
+
const seg = planMove(cur, target, p, { targetW: 80, rng });
|
|
284
|
+
for (const s of seg) {
|
|
285
|
+
out.push(s);
|
|
286
|
+
elapsed += s.sleepMs;
|
|
287
|
+
}
|
|
288
|
+
// rest with a little drift between excursions (hand idling on the mouse)
|
|
289
|
+
const restMs = lerp(120, 600, rng());
|
|
290
|
+
const drift = { x: 0, y: 0 };
|
|
291
|
+
const stepMs = 1000 / p.deviceHz;
|
|
292
|
+
let held = 0;
|
|
293
|
+
const tphase = rng() * 2 * Math.PI;
|
|
294
|
+
while (held < restMs) {
|
|
295
|
+
const k = stepMs / p.driftTau;
|
|
296
|
+
drift.x += -k * drift.x + Math.sqrt(2 * k) * p.driftAmp * gaussFrom(rng);
|
|
297
|
+
drift.y += -k * drift.y + Math.sqrt(2 * k) * p.driftAmp * gaussFrom(rng);
|
|
298
|
+
const ph = tphase + (2 * Math.PI * p.tremorHz * held) / 1000;
|
|
299
|
+
out.push({
|
|
300
|
+
x: target.x + drift.x + p.tremorAmp * Math.sin(ph),
|
|
301
|
+
y: target.y + drift.y + p.tremorAmp * Math.sin(ph + Math.PI / 2),
|
|
302
|
+
sleepMs: stepMs * lerp(0.9, 1.4, rng()),
|
|
303
|
+
});
|
|
304
|
+
held += stepMs;
|
|
305
|
+
elapsed += stepMs;
|
|
306
|
+
}
|
|
307
|
+
cur = target;
|
|
308
|
+
}
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=motion.js.map
|