ant0-browser 0.1.1 → 0.2.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 (135) hide show
  1. package/README.md +112 -4
  2. package/dist/canvas.d.ts +55 -0
  3. package/dist/canvas.d.ts.map +1 -0
  4. package/dist/canvas.js +82 -0
  5. package/dist/canvas.js.map +1 -0
  6. package/dist/chromium-version.d.ts +3 -3
  7. package/dist/chromium-version.js +3 -3
  8. package/dist/claim-hints.d.ts +36 -0
  9. package/dist/claim-hints.d.ts.map +1 -0
  10. package/dist/claim-hints.js +9 -0
  11. package/dist/claim-hints.js.map +1 -0
  12. package/dist/cleanup.d.ts +35 -0
  13. package/dist/cleanup.d.ts.map +1 -0
  14. package/dist/cleanup.js +106 -0
  15. package/dist/cleanup.js.map +1 -0
  16. package/dist/content.d.ts +11 -0
  17. package/dist/content.d.ts.map +1 -0
  18. package/dist/content.js +52 -0
  19. package/dist/content.js.map +1 -0
  20. package/dist/download.d.ts +2 -0
  21. package/dist/download.d.ts.map +1 -1
  22. package/dist/download.js +14 -6
  23. package/dist/download.js.map +1 -1
  24. package/dist/errors.d.ts +49 -0
  25. package/dist/errors.d.ts.map +1 -0
  26. package/dist/errors.js +53 -0
  27. package/dist/errors.js.map +1 -0
  28. package/dist/fingerprint.d.ts +42 -37
  29. package/dist/fingerprint.d.ts.map +1 -1
  30. package/dist/fingerprint.js +124 -24
  31. package/dist/fingerprint.js.map +1 -1
  32. package/dist/fontpack.d.ts.map +1 -1
  33. package/dist/fontpack.js +2 -1
  34. package/dist/fontpack.js.map +1 -1
  35. package/dist/fonts.js +1 -1
  36. package/dist/fonts.js.map +1 -1
  37. package/dist/geoip.d.ts.map +1 -1
  38. package/dist/geoip.js +3 -2
  39. package/dist/geoip.js.map +1 -1
  40. package/dist/geometry.d.ts +4 -0
  41. package/dist/geometry.d.ts.map +1 -1
  42. package/dist/geometry.js +9 -3
  43. package/dist/geometry.js.map +1 -1
  44. package/dist/identity-persistence.d.ts +38 -1
  45. package/dist/identity-persistence.d.ts.map +1 -1
  46. package/dist/identity-persistence.js +90 -10
  47. package/dist/identity-persistence.js.map +1 -1
  48. package/dist/identity.d.ts +41 -3
  49. package/dist/identity.d.ts.map +1 -1
  50. package/dist/identity.js +199 -26
  51. package/dist/identity.js.map +1 -1
  52. package/dist/index.d.ts +69 -22
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +415 -218
  55. package/dist/index.js.map +1 -1
  56. package/dist/launch-ticket.d.ts +109 -5
  57. package/dist/launch-ticket.d.ts.map +1 -1
  58. package/dist/launch-ticket.js +327 -11
  59. package/dist/launch-ticket.js.map +1 -1
  60. package/dist/launchopts.d.ts +181 -48
  61. package/dist/launchopts.d.ts.map +1 -1
  62. package/dist/launchopts.js +470 -51
  63. package/dist/launchopts.js.map +1 -1
  64. package/dist/native/linux-x64/PRODUCT-LICENSE.txt +28 -0
  65. package/dist/native/linux-x64/ant0_runtime.node +0 -0
  66. package/dist/native/windows-x64/PRODUCT-LICENSE.txt +28 -0
  67. package/dist/native/windows-x64/ant0_runtime.node +0 -0
  68. package/dist/persona-migration.d.ts +3 -0
  69. package/dist/persona-migration.d.ts.map +1 -1
  70. package/dist/persona-migration.js +2 -0
  71. package/dist/persona-migration.js.map +1 -1
  72. package/dist/persona-profile-v2.d.ts +15 -1
  73. package/dist/persona-profile-v2.d.ts.map +1 -1
  74. package/dist/persona-profile-v2.js +35 -2
  75. package/dist/persona-profile-v2.js.map +1 -1
  76. package/dist/persona-profile-v4.d.ts +61 -0
  77. package/dist/persona-profile-v4.d.ts.map +1 -0
  78. package/dist/persona-profile-v4.js +79 -0
  79. package/dist/persona-profile-v4.js.map +1 -0
  80. package/dist/persona-rejected.d.ts +36 -0
  81. package/dist/persona-rejected.d.ts.map +1 -0
  82. package/dist/persona-rejected.js +40 -0
  83. package/dist/persona-rejected.js.map +1 -0
  84. package/dist/population-model.d.ts +3 -0
  85. package/dist/population-model.d.ts.map +1 -1
  86. package/dist/population-model.js +24 -3
  87. package/dist/population-model.js.map +1 -1
  88. package/dist/profile-file.d.ts +201 -0
  89. package/dist/profile-file.d.ts.map +1 -0
  90. package/dist/profile-file.js +736 -0
  91. package/dist/profile-file.js.map +1 -0
  92. package/dist/release-fetch.d.ts +4 -0
  93. package/dist/release-fetch.d.ts.map +1 -1
  94. package/dist/release-fetch.js +3 -0
  95. package/dist/release-fetch.js.map +1 -1
  96. package/dist/render.js +2 -2
  97. package/dist/render.js.map +1 -1
  98. package/dist/runtime-client.d.ts +47 -0
  99. package/dist/runtime-client.d.ts.map +1 -0
  100. package/dist/runtime-client.js +327 -0
  101. package/dist/runtime-client.js.map +1 -0
  102. package/dist/runtime-launch.d.ts +22 -0
  103. package/dist/runtime-launch.d.ts.map +1 -0
  104. package/dist/runtime-launch.js +92 -0
  105. package/dist/runtime-launch.js.map +1 -0
  106. package/dist/scale.d.ts +29 -0
  107. package/dist/scale.d.ts.map +1 -0
  108. package/dist/scale.js +105 -0
  109. package/dist/scale.js.map +1 -0
  110. package/dist/shaderdialect.d.ts.map +1 -1
  111. package/dist/shaderdialect.js +2 -1
  112. package/dist/shaderdialect.js.map +1 -1
  113. package/dist/speech-coherence.d.ts +52 -0
  114. package/dist/speech-coherence.d.ts.map +1 -0
  115. package/dist/speech-coherence.js +254 -0
  116. package/dist/speech-coherence.js.map +1 -0
  117. package/dist/template-selection.d.ts.map +1 -1
  118. package/dist/template-selection.js +8 -7
  119. package/dist/template-selection.js.map +1 -1
  120. package/dist/warnings.d.ts +35 -4
  121. package/dist/warnings.d.ts.map +1 -1
  122. package/dist/warnings.js +139 -25
  123. package/dist/warnings.js.map +1 -1
  124. package/dist/webgl-coherence.d.ts +30 -0
  125. package/dist/webgl-coherence.d.ts.map +1 -0
  126. package/dist/webgl-coherence.js +98 -0
  127. package/dist/webgl-coherence.js.map +1 -0
  128. package/dist/webgpu-override.d.ts +14 -0
  129. package/dist/webgpu-override.d.ts.map +1 -0
  130. package/dist/webgpu-override.js +82 -0
  131. package/dist/webgpu-override.js.map +1 -0
  132. package/dist/widevine.d.ts.map +1 -1
  133. package/dist/widevine.js +11 -10
  134. package/dist/widevine.js.map +1 -1
  135. package/package.json +5 -5
package/README.md CHANGED
@@ -10,18 +10,27 @@ The `ant0-browser` package contains the SDK, not the browser engine, an Ant0 acc
10
10
 
11
11
  ## Before you install
12
12
 
13
+ **System requirements, Linux:** glibc 2.39 or newer (Ubuntu 24.04+, Debian 13+, Fedora 40+). Older distributions are not supported. This applies to the Ant0 application, the engine and the native bindings.
14
+
13
15
  Direct SDK launches require all of the following:
14
16
 
15
17
  1. Install the Ant0 application and its licensed Ant0 Browser engine.
16
18
  2. Complete sign-in in the Ant0 application; its local `ant0d` daemon uses that signed-in, licensed state to provide launch tickets.
17
19
  3. Set `ANT0_BROWSER_BINARY` to the absolute path of that installation's engine executable before starting Node.js.
18
20
 
19
- The SDK checks that the executable is an Ant0 build; stock Chrome or Chromium is not a substitute. SDK package version `0.1.1` and the installed engine release version are independent.
21
+ The SDK checks that the executable is an Ant0 build; stock Chrome or Chromium is not a substitute. SDK package version `0.2.0` and the installed engine release version are independent.
20
22
 
21
23
  ## Install
22
24
 
23
25
  ```bash
24
- npm install ant0-browser@0.1.1
26
+ npm install ant0-browser@0.2.0
27
+ ```
28
+
29
+ This is a beta release, published under the npm `beta` dist-tag (`npm install ant0-browser@beta`); `npm install ant0-browser` (the `latest` tag) keeps installing the current stable release, 0.1.1, until a stable 0.2.0 ships.
30
+
31
+ ```bash
32
+ # pin the exact beta for reproducible installs
33
+ npm install --save-exact ant0-browser@0.2.0
25
34
  ```
26
35
 
27
36
  Package metadata declares Node.js 18 or newer. See the qualification table below for tested environments.
@@ -56,10 +65,49 @@ try {
56
65
 
57
66
  Omitting `identity` selects native identity. Captured or synthetic identities and explicit overrides are also available; creating a new synthetic identity requires separately authorized local model or template assets. Those assets are not included in the package.
58
67
 
68
+ Optional `overrides: { audioProfile: { sampleRate, baseLatency, outputLatency } }` replaces individual audio fields for one launch (launch-only, never saved into the identity). The default is the real-world distribution of the population model; see `docs/FINGERPRINT-MODES.md`, section "Audio profile override".
69
+
70
+ Optional `overrides: { network: { rtt, downlink, effectiveType } }` sets the persona's base `navigator.connection` link for one launch (launch-only, never saved; engine ant0.7 or later); see `docs/FINGERPRINT-MODES.md`, section "Network (`navigator.connection`) override". Newly generated synthetic identities get a speech voice list in the persona's language; saved identities are not rewritten (same document, "Speech voices follow the persona language").
71
+
72
+ ## Screen scale and the window
73
+
74
+ When the SDK knows the persona's device pixel ratio (an explicit `devicePixelRatio`, `lightStealth`, or a v2 profile's `display.device_pixel_ratio`) it adds `--force-device-scale-factor=<ratio>`, so the page sees the persona's scale on a Linux host too. A Playwright `viewport` alone emulates scale 1, so the SDK adds the matching `deviceScaleFactor` unless you set your own. A headed window is kept on the real display: its size is clamped to the display divided by the scale. The display is read from `ANT0_DISPLAY_SIZE=WIDTHxHEIGHT` or, on Linux, `xrandr`/`xdpyinfo`; Windows and macOS are not detected, so pass your own window size there (your `--window-size`, `--start-maximized`, `--start-fullscreen` or `--kiosk` always wins). A persona the engine picks by itself, and a native identity, get no flag.
75
+
76
+ ## Playwright calls that do not work on Ant0
77
+
78
+ These fail or time out (27 of 62 calls tried): `page.setContent` (use `setContent` from this package), `exposeFunction` and `exposeBinding` on a page, context or frame, `page.on('console')`, `page.on('pageerror')`, and a raw CDP session that enables `Runtime` and waits for `consoleAPICalled`. Everything else tried works: navigation, `evaluate`, init scripts, dialogs, waits, locators, frames, `route`, popups, workers, `storageState`, screenshots, PDF, mouse and plain CDP sessions.
79
+
80
+ ```ts
81
+ import { setContent } from "ant0-browser";
82
+ await setContent(page, "<h1>hi</h1>", { waitUntil: "load" }); // load | domcontentloaded | networkidle | commit
83
+ ```
84
+
85
+ `canvasBridge` was removed with the engine's canvas bridge. An old value is ignored with a one-time note and never fails a launch.
86
+
87
+ ## Browser switches `launch()` does and does not pass
88
+
89
+ Playwright adds testing switches to every launch. `launch()` and `launchPersistentContext()` remove the ones a page can observe, so pages see what a normal Chrome window shows: `--hide-scrollbars` (scrollbars are drawn), `--disable-popup-blocking` (`window.open()` without a user gesture is blocked; a popup from a click still opens and `context.on("page")` fires), and the `HttpsUpgrades` and `BoundaryEventDispatchTracksNodeRemoval` feature disables (`http://` upgrades to `https://` when TLS answers and falls back to `http://` when it does not; boundary events after a node under the pointer is removed match Chrome). `HttpsFirstBalancedModeAutoEnable` stays disabled, so a host with no TLS still loads over `http://`. This does not hold when you ignore every Playwright default (`ignoreDefaultArgs: true`), when you ignore Playwright's exact `--disable-features=` default, or when the SDK cannot read Playwright's default feature lists (unreadable-defaults fallback); `http://` to a host with no TLS can then fail with `ERR_BLOCKED_BY_CLIENT`. A switch or feature you pass yourself in `args` is kept, and a feature you enable yourself with `--enable-features` (including `HttpsFirstBalancedModeAutoEnable`) is removed from the disabled list.
90
+
91
+ Known difference from stock Chrome: `launch()` keeps `--disable-back-forward-cache`. With the cache on, Playwright's default `page.goBack()` waits for a load event that never fires on a restored page and times out; `waitUntil: "commit"` works. `serve()` does not pass it and matches stock.
92
+
93
+ ## Profile storage
94
+
95
+ localStorage is pinned to the leveldb backend (the SDK always disables `DomStorageSqlite`, `DomStorageSqliteMigration` and `DomStorageSqliteNewDatabases`), so a caller's `--enable-features=DomStorageSqlite` is overridden: disable wins. On `launch()` and `launchPersistentContext()` the SDK skips the pin when it cannot read Playwright's default feature lists (old Playwright releases), because its `--disable-features` would then replace Playwright's whole disabled list; `serve()` and `launchPlan()` always pin.
96
+
97
+ ## serve() and launchPlan()
98
+
99
+ `serve()` and `launchPlan()` apply the same engine options as `launch()`: identity, `overrides`, `args`, `extensions`, `shaderDialect`, `widevine` (seeded into the served profile), `resolveFonts`, `env` (over `process.env` and the font wiring), `quiet`, the launch-ticket and runtime options, and a `proxy`'s `server` and `bypass` (a `--proxy-bypass-list` in `args` wins). `chromiumSandbox: false` adds `--no-sandbox`; the sandbox stays on by default. Playwright-only options (`humanize`, `showCursor`, context options, proxy `username`/`password`) are ignored, and a direct spawn has no `<-loopback>` proxy rule, so `localhost` stays direct.
100
+
101
+ A `launchPlan()` plan carries a launch ticket that engines from ant0.11 accept only for about 5 minutes after it was issued. Spawn the plan promptly, and call `launchPlan()` again for every (re)spawn; never respawn from an old plan.
102
+
103
+ `cacheDir` is accepted on every launch path and ignored; it prints a one-time note. To choose the download cache, use `executablePath({ cacheDir })`.
104
+
59
105
  ## Proxy, network, and privacy
60
106
 
61
107
  Proxy settings for browser launches are optional and follow Playwright's configuration. SOCKS5 username/password authentication is not supported by the engine; use an HTTP(S) proxy with credentials, an unauthenticated SOCKS5 proxy, or Ant0's local relay. GeoIP exit-IP lookups use an HTTP(S) proxy; SOCKS proxies are not supported for that lookup.
62
108
 
109
+ `socks5h://` is accepted and sent as `socks5://`; the engine resolves hostnames at the SOCKS5 proxy in both cases.
110
+
63
111
  | Behavior | Network use |
64
112
  | --- | --- |
65
113
  | Launch-ticket handling | When needed, the SDK requests a ticket from the local `ant0d` daemon over loopback. |
@@ -70,14 +118,14 @@ See [SDK network details](https://docs.ant0.link/sdk#network) and the [Ant0 Priv
70
118
 
71
119
  ## Runtime and qualification
72
120
 
73
- The package declares Node.js `>=18`. Qualification so far covers the combinations below; the declared minimum is not a claim that every minimum-version/platform combination has been tested.
121
+ The package declares Node.js `>=18`. The table below is the qualification of the previous release; this beta is being requalified and its results are recorded in the release notes. The declared minimum is not a claim that every minimum-version/platform combination has been tested.
74
122
 
75
123
  | Platform | Tested runtime |
76
124
  | --- | --- |
77
125
  | Linux | Node.js 24 |
78
126
  | Windows | Node.js 24 |
79
127
 
80
- The engine used for native launch qualification was `154.0.8037.57-ant0.2`.
128
+ Target engine for this release: `158.0.8127.18-ant0.11`.
81
129
 
82
130
  ## Troubleshooting
83
131
 
@@ -88,6 +136,66 @@ The engine used for native launch qualification was `154.0.8037.57-ant0.2`.
88
136
  | Temporary profile or socket path is too long | Set `TMPDIR` (POSIX) or `TEMP`/`TMP` (Windows) to a short, writable local directory before starting Node.js. |
89
137
  | SOCKS5 proxy credentials are rejected | Use an HTTP(S) proxy, an unauthenticated SOCKS5 endpoint, or Ant0's local relay. |
90
138
 
139
+ ### Launch ticket in the environment
140
+
141
+ The SDK hands the engine its launch ticket twice, with the same value: as `--ant0-launch=<ticket>` in the engine's arguments, and as `ANT0_LAUNCH` in the environment of the engine process only. Engines that predate the environment variable read only the argument; newer ones read the environment first, so the ticket is not needed on the command line. The argument is dropped in a later release. This applies to `launch()`, `launchPersistentContext()`, `serve()` and `launchPlan()`. `launchPlan()` returns the plan the caller spawns itself; `plan.env` carries the entry, so pass `plan.env` and `plan.args` to your own spawn. The SDK never sets `ANT0_LAUNCH` in its own process (`process.env`); it is added to a copy of the environment that goes to the engine.
142
+
143
+ If you pass your own ticket, nothing is overwritten and nothing is refused. A ticket in your `env` option (`ANT0_LAUNCH`) or in your `args` (`--ant0-launch=`) counts as yours: the SDK then neither fetches nor adds another, and copies yours into the place that has none, so both match. If you set both and they differ, both are left as you set them (a newer engine uses the environment one and logs a line). Only those two count. An `ANT0_LAUNCH` that is merely set in your shell or in the SDK's own environment does nothing: it is never read as your ticket, never reaches the engine, and an engine launch that has no ticket of its own carries none. `--ant0-launch <ticket>` (with a space) is not parsed or mirrored: it is an ordinary argument left to the engine, which only reads the `=` form. On Windows the variable name is matched case-insensitively. **Stale tickets:** when the engine exits 90 with `claim_expired` or `claim_stale` and the SDK itself fetched the ticket from the daemon, `launch()`, `launchPersistentContext()` and `serve()` retry the launch once with a ticket fetched right before the respawn. A ticket you provided (the launch-ticket option, `--ant0-launch=` in your args, or `ANT0_LAUNCH` in your explicit env) and every other reason are never retried, and a second failure is raised as usual. `launchPlan()` returns a plan you spawn yourself, so it cannot retry: if your child exits 90 with one of those two reasons and you used the SDK-fetched ticket, call `launchPlan()` again (or `plan.spawn()` for a new ticket) and respawn once.
144
+
145
+ The ticket in the environment is a secret like the one in the arguments: it is removed from launch errors, and an `env` property on a wrapped error is dropped. Do not log the engine's environment. An engine that rejects a stale claim reports `claim_stale` (exit code 90), which the SDK treats like `claim_expired`.
146
+
147
+ ### Launch errors and secrets
148
+
149
+ Errors the SDK raises or re-raises for a failed launch have the launch ticket, the persona file path and the profile directory removed from their message, stack and string properties (the values the SDK itself passed are replaced exactly; the `--ant0-launch` and `--fingerprint-profile-file` switches are also matched by pattern), and carry no `cause`. This covers error messages and tracebacks only. A tool that captures local variables when an error happens (Sentry with local variables enabled, a debugger, a crash reporter) can still see the raw launch arguments in the SDK's frames. Keep such capture off for code that calls `launch()` or `serve()`, or scrub the `--ant0-launch`, `--fingerprint-profile-file` and `--user-data-dir` values in its hooks. A `--ant0-launch` value shorter than 16 characters is replaced only where it follows its switch or stands as a whole token, not anywhere in a text, so a short word cannot mangle the text around it. Only a malformed value that a user typed is that short; a minted ticket carries a 64-byte signature and is about 86 characters, so it is always replaced everywhere.
150
+
151
+ ### Engine damaged
152
+
153
+ **Symptom.** `launch()` raises `browser.proof_mismatch` (next action `reinstall_engine`).
154
+
155
+ **Cause.** The engine's signed proof is present and valid, but an installed file was changed, truncated or removed. `ant0 browsers ls` shows the release as failed and names the file.
156
+
157
+ **Fix.** Reinstall that release: `ant0 browsers rm <version>`, then `ant0 browsers install --release <version>`.
158
+
159
+ ### Engine not found
160
+
161
+ **Symptom.** `launch()` raises `browser.not_installed`, even though `ant0 browsers ls` shows the engine as installed.
162
+
163
+ **Cause.** The installed engine has no valid install proof (a signed record of its files, kept in `<home>/browsers/<version>/.provenance/`). Without it, the SDK will not use the engine automatically. The error code does not say which part failed; this is by design.
164
+
165
+ **Fix 1: write the proof for the installed engine.** Update the Ant0 desktop app to 0.3.22 or later, then run:
166
+
167
+ ```bash
168
+ ant0 browsers install --release <version> --repair-proof
169
+ ```
170
+
171
+ This never reinstalls the engine. It writes the proof only if every installed file matches the signed list.
172
+
173
+ **Fix 2: reinstall the engine** with the desktop app 0.3.22 or later. New installs write the proof automatically.
174
+
175
+ **Engines with no published proof** (for example the current stable `ant0.5`) cannot be found automatically. Pass the path to the browser yourself, using `executablePath` or the `ANT0_BROWSER_BINARY` environment variable:
176
+
177
+ ```js
178
+ const browser = await launch({ executablePath: "/path/to/ant0/chrome" });
179
+ ```
180
+
181
+ ### Unexpected file in the engine folder
182
+
183
+ **Symptom.** `launch()` raises `browser.unexpected_file` (next action `reinstall_engine`). The native runtime's own text names the file ("the engine folder has an unexpected file (`<name>`); repair or reinstall the engine"), but the SDK error carries the code and next action only, never the runtime's message.
184
+
185
+ **Cause.** The engine is installed, but its folder holds an entry that is not on the engine's signed file list (for example a log file written by something that ran inside it). The check is exact on purpose: no file name is accepted.
186
+
187
+ **Fix.** Reinstall that release (this also removes the extra entry): `ant0 browsers rm <version>`, then `ant0 browsers install --release <version>`. Not `browser.proof_mismatch`: that means a listed file was changed or removed.
188
+
189
+ ## Shutdown and cleanup
190
+
191
+ Ctrl+C / SIGTERM cleanup is the application's job: call `close()` (for example from your own `SIGINT` handler). The SDK installs no signal handlers, so it never changes how your process terminates.
192
+
193
+ What the exit hook guarantees: if the process exits without `close()` (including `srv.close(); process.exit(0)` without awaiting), one `exit` listener stops every running `serve()` browser and removes the temp profile directory `serve()` created. A browser that uses a throwaway temp profile gets SIGKILL (a graceful Chromium shutdown writes files back into the directory being removed); a browser using a `userDataDir` you passed in gets SIGTERM so it can shut down gracefully (unless `close()` has already sent it SIGTERM, in which case it is not signalled a second time, since a second SIGTERM would cut its graceful shutdown short), and that directory is never deleted. The hook is synchronous and bounded: it spends about 1 s per directory and about 3 s in total on removal retries, then gives up and accepts the leak. A process killed by a signal you did not handle does not run `exit` hooks, so nothing is cleaned up in that case.
194
+
195
+ On Windows there is no graceful SIGTERM: stopping a process is a hard terminate.
196
+
197
+ `close()` sends SIGTERM, waits for the browser to exit (SIGKILL only if it has not exited after a timeout), then removes the temp profile directory.
198
+
91
199
  ## GeoIP attribution
92
200
 
93
201
  Optional GeoIP uses the IP2Location LITE database ([ip2location.com](https://lite.ip2location.com)), includes GeoLite2 data created by MaxMind ([maxmind.com](https://www.maxmind.com/)), and includes IP geolocation by DB-IP ([db-ip.com](https://db-ip.com)). The merged `geoip-all-in-one` database is GPL-3.0; its data covers country, coordinates, and timezone.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Canvas mode per profile, and the per-profile canvas noise key.
3
+ *
4
+ * Two modes:
5
+ * real this computer's genuine canvas output. Every profile on this computer shows the same
6
+ * canvas result. This is the default.
7
+ * noise a canvas result that is unique to the profile, stable across launches and across sites.
8
+ * Needs a 16-hex key; the engine takes it as `--fingerprint-noise-key=<key>`.
9
+ *
10
+ * Mapping of the options onto the mode (`canvasMode`):
11
+ *
12
+ * canvas canvasNoise fingerprintNoise mode
13
+ * "real" any any real
14
+ * "noise" any any noise (the key is required)
15
+ * unset any any real
16
+ *
17
+ * Only `canvas: "noise"` selects noise. The legacy `canvasNoise` and `fingerprintNoise` flags never do:
18
+ * on earlier releases `true` sent nothing and `false` sent `--disable-canvas-noise` /
19
+ * `--disable-fingerprint-noise`, and a profile that already existed must not change its fingerprint on
20
+ * upgrade. They keep exactly that behaviour; `true` now also gets the `canvas-noise-no-key` warning.
21
+ */
22
+ /** The engine switch that carries the key. One constant so the spelling is a one-line change. */
23
+ export declare const CANVAS_NOISE_KEY_SWITCH = "--fingerprint-noise-key";
24
+ /** The key is exactly this many lowercase hex characters (8 bytes), with no 0x prefix. */
25
+ export declare const CANVAS_NOISE_KEY_LENGTH = 16;
26
+ /** Domain separator for the key derived for older identity files (v1 and v2 wrappers), which store none. */
27
+ export declare const CANVAS_NOISE_KEY_DOMAIN = "ant0/canvas-noise-key/v1\0";
28
+ export type CanvasMode = "real" | "noise";
29
+ export interface CanvasOptions {
30
+ canvas?: CanvasMode;
31
+ canvasNoise?: boolean;
32
+ fingerprintNoise?: boolean;
33
+ }
34
+ /** True when `value` is a valid canvas noise key: 16 lowercase hex characters. */
35
+ export declare function isCanvasNoiseKey(value: unknown): value is string;
36
+ /** Throw unless `canvas` is undefined, "real" or "noise". */
37
+ export declare function assertCanvasOption(canvas: unknown): void;
38
+ /** Throw unless `key` is undefined or a valid canvas noise key. */
39
+ export declare function assertCanvasNoiseKey(key: unknown): void;
40
+ /** Resolve the canvas mode from the options (see the table at the top of this file). */
41
+ export declare function canvasMode(o: CanvasOptions): CanvasMode;
42
+ /** A fresh random canvas noise key (CSPRNG, 8 bytes as 16 lowercase hex). */
43
+ export declare function newCanvasNoiseKey(): string;
44
+ /** The key for an identity stored without one: the first 8 bytes of
45
+ * SHA-256("ant0/canvas-noise-key/v1\0" + identityKey), as 16 lowercase hex.
46
+ * `identityKey` is the string the caller gave as `identity.key` (the daemon: the profile's
47
+ * identity key); it is hashed as UTF-8. */
48
+ export declare function deriveCanvasNoiseKey(identityKey: string): string;
49
+ /** The canvas noise key of a persisted identity: its stored `canvas_noise_key`, else the key derived
50
+ * from `identityKey`. The wrapper does not record the identity key (its file name is an HMAC of it),
51
+ * so the caller passes it. */
52
+ export declare function canvasNoiseKeyFor(persisted: {
53
+ canvas_noise_key?: string;
54
+ } | null | undefined, identityKey: string): string;
55
+ //# sourceMappingURL=canvas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../src/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,iGAAiG;AACjG,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AACjE,0FAA0F;AAC1F,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,4GAA4G;AAC5G,eAAO,MAAM,uBAAuB,+BAA+B,CAAC;AAEpE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAG1C,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED,6DAA6D;AAC7D,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAIxD;AAED,mEAAmE;AACnE,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAIvD;AAED,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,CAAC,EAAE,aAAa,GAAG,UAAU,CAIvD;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;2CAG2C;AAC3C,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED;;8BAE8B;AAC9B,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM,GAC/E,MAAM,CASR"}
package/dist/canvas.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Canvas mode per profile, and the per-profile canvas noise key.
3
+ *
4
+ * Two modes:
5
+ * real this computer's genuine canvas output. Every profile on this computer shows the same
6
+ * canvas result. This is the default.
7
+ * noise a canvas result that is unique to the profile, stable across launches and across sites.
8
+ * Needs a 16-hex key; the engine takes it as `--fingerprint-noise-key=<key>`.
9
+ *
10
+ * Mapping of the options onto the mode (`canvasMode`):
11
+ *
12
+ * canvas canvasNoise fingerprintNoise mode
13
+ * "real" any any real
14
+ * "noise" any any noise (the key is required)
15
+ * unset any any real
16
+ *
17
+ * Only `canvas: "noise"` selects noise. The legacy `canvasNoise` and `fingerprintNoise` flags never do:
18
+ * on earlier releases `true` sent nothing and `false` sent `--disable-canvas-noise` /
19
+ * `--disable-fingerprint-noise`, and a profile that already existed must not change its fingerprint on
20
+ * upgrade. They keep exactly that behaviour; `true` now also gets the `canvas-noise-no-key` warning.
21
+ */
22
+ import { createHash, randomBytes } from "node:crypto";
23
+ import { SdkInputError } from "./errors.js";
24
+ /** The engine switch that carries the key. One constant so the spelling is a one-line change. */
25
+ export const CANVAS_NOISE_KEY_SWITCH = "--fingerprint-noise-key";
26
+ /** The key is exactly this many lowercase hex characters (8 bytes), with no 0x prefix. */
27
+ export const CANVAS_NOISE_KEY_LENGTH = 16;
28
+ /** Domain separator for the key derived for older identity files (v1 and v2 wrappers), which store none. */
29
+ export const CANVAS_NOISE_KEY_DOMAIN = "ant0/canvas-noise-key/v1\0";
30
+ const KEY_RE = /^[0-9a-f]{16}$/;
31
+ /** True when `value` is a valid canvas noise key: 16 lowercase hex characters. */
32
+ export function isCanvasNoiseKey(value) {
33
+ return typeof value === "string" && KEY_RE.test(value);
34
+ }
35
+ /** Throw unless `canvas` is undefined, "real" or "noise". */
36
+ export function assertCanvasOption(canvas) {
37
+ if (canvas !== undefined && canvas !== "real" && canvas !== "noise") {
38
+ throw new SdkInputError("sdk.canvas_invalid", 'canvas must be "real" or "noise"');
39
+ }
40
+ }
41
+ /** Throw unless `key` is undefined or a valid canvas noise key. */
42
+ export function assertCanvasNoiseKey(key) {
43
+ if (key !== undefined && !isCanvasNoiseKey(key)) {
44
+ throw new SdkInputError("sdk.canvas_invalid", "canvasNoiseKey must be 16 lowercase hex characters");
45
+ }
46
+ }
47
+ /** Resolve the canvas mode from the options (see the table at the top of this file). */
48
+ export function canvasMode(o) {
49
+ assertCanvasOption(o.canvas);
50
+ if (o.canvas !== undefined)
51
+ return o.canvas;
52
+ return "real";
53
+ }
54
+ /** A fresh random canvas noise key (CSPRNG, 8 bytes as 16 lowercase hex). */
55
+ export function newCanvasNoiseKey() {
56
+ return randomBytes(8).toString("hex");
57
+ }
58
+ /** The key for an identity stored without one: the first 8 bytes of
59
+ * SHA-256("ant0/canvas-noise-key/v1\0" + identityKey), as 16 lowercase hex.
60
+ * `identityKey` is the string the caller gave as `identity.key` (the daemon: the profile's
61
+ * identity key); it is hashed as UTF-8. */
62
+ export function deriveCanvasNoiseKey(identityKey) {
63
+ if (typeof identityKey !== "string") {
64
+ throw new SdkInputError("sdk.canvas_invalid", "identityKey must be a string");
65
+ }
66
+ return createHash("sha256").update(CANVAS_NOISE_KEY_DOMAIN, "utf8").update(identityKey, "utf8")
67
+ .digest().subarray(0, 8).toString("hex");
68
+ }
69
+ /** The canvas noise key of a persisted identity: its stored `canvas_noise_key`, else the key derived
70
+ * from `identityKey`. The wrapper does not record the identity key (its file name is an HMAC of it),
71
+ * so the caller passes it. */
72
+ export function canvasNoiseKeyFor(persisted, identityKey) {
73
+ const stored = persisted?.canvas_noise_key;
74
+ if (stored !== undefined) {
75
+ if (!isCanvasNoiseKey(stored)) {
76
+ throw new SdkInputError("sdk.canvas_invalid", "stored canvas_noise_key is not 16 lowercase hex characters");
77
+ }
78
+ return stored;
79
+ }
80
+ return deriveCanvasNoiseKey(identityKey);
81
+ }
82
+ //# sourceMappingURL=canvas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas.js","sourceRoot":"","sources":["../src/canvas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,iGAAiG;AACjG,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AACjE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,4GAA4G;AAC5G,MAAM,CAAC,MAAM,uBAAuB,GAAG,4BAA4B,CAAC;AAGpE,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAQhC,kFAAkF;AAClF,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,kBAAkB,CAAC,MAAe;IAChD,IAAI,MAA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AAM,GAAG,SAAS,EAAE,gBAAgB,CAAC;IAC3C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,aAAa,CAAC,oBAAoB,EAAE,4DAA4D,CAAC,CAAC;QAC9G,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,oBAAoB,CAAC,WAAW,CAAC,CAAC;AAC3C,CAAC"}
@@ -14,9 +14,9 @@
14
14
  * script, re-apply, rebuild".
15
15
  */
16
16
  /** Full pinned Chromium version, e.g. `"154.0.8037.57"`. */
17
- export declare const CHROMIUM_VERSION = "154.0.8037.57";
17
+ export declare const CHROMIUM_VERSION = "158.0.8127.18";
18
18
  /** Major of {@link CHROMIUM_VERSION}, e.g. `154`. The identity contract's `browser_major`. */
19
- export declare const CHROMIUM_MAJOR = 154;
19
+ export declare const CHROMIUM_MAJOR = 158;
20
20
  /** The UA-reduction form Chromium reports, e.g. `"154.0.0.0"`. */
21
- export declare const CHROMIUM_UA_VERSION = "154.0.0.0";
21
+ export declare const CHROMIUM_UA_VERSION = "158.0.0.0";
22
22
  //# sourceMappingURL=chromium-version.d.ts.map
@@ -14,9 +14,9 @@
14
14
  * script, re-apply, rebuild".
15
15
  */
16
16
  /** Full pinned Chromium version, e.g. `"154.0.8037.57"`. */
17
- export const CHROMIUM_VERSION = "154.0.8037.57";
17
+ export const CHROMIUM_VERSION = "158.0.8127.18";
18
18
  /** Major of {@link CHROMIUM_VERSION}, e.g. `154`. The identity contract's `browser_major`. */
19
- export const CHROMIUM_MAJOR = 154;
19
+ export const CHROMIUM_MAJOR = 158;
20
20
  /** The UA-reduction form Chromium reports, e.g. `"154.0.0.0"`. */
21
- export const CHROMIUM_UA_VERSION = "154.0.0.0";
21
+ export const CHROMIUM_UA_VERSION = "158.0.0.0";
22
22
  //# sourceMappingURL=chromium-version.js.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Hints a caller may send when it asks the cloud to issue an identity (contract ant0#53,
3
+ * docs/PHASE3-CONTRACT.md section 9, `POST /workspaces/:ws/profiles/claim` `hints`).
4
+ *
5
+ * The SDK has no request path to the daemon or the cloud for identities (the daemon owns the claim),
6
+ * so these are types only. The daemon passes the same shape through.
7
+ */
8
+ /** Browser brand a persona may present. */
9
+ export type ClaimBrand = "chrome" | "edge";
10
+ /** Vendor of the claiming host's real GPU. */
11
+ export type ClaimHostGpuVendor = "intel" | "nvidia" | "amd" | "apple";
12
+ /** Locale inputs for the persona, from the profile's proxy. Required when population model V2.2 is requested. */
13
+ export interface ClaimLocale {
14
+ /** BCP 47 tag of the OS language, e.g. "en-US". */
15
+ os_language: string;
16
+ /** IANA timezone, e.g. "America/New_York". */
17
+ timezone: string;
18
+ /** One to eight BCP 47 tags; the cloud moves `os_language` to the front when it is not first. */
19
+ languages?: string[];
20
+ }
21
+ export interface ClaimHints {
22
+ /** `windows`, `macos` or `linux`. */
23
+ os_family?: string;
24
+ browser_major?: number;
25
+ /** Population model version, `^[a-z0-9][a-z0-9._-]{0,63}$`. Fresh issuance only. */
26
+ model_version?: string;
27
+ brand?: ClaimBrand;
28
+ locale?: ClaimLocale;
29
+ /** Whether the claiming host presents its real GPU (default false). */
30
+ host_gpu?: boolean;
31
+ host_gpu_vendor?: ClaimHostGpuVendor;
32
+ /** The engine's `--ant0-sdk-info` `persona.capabilities`: at most 64 ids matching `^[a-z0-9_.]{1,64}$`, no
33
+ * duplicates. Sent with a model version; the newest model refuses a claim without it. */
34
+ engine_capabilities?: string[];
35
+ }
36
+ //# sourceMappingURL=claim-hints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-hints.d.ts","sourceRoot":"","sources":["../src/claim-hints.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,2CAA2C;AAC3C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;AAC3C,8CAA8C;AAC9C,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;AAEtE,iHAAiH;AACjH,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,iGAAiG;IACjG,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,kBAAkB,CAAC;IACrC;6FACyF;IACzF,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAChC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hints a caller may send when it asks the cloud to issue an identity (contract ant0#53,
3
+ * docs/PHASE3-CONTRACT.md section 9, `POST /workspaces/:ws/profiles/claim` `hints`).
4
+ *
5
+ * The SDK has no request path to the daemon or the cloud for identities (the daemon owns the claim),
6
+ * so these are types only. The daemon passes the same shape through.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=claim-hints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim-hints.js","sourceRoot":"","sources":["../src/claim-hints.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,35 @@
1
+ import type { ChildProcess } from "node:child_process";
2
+ /** Exit-time budget: at most about this long per temp dir ... */
3
+ export declare const EXIT_DIR_BUDGET_MS = 1000;
4
+ /** ... and about this long across all dirs in one exit. When it runs out we give up and accept the
5
+ * leak (an `exit` handler must not hang the process). */
6
+ export declare const EXIT_TOTAL_BUDGET_MS = 3000;
7
+ export interface Tracked {
8
+ proc: ChildProcess;
9
+ /** Set ONLY for a temp dir the SDK created itself (serve/plan). Never a caller-supplied or
10
+ * persistent profile dir, which is left alone even when the SDK launched the browser. */
11
+ ownDir?: string;
12
+ }
13
+ export declare const tracked: Set<Tracked>;
14
+ /** Sleep without spinning: Atomics.wait on a private SharedArrayBuffer blocks the thread. */
15
+ export declare function sleepSync(ms: number): void;
16
+ /** Injection points so the budget can be tested with a dir that cannot be removed. */
17
+ export interface ExitOps {
18
+ rm(dir: string): void;
19
+ exists(dir: string): boolean;
20
+ sleep(ms: number): void;
21
+ now(): number;
22
+ }
23
+ /** Runs inside the "exit" event, so it is SYNCHRONOUS (process.kill, fs.rmSync and a blocking sleep
24
+ * only; anything awaited or promise-based never runs there). Bounded: about EXIT_DIR_BUDGET_MS per
25
+ * dir and EXIT_TOTAL_BUDGET_MS in all. */
26
+ export declare function runExitCleanup(entries?: Iterable<Tracked>, ops?: ExitOps): void;
27
+ export declare function track(proc: ChildProcess, ownDir?: string): Tracked;
28
+ export declare function untrack(entry: Tracked): void;
29
+ /** Remove a profile dir we created. Retries because a browser that is still shutting down can
30
+ * recreate files for a moment; never throws. */
31
+ export declare function removeOwnDir(dir: string): Promise<void>;
32
+ /** Stop a child we spawned and wait until it has exited: SIGTERM first (a graceful shutdown, so a
33
+ * persistent profile keeps its writes), SIGKILL only as a fallback after `graceMs`. */
34
+ export declare function stopChild(proc: ChildProcess, graceMs?: number, killMs?: number): Promise<void>;
35
+ //# sourceMappingURL=cleanup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../src/cleanup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,iEAAiE;AACjE,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC;yDACyD;AACzD,eAAO,MAAM,oBAAoB,OAAO,CAAC;AASzC,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,YAAY,CAAC;IACnB;6FACyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AACD,eAAO,MAAM,OAAO,cAAqB,CAAC;AAE1C,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,sFAAsF;AACtF,MAAM,WAAW,OAAO;IACtB,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,GAAG,IAAI,MAAM,CAAC;CACf;AAkBD;;0CAE0C;AAC1C,wBAAgB,cAAc,CAAC,OAAO,GAAE,QAAQ,CAAC,OAAO,CAAW,EAAE,GAAG,GAAE,OAAiB,GAAG,IAAI,CAoBjG;AAKD,wBAAgB,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAKlE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAG5C;AAED;gDACgD;AAChD,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK7D;AAED;uFACuF;AACvF,wBAAsB,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,SAAO,EAAE,MAAM,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAUhG"}
@@ -0,0 +1,106 @@
1
+ import { existsSync, rmSync } from "node:fs";
2
+ /** Exit-time budget: at most about this long per temp dir ... */
3
+ export const EXIT_DIR_BUDGET_MS = 1000;
4
+ /** ... and about this long across all dirs in one exit. When it runs out we give up and accept the
5
+ * leak (an `exit` handler must not hang the process). */
6
+ export const EXIT_TOTAL_BUDGET_MS = 3000;
7
+ export const tracked = new Set();
8
+ /** Sleep without spinning: Atomics.wait on a private SharedArrayBuffer blocks the thread. */
9
+ export function sleepSync(ms) {
10
+ if (ms > 0)
11
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
12
+ }
13
+ const realOps = {
14
+ rm: (dir) => rmSync(dir, { recursive: true, force: true }),
15
+ exists: existsSync,
16
+ sleep: sleepSync,
17
+ now: Date.now,
18
+ };
19
+ /** Remove `dir`, retrying with short sleeps until it is gone or `deadline` (ms, ops.now clock) passes. */
20
+ function removeWithin(dir, deadline, ops) {
21
+ for (let attempt = 1;; attempt++) {
22
+ try {
23
+ ops.rm(dir);
24
+ if (!ops.exists(dir))
25
+ return;
26
+ }
27
+ catch { /* retry until the deadline */ }
28
+ const left = deadline - ops.now();
29
+ if (left <= 0)
30
+ return; // budget spent: accept the leak
31
+ ops.sleep(Math.min(50 * attempt, left));
32
+ }
33
+ }
34
+ /** Runs inside the "exit" event, so it is SYNCHRONOUS (process.kill, fs.rmSync and a blocking sleep
35
+ * only; anything awaited or promise-based never runs there). Bounded: about EXIT_DIR_BUDGET_MS per
36
+ * dir and EXIT_TOTAL_BUDGET_MS in all. */
37
+ export function runExitCleanup(entries = tracked, ops = realOps) {
38
+ const list = [...entries];
39
+ const start = ops.now();
40
+ for (const t of list) {
41
+ // A throwaway temp profile has nothing to flush, and Chromium writes "Local State" back during a
42
+ // graceful shutdown, which would recreate the dir we are about to remove: SIGKILL. Persistent and
43
+ // caller-supplied dirs (no ownDir) still get SIGTERM so they shut down gracefully.
44
+ // A caller-supplied dir whose browser close() has already sent SIGTERM (proc.killed) is not signalled
45
+ // again: Chromium restores the default SIGTERM handler after the first one, so a second SIGTERM
46
+ // would kill it mid-shutdown and leave the profile without Preferences / a clean exit marker.
47
+ try {
48
+ if (t.proc.exitCode === null && t.proc.signalCode === null && (t.ownDir || !t.proc.killed))
49
+ t.proc.kill(t.ownDir ? "SIGKILL" : "SIGTERM");
50
+ }
51
+ catch { /* gone */ }
52
+ }
53
+ for (const t of list) {
54
+ if (!t.ownDir)
55
+ continue;
56
+ const now = ops.now();
57
+ removeWithin(t.ownDir, Math.min(now + EXIT_DIR_BUDGET_MS, start + EXIT_TOTAL_BUDGET_MS), ops);
58
+ }
59
+ }
60
+ function killTrackedAtExit() { runExitCleanup(); }
61
+ export function track(proc, ownDir) {
62
+ const entry = { proc, ownDir };
63
+ if (tracked.size === 0)
64
+ process.on("exit", killTrackedAtExit);
65
+ tracked.add(entry);
66
+ return entry;
67
+ }
68
+ export function untrack(entry) {
69
+ tracked.delete(entry);
70
+ if (tracked.size === 0)
71
+ process.removeListener("exit", killTrackedAtExit);
72
+ }
73
+ /** Remove a profile dir we created. Retries because a browser that is still shutting down can
74
+ * recreate files for a moment; never throws. */
75
+ export async function removeOwnDir(dir) {
76
+ for (let attempt = 0; attempt < 6; attempt++) {
77
+ try {
78
+ rmSync(dir, { recursive: true, force: true });
79
+ if (!existsSync(dir))
80
+ return;
81
+ }
82
+ catch { /* retry */ }
83
+ await new Promise((r) => setTimeout(r, 100 * (attempt + 1)));
84
+ }
85
+ }
86
+ /** Stop a child we spawned and wait until it has exited: SIGTERM first (a graceful shutdown, so a
87
+ * persistent profile keeps its writes), SIGKILL only as a fallback after `graceMs`. */
88
+ export async function stopChild(proc, graceMs = 5000, killMs = 2000) {
89
+ if (proc.exitCode !== null || proc.signalCode !== null)
90
+ return;
91
+ const exited = new Promise((resolve) => proc.once("exit", () => resolve()));
92
+ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms).unref());
93
+ try {
94
+ proc.kill("SIGTERM");
95
+ }
96
+ catch { /* already gone */ }
97
+ await Promise.race([exited, wait(graceMs)]);
98
+ if (proc.exitCode === null && proc.signalCode === null) {
99
+ try {
100
+ proc.kill("SIGKILL");
101
+ }
102
+ catch { /* already gone */ }
103
+ await Promise.race([exited, wait(killMs)]);
104
+ }
105
+ }
106
+ //# sourceMappingURL=cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../src/cleanup.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,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAClF,MAAM,IAAI,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7F,IAAI,CAAC;QAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC;IAC1D,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5C,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QACvD,IAAI,CAAC;YAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC;QAC1D,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Frame, Page } from "playwright-core";
2
+ export interface SetContentOptions {
3
+ /** Lifecycle point to wait for: "load" (default), "domcontentloaded", "networkidle" or "commit"
4
+ * (return right after `document.close()`). */
5
+ waitUntil?: "load" | "domcontentloaded" | "networkidle" | "commit";
6
+ /** Milliseconds (default 30000). 0 disables the limit. */
7
+ timeout?: number;
8
+ }
9
+ /** Replace the page's (or frame's) document with `html` and wait. Use instead of `page.setContent`. */
10
+ export declare function setContent(target: Page | Frame, html: string, options?: SetContentOptions): Promise<void>;
11
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,iBAAiB;IAChC;kDAC8C;IAC9C,SAAS,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,aAAa,GAAG,QAAQ,CAAC;IACnE,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAoBD,uGAAuG;AACvG,wBAAsB,UAAU,CAC9B,MAAM,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAClE,OAAO,CAAC,IAAI,CAAC,CAsBf"}
@@ -0,0 +1,52 @@
1
+ // setContent: Playwright's `page.setContent` times out on Ant0 (engine patch 110 removes the
2
+ // `console.debug` handshake it waits on). This sets the document the plain-DOM way instead:
3
+ // `document.open()`, `document.write(html)`, `document.close()`, then waits for the same lifecycle
4
+ // point. Mirror of the Python ant0browser `set_content`.
5
+ // Runs in the page. Plain function (not a string) so Playwright calls it with the argument.
6
+ function writeDocument(args) {
7
+ // The SDK compiles without the DOM lib, so the page's document is reached untyped.
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ const document = globalThis.document;
10
+ return new Promise((resolve) => {
11
+ document.open();
12
+ document.write(args.html);
13
+ document.close();
14
+ const done = () => {
15
+ const rs = document.readyState;
16
+ return args.until === "load" ? rs === "complete" : rs === "interactive" || rs === "complete";
17
+ };
18
+ if (args.until === "commit" || done()) {
19
+ resolve();
20
+ return;
21
+ }
22
+ document.addEventListener("readystatechange", () => { if (done())
23
+ resolve(); });
24
+ });
25
+ }
26
+ /** Replace the page's (or frame's) document with `html` and wait. Use instead of `page.setContent`. */
27
+ export async function setContent(target, html, options = {}) {
28
+ const until = options.waitUntil ?? "load";
29
+ if (!["load", "domcontentloaded", "networkidle", "commit"].includes(until)) {
30
+ throw new TypeError(`setContent: unsupported waitUntil ${JSON.stringify(until)}`);
31
+ }
32
+ const timeout = options.timeout ?? 30000;
33
+ const write = target.evaluate(writeDocument, { html: String(html), until: until === "networkidle" ? "load" : until });
34
+ let timer;
35
+ const limit = timeout > 0
36
+ ? new Promise((_, reject) => {
37
+ timer = setTimeout(() => reject(new Error(`setContent: timeout ${timeout}ms exceeded waiting for "${until}"`)), timeout);
38
+ })
39
+ : undefined;
40
+ try {
41
+ await (limit ? Promise.race([write, limit]) : write);
42
+ if (until === "networkidle") {
43
+ const page = "page" in target && typeof target.page === "function" ? target.page() : target;
44
+ await page.waitForLoadState("networkidle", timeout > 0 ? { timeout } : undefined);
45
+ }
46
+ }
47
+ finally {
48
+ if (timer)
49
+ clearTimeout(timer);
50
+ }
51
+ }
52
+ //# sourceMappingURL=content.js.map