@keploy/capture-sdk 3.0.1 → 3.1.0-rc.2

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 (55) hide show
  1. package/README.md +1617 -130
  2. package/body-redact/package.json +6 -0
  3. package/body-worker-start/package.json +6 -0
  4. package/dist/body-jobs.d.ts +134 -0
  5. package/dist/body-redact.d.ts +23 -0
  6. package/dist/body-redact.js +1 -0
  7. package/dist/body-redact.js.map +1 -0
  8. package/dist/body-redact.mjs +1 -0
  9. package/dist/body-redact.mjs.map +1 -0
  10. package/dist/body-worker-none.d.ts +3 -0
  11. package/dist/body-worker-none.js +1 -0
  12. package/dist/body-worker-none.js.map +1 -0
  13. package/dist/body-worker-none.mjs +1 -0
  14. package/dist/body-worker-none.mjs.map +1 -0
  15. package/dist/body-worker-start.d.ts +3 -0
  16. package/dist/body-worker-start.js +1 -0
  17. package/dist/body-worker-start.js.map +1 -0
  18. package/dist/body-worker-start.mjs +1 -0
  19. package/dist/body-worker-start.mjs.map +1 -0
  20. package/dist/body-worker-unbundled.d.ts +1 -0
  21. package/dist/body-worker-unbundled.mjs +1 -0
  22. package/dist/body-worker-unbundled.mjs.map +1 -0
  23. package/dist/body-worker.d.ts +1 -0
  24. package/dist/body-worker.js +1 -0
  25. package/dist/body-worker.js.map +1 -0
  26. package/dist/errors.d.ts +224 -28
  27. package/dist/index.bundler.mjs +1 -0
  28. package/dist/index.bundler.mjs.map +1 -0
  29. package/dist/index.d.ts +23 -28
  30. package/dist/index.js +1 -2354
  31. package/dist/index.js.map +1 -0
  32. package/dist/index.mjs +1 -2297
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/leave.d.ts +67 -0
  35. package/dist/module-of.d.ts +58 -0
  36. package/dist/network.d.ts +163 -4
  37. package/dist/privacy.d.ts +387 -12
  38. package/dist/recorder.d.ts +304 -64
  39. package/dist/redact.d.ts +48 -6
  40. package/dist/request-term.d.ts +23 -0
  41. package/dist/request-term.js +1 -0
  42. package/dist/request-term.js.map +1 -0
  43. package/dist/request-term.mjs +1 -0
  44. package/dist/request-term.mjs.map +1 -0
  45. package/dist/strict-attributes.d.ts +9 -0
  46. package/dist/strict-attributes.js +1 -0
  47. package/dist/strict-attributes.js.map +1 -0
  48. package/dist/strict-attributes.mjs +1 -0
  49. package/dist/strict-attributes.mjs.map +1 -0
  50. package/dist/term-candidate.d.ts +16 -0
  51. package/dist/transport.d.ts +269 -130
  52. package/dist/types.d.ts +152 -9
  53. package/package.json +37 -4
  54. package/request-term/package.json +6 -0
  55. package/strict-attributes/package.json +6 -0
package/README.md CHANGED
@@ -1,57 +1,53 @@
1
1
  # @keploy/capture-sdk
2
2
 
3
- The browser SDK for [Keploy UI Flow Capture](https://keploy.io/docs/ui-capture/overview/).
3
+ The browser SDK for [Keploy UI Capture](https://keploy.io/docs/running-keploy/ui-capture/).
4
4
  It records what a real user does in your web app — the DOM through
5
5
  [rrweb](https://github.com/rrweb-io/rrweb), and every `fetch` and
6
6
  `XMLHttpRequest` exchange the page makes — masks personal data before
7
7
  anything leaves the browser, and posts the recording in batches to
8
- Keploy. Keploy turns the recordings into deduplicated flows and, from
9
- those, into Playwright tests that replay against recorded mocks.
8
+ Keploy. Keploy turns the recordings into deduplicated flows; turning
9
+ flows into Playwright tests that replay against recorded mocks is the
10
+ next step of the product and not in this release (see below).
10
11
 
11
12
  This package runs inside your bundle, on your users' machines, which is
12
13
  why it is **Apache-2.0** while the rest of the product is proprietary.
13
- It is the only part of UI Flow Capture on npm: the tests are generated
14
- and run by the `keploy` binary, not by another package.
14
+ It is the only part of Keploy UI Capture on npm.
15
+
16
+ > The UI Capture guide and the two screenshots below are published with
17
+ > the docs release that accompanies this SDK release; until then those
18
+ > links answer 404.
15
19
 
16
20
  ## What ships today
17
21
 
18
22
  **The version is the git tag's** -- the committed manifest says
19
23
  `0.0.0-tag` and the release lane writes the tag's version in before it
20
24
  publishes (`RELEASING.md` in the repository; `sdk.version` on every
21
- batch is that number). **The pipeline behind the SDK is mid-migration.**
22
- The SDK
23
- records, masks and posts as this page describes. What happens to a
24
- recording after it arrives does not all exist yet: the ingest route and
25
- the app-bound keys it needs are on an unmerged branch of the Keploy API
26
- server, so no deployment has them; flow extraction writes one
27
- placeholder flow with no steps; **Generate Test** produces no files and
28
- **Run Test** executes nothing. The
29
- [overview](https://keploy.io/docs/ui-capture/overview/) has the
30
- part-by-part list under "What ships today", and the screenshots below
31
- show what the dashboard will do with a recording, not what today's
32
- pipeline produces from one.
33
-
34
- Those docs pages, and the images below, publish with the docs release
35
- that accompanies this package. If you are reading this before that
36
- lands, they 404; [support@keploy.io](mailto:support@keploy.io) has the
37
- current state.
25
+ batch is that number).
26
+
27
+ What works end to end: this SDK records, masks and posts as this page
28
+ describes; Keploy's API server accepts the recording with an app's UI
29
+ ingest key; a visit becomes **UI flows** once it has been idle for the
30
+ server's window (30 minutes by default) -- the steps a user took and the
31
+ network calls they made -- and you read them in the Keploy dashboard,
32
+ over the REST API (`/client/v1/apps/<appId>/ui/capture-status` and
33
+ `/ui/flows`), or from an AI agent through the Keploy MCP server
34
+ (`uiCaptureSetup`, `uiCaptureStatus`, `listUIFlows`). The
35
+ [UI Capture guide](https://keploy.io/docs/running-keploy/ui-capture/)
36
+ walks through all three.
37
+
38
+ Not in this release: generating Playwright tests from flows and running
39
+ them. Flows are what you get today.
38
40
 
39
41
  ## What you get
40
42
 
41
- Recorded sessions become flows in the Keploy dashboard:
43
+ Each visit becomes flows, listed per app in the Keploy dashboard:
42
44
 
43
- ![The UI Flows list: each flow with its page path, step count, how many sessions matched it, and its verdict on the last run](https://raw.githubusercontent.com/keploy/docs/main/static/img/ui-capture/flows.png)
45
+ ![The UI Flows list: each flow with its page path, step count and the network calls it made](https://raw.githubusercontent.com/keploy/docs/main/static/img/ui-capture/ui-capture-flows.webp)
44
46
 
45
47
  Each flow is the sequence of steps a user took, with every network call
46
48
  those steps made recorded beside them:
47
49
 
48
- ![A flow's detail page: the recorded steps down the left, the network calls captured for the flow on the right](https://raw.githubusercontent.com/keploy/docs/main/static/img/ui-capture/flow-detail-full.png)
49
-
50
- And every run of the generated tests reports one verdict per flow —
51
- `passed`, `failed`, `blocked`, and the rest of the
52
- [closed verdict set](https://keploy.io/docs/ui-capture/overview/):
53
-
54
- ![The test runs page: one row per run with its per-flow verdicts and the worst-wins rollup](https://raw.githubusercontent.com/keploy/docs/main/static/img/ui-capture/test-runs.png)
50
+ ![A flow's detail page: the recorded steps down the left, the network calls captured for the flow on the right](https://raw.githubusercontent.com/keploy/docs/main/static/img/ui-capture/ui-capture-flow-detail.webp)
55
51
 
56
52
  ## Install
57
53
 
@@ -62,11 +58,106 @@ npm install @keploy/capture-sdk
62
58
  A runtime dependency, not a dev one: it runs in production, on the
63
59
  page. Its only dependency is `rrweb`, which your bundler resolves; there
64
60
  are no peer dependencies. The package ships ESM and CommonJS
65
- (`dist/index.mjs`, `dist/index.js`) with types. The bundle is 26.2 kB
66
- (decimal) gzipped with rrweb excluded — MEASURED on the publish build
67
- (`tsup src/index.ts`), and a test holds both that figure and the 30 KiB
68
- ceiling this package is budgeted at. There is no script-tag build: the
69
- only way in is an `import`.
61
+ (`dist/index.mjs`, `dist/index.js`) with types, and a second ESM build,
62
+ `dist/index.bundler.mjs`, for the bundlers that read the `module` field
63
+ rather than the `exports` map (webpack 4, Parcel by default): the same
64
+ SDK without the worker start a page with no bundler loads from beside
65
+ it (see below), so webpack 4 never reads `import.meta`, for the web or
66
+ for node. The bundle is 40.7 kB
67
+ (decimal) gzipped with rrweb excluded -- the ESM build; the CommonJS
68
+ build is 40.9 kB and the `module` field's build is 40.6 kB, and
69
+ `privacyMode: "strict"` alone loads its 1.3 kB attribute allow-list
70
+ beside it -- MEASURED on the repository's build at its
71
+ placeholder version (`pnpm build`, which runs `node scripts/build-main.mjs`);
72
+ the published build carries its version in place of the placeholder,
73
+ which moves both figures by a few bytes either way (MEASURED for
74
+ 3.1.0-rc.1: 2 B more on each build). It is fully minified, so its
75
+ local names are shortened: that is what keeps an SDK that redacts what
76
+ it records, in the browser, under its budget: 40 KiB, and 41,316 B for
77
+ the CommonJS build, set on 2026-11-11 as 40 KiB plus the 356 B its
78
+ format cost then (as built now, the format costs 226 B). Body
79
+ redaction is not in it: it runs in
80
+ a Web Worker, `dist/body-worker.js` (9.3 kB gzipped), which your bundler
81
+ emits beside your app and the SDK starts when a capture that redacts
82
+ bodies starts, in the page's next idle period; its main-thread copy,
83
+ `dist/body-redact.mjs` (9.4 kB), is a chunk `init()` asks for at once
84
+ for such a capture, beside rrweb, while your page's network is recorded
85
+ from the start (see [Your page's own network](#your-pages-own-network)).
86
+ A capture that masks bodies whole (`privacy.maskNetworkBodies`, which
87
+ `privacyMode: "strict"` sets) loads neither. The source maps ship
88
+ beside it as separate files, `dist/index.mjs.map`,
89
+ `dist/index.bundler.mjs.map` and `dist/index.js.map`, never inlined and carrying the SDK's own sources,
90
+ so a stack trace from the page decodes back to the SDK's functions and
91
+ lines in any tool that reads source maps. A test holds the figures, the maps and the limits: the 40 KiB
92
+ budget this package is held to, and 12 KiB for each body chunk. There is no
93
+ script-tag build: the only way in is an `import`, and the SDK loads
94
+ `rrweb` with `import("rrweb")`, which a bundler resolves. Without one,
95
+ map the
96
+ specifier with an import map (`<script type="importmap">{"imports":
97
+ {"rrweb": "<url of rrweb's dist/rrweb.js>"}}</script>`) before the SDK
98
+ loads; if rrweb cannot be loaded in a browser the capture ends before
99
+ anything is sent and says so (`KUI_E_DOM_RECORDER_UNAVAILABLE`) rather
100
+ than recording nothing in silence.
101
+
102
+ A bundler that ignores a package's `exports` map -- webpack 4, as under
103
+ Create React App 4, or Parcel 2 by default -- resolves the SDK's
104
+ `request-term` and `strict-attributes` subpaths through the
105
+ `request-term/package.json` and `strict-attributes/package.json` the
106
+ package ships. **Parcel 2 needs the `buffer` package installed** (`npm
107
+ install buffer`): rrweb's build reads Node's `Buffer`, and Parcel
108
+ polyfills no Node built-in it is not given. That is rrweb's need, not
109
+ new in this version; 3.0.1 has it too.
110
+
111
+ The body worker is started as `new Worker(new URL("./body-worker.js",
112
+ import.meta.url))`, which webpack 5, Next.js (webpack and Turbopack),
113
+ Vite and Parcel 2 turn into a file of your build (each is built in the
114
+ SDK's tests). These setups have no worker, and redact bodies on the
115
+ page's main thread instead, each body only up to 64 KiB (see [What a
116
+ large body looks like](#what-a-large-body-looks-like)):
117
+
118
+ - **webpack 4** cannot parse `import.meta`, so the SDK keeps it out of
119
+ every file webpack 4 reads.
120
+ - **esbuild** does not emit the worker: copy
121
+ `node_modules/@keploy/capture-sdk/dist/body-worker.js` beside your
122
+ bundle and it runs.
123
+ - **A build whose assets are served from another origin** (webpack's
124
+ `publicPath` or Next's `assetPrefix` on a CDN): a browser runs a
125
+ worker only from the page's own origin.
126
+ - **A Content-Security-Policy that does not let your origin run it**:
127
+ allow `worker-src 'self'` (or the `child-src` or `script-src` it falls
128
+ back to).
129
+ - **The SDK's files served from another origin without a bundler** (a
130
+ CDN): the chunks load from there (it must send CORS headers, as CDNs
131
+ do), the worker cannot. Import `dist/index.mjs` by its path. unpkg's
132
+ package root redirects there too; jsDelivr's answers with the file at
133
+ the root's own URL, where no chunk is beside it, so name the path
134
+ there. The SDK loads only chunks of its own version: unpkg's `?module`
135
+ rewrites the SDK's imports of its own name to the `@latest` version's
136
+ files, which `dist/index.mjs` refuses, loading its own from beside it.
137
+ A package-root URL with `?module` serves the `module` field instead,
138
+ `dist/index.bundler.mjs` (webpack 4's build), which loads no chunk from
139
+ beside it, and records every body as not captured (see below) -- and
140
+ refuses
141
+ every strict capture with `KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE`,
142
+ having no allow-list to load.
143
+
144
+ **Without a bundler**, serve the package's `dist/` directory as it is
145
+ and import `dist/index.mjs` from it, with an import map for `rrweb`
146
+ alone: the SDK loads its chunks and the worker from beside
147
+ `dist/index.mjs` (`dist/body-redact.mjs`, `dist/request-term.mjs`,
148
+ `dist/strict-attributes.mjs` under strict, and
149
+ `dist/body-worker-unbundled.mjs`, which starts `dist/body-worker.js`),
150
+ and an import map that maps `@keploy/capture-sdk/body-redact`,
151
+ `/body-worker-start`, `/request-term` or `/strict-attributes` is
152
+ honoured first. A page that serves `dist/index.mjs` alone has no code
153
+ to redact a body with, and records each body as not captured, never in
154
+ the clear (under strict it records nothing, refused with
155
+ `KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE`):
156
+
157
+ ```
158
+ [Body cut: 0 of N characters kept, unverified]
159
+ [Body not captured: the redaction code could not load]
160
+ ```
70
161
 
71
162
  ## Use
72
163
 
@@ -91,26 +182,28 @@ any other kind of Keploy credential here.
91
182
  Those two are the only required fields. The others, with the value the
92
183
  SDK uses when you leave them out:
93
184
 
94
- | option | default | what it does |
95
- | -------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
96
- | `privacyMode` | `"balanced"` | `"balanced"` masks every typed input value; `"strict"` also masks every visible text node; `"off"` masks only password and hidden fields — see [Privacy](#privacy) |
97
- | `sampleRate` | `1` | fraction of sessions recorded, decided once when a session starts. `0.1` records one visitor in ten; the rest never start |
98
- | `networkCapture` | `true` | record `fetch` and `XMLHttpRequest` exchanges. `false` records the DOM only |
99
- | `maxSessionDuration` | `600000` | milliseconds after which the capture ends on its own (10 minutes): recording stops, the queue is flushed, and a later `init()` starts a new session |
100
- | `batchSize` | `50` | events per POST, as a ceiling: clamped to 5000, the most the ingest server accepts in one batch, and a batch is also cut at the server's 10 MiB body cap, so large events make more, smaller POSTs rather than one the server would refuse |
101
- | `batchInterval` | `5000` | milliseconds between flushes. Each flush sends ONE batch, so a backlog drains at a batch per interval |
102
- | `maxQueueSize` | `5000` | events held in memory while waiting to send; past this the oldest are dropped |
103
- | `maxBodySize` | `524288` | how much of a request or response body is recorded (512 KB), counted in UTF-16 code units — see [What a large body looks like](#what-a-large-body-looks-like) |
104
- | `maskSelectors` | — | CSS selectors whose matched elements have their text masked, including every text node below them. Input values are decided by `privacyMode` alone |
105
- | `unmaskSelectors` | — | CSS selectors whose text is left in the clear, overriding `maskSelectors` and `"strict"` for the subtree below them. It cannot unmask an input value |
106
- | `privacy` | — | a `Partial<PrivacyConfig>`: `maskSelectors`, `unmaskSelectors`, `blockSelectors`, `maskNetworkBodies`, `sensitiveHeaders`, `piiPatterns` — see [Privacy](#privacy) |
107
- | `sessionIdGenerator` | — | supply your own session id instead of the SDK's UUID v4, to correlate with your own systems. It must be a string of 1-200 characters of letters, digits, dot, dash and underscore with no empty dot-separated segment (`tenant-7.user_42.run-3`; encode a `user:42/session 1` first) — the SDK checks what the generator produces before sending and refuses to start on anything else, a throw included (`KUI_E_SESSION_ID_INVALID`). Two live sessions with one id are refused by the server (a terminal `409`) |
108
- | `onError` | — | called once when a terminal condition ends the capture — see [When the server rejects a batch](#when-the-server-rejects-a-batch) |
185
+ | option | default | what it does |
186
+ | --------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
187
+ | `privacyMode` | `"balanced"` | `"balanced"` masks every typed input value; `"strict"`, for public sites, records no page text -- it also masks every visible text node, blanks every attribute, `<meta>` content and comment that holds text, records no request or response body and replaces every query value in a URL; `"off"` masks only password and hidden fields — see [Privacy](#privacy) |
188
+ | `sampleRate` | `1` | fraction of sessions recorded, decided once when a session starts. `0.1` records one visitor in ten; the rest never start |
189
+ | `networkCapture` | `true` | record `fetch` and `XMLHttpRequest` exchanges. `false` records the DOM only |
190
+ | `maxSessionDuration` | `600000` | milliseconds after which a session ends on its own (10 minutes): recording stops, the queue is flushed, and a later `init()` starts a new session -- or, with `continuous`, the next one starts by itself |
191
+ | `continuous` | `false` | keep capturing for the life of the page, one session at a time: a session that ends (at `maxSessionDuration`, or because the server completed or filled it) is followed by a new one at the visitor's next click, tap or key press, so an idle tab posts nothing. Has no effect with a `sessionIdGenerator`: that id is yours, and a second session under it would be refused — see [Single-page apps](#single-page-apps) |
192
+ | `batchSize` | `50` | events per POST, as a ceiling: clamped to 5000, the most the ingest server accepts in one batch, and a batch is also cut at the server's 10 MiB body cap, so large events make more, smaller POSTs rather than one the server would refuse |
193
+ | `batchInterval` | `5000` | milliseconds between flushes. Each flush sends ONE batch, so a backlog drains at a batch per interval (after an outage, the first upload accepted sends it all) |
194
+ | `maxQueueSize` | `5000` | events held in memory while waiting to send; past this, or past 16 MiB of them, the oldest are dropped |
195
+ | `maxBodySize` | `524288` | how much of a request or response body is recorded (512 KB), counted in UTF-16 code units — see [What a large body looks like](#what-a-large-body-looks-like) |
196
+ | `maskSelectors` | — | CSS selectors whose matched elements have their text masked, including every text node below them. Input values are decided by `privacyMode` alone |
197
+ | `unmaskSelectors` | — | CSS selectors whose text is left in the clear, overriding `maskSelectors` and `"strict"` for the subtree below them. It cannot unmask an input value |
198
+ | `privacy` | — | a `Partial<PrivacyConfig>`: `maskSelectors`, `unmaskSelectors`, `blockSelectors`, `maskNetworkBodies`, `sensitiveHeaders`, `piiPatterns`, `secretRoutes`, `keepRoutes` — see [Privacy](#privacy) |
199
+ | `sessionIdGenerator` | — | supply your own session id instead of the SDK's UUID v4, to correlate with your own systems. It must be a string of 1-200 characters of letters, digits, dot, dash and underscore with no empty dot-separated segment (`tenant-7.user_42.run-3`; encode a `user:42/session 1` first) — the SDK checks what the generator produces before sending and refuses to start on anything else, a throw included (`KUI_E_SESSION_ID_INVALID`). Two live sessions with one id are refused by the server (a terminal `409`) |
200
+ | `honorPrivacySignals` | `true` | when the browser sends Do Not Track (`navigator.doNotTrack === "1"`) or Global Privacy Control (`navigator.globalPrivacyControl === true`), `init()` records, patches and sends nothing and reports `KUI_E_CAPTURE_DECLINED` to `onError` on every declined `init()` and by `console.info` once per page. `false` records regardless — only where the site has its own lawful basis and says so in its privacy policy |
201
+ | `onError` | — | called once when a terminal condition ends the capture — see [When the server rejects a batch](#when-the-server-rejects-a-batch) |
109
202
 
110
203
  After `init`, the static surface is:
111
204
 
112
205
  ```ts
113
- KeployCapture.pause(); // keep the session, stop emitting events
206
+ KeployCapture.pause(); // keep the session, record nothing more
114
207
  KeployCapture.resume();
115
208
  KeployCapture.getSessionId(); // "" when no session is live
116
209
  KeployCapture.getCaptureIdentity(); // the browser half of the backend join, or why there is none
@@ -120,17 +213,205 @@ KeployCapture.stop(); // stop recording and send what is queued
120
213
  `init` returns the same instance on a second call; `stop` clears it so
121
214
  a later `init` starts a new session.
122
215
 
216
+ ### Single-page apps
217
+
218
+ A route change without a page load -- `history.pushState`, the visitor
219
+ going back or forward, a hash router's `#/route` -- is recorded the way
220
+ rrweb records a load, as a Meta event with the new URL, so each step
221
+ belongs to the page it happened on. A change of the query alone --
222
+ pushed, replaced or traversed, a router syncing filter or search state
223
+ -- is not a page change and records nothing, so a search box that
224
+ pushes `?q=` per keystroke records no navigation of its own. The URL
225
+ recorded is always the one the page is on: the snapshot a returning tab
226
+ or `resume()` takes carries the query as it is, so a query the page
227
+ changed in the meantime starts the flow after it at that exact URL --
228
+ the one its replay has to open. An in-page anchor (`#reviews`) is not a
229
+ page change either.
230
+
231
+ Each route change's Meta event also says what moved the page, as
232
+ `cause`: `push` or `replace` (a navigation that added or replaced a history
233
+ entry: `history.pushState`, a `replaceState` that changes the path -- a
234
+ redirect), `traverse` (a move through the session history: the browser's
235
+ Back or Forward, or the page's own `history.back()` or `go()`) or `hash` (a
236
+ fragment navigation the History API did not make: a link to `#/route`,
237
+ `location.hash = ...`). rrweb's own Meta, written with every full snapshot
238
+ (a load, a returning tab, `resume()`), has none. Where the browser has the
239
+ Navigation API, the route Meta also carries `userInitiated`, as its
240
+ `navigate` event said it. The standard makes it `true` when the visitor
241
+ started the move -- the browser's Back or Forward, a click on a link, a
242
+ form submitted -- and `false` when the page's script did (an in-app Back
243
+ button calling `history.back()`, a `pushState`). Engines differ, and the
244
+ SDK records what each says without correcting it. MEASURED with
245
+ Playwright 1.63's builds: a click on a plain link is `true` in Chromium,
246
+ Firefox and WebKit; a `pushState` or `history.back()` made in a click
247
+ handler is `false` in Chromium and Firefox and `true` in WebKit (it
248
+ reads the click's user activation); Playwright's `page.goBack()` is
249
+ `true` in Chromium and `false` in Firefox and WebKit (a real Back button
250
+ was not measured). So neither value alone tells an in-app Back from the
251
+ browser's own in every engine. The field is absent where the browser has
252
+ no Navigation API, for a move found late (below), and when the navigate
253
+ event named another URL than the one the page moved to: never guessed.
254
+
255
+ A traversal the page's own script asked for -- `history.back()`,
256
+ `forward()` or `go()`, as an in-app Back button calls them, or the
257
+ Navigation API's `navigation.back()`, `forward()` or `traverseTo()` --
258
+ also carries `initiator: "script"`, so a recording tells it from the
259
+ browser's Back in every engine that has the Navigation API, WebKit
260
+ included. The SDK wraps those methods as it wraps `pushState`: a call
261
+ notes the entry it names in `navigation.entries()` (`traverseTo()` names
262
+ its key), and a traversal the `navigate` event announces to a noted entry
263
+ is the call's. Calls made before the first has moved count as each engine
264
+ moves them, MEASURED: Chromium and Firefox move once per call, each counted
265
+ on from the entry the call before it named, so two `history.back()` in one
266
+ handler move twice and both moves carry `initiator: "script"`; a call
267
+ counted on to the entry the page is on moves nothing, and Chromium drops a
268
+ call that names no entry from where the page is (`back()` then `forward()`
269
+ from the last entry moves back, the script's). WebKit moves once, to the
270
+ entry the last call named from where the page was, and that move carries
271
+ it. A move to an entry an earlier call of several named is credited only
272
+ when its `navigate` event says `userInitiated: false`, as Chromium and
273
+ Firefox say of the page's moves; a call made while another wrapped call
274
+ runs (a polyfill's `navigation.back()` calling `history.back()`) is the
275
+ outer call's. A `pushState` in the task of a call drops the entries after
276
+ the current one alone, and MEASURED, Chromium and WebKit still move to an
277
+ entry before it that the call named (`back()` then a push in one handler,
278
+ as a page closes a modal and routes), so that move carries it too; a call
279
+ made after the push counts from the pushed entry. A `go()` given a
280
+ string reads it as the browser does (`go("-1")`). The field is absent
281
+ otherwise: for the browser's own Back and Forward, where the browser has no
282
+ Navigation API, for a `go()` given an object or a `traverseTo()` given
283
+ anything but a string, for a call that names no entry of the page's, for a
284
+ call whose entry a push dropped, and for a `back()` a router kept from
285
+ before `init()`, which passes no wrapper. The limits, MEASURED: a note no
286
+ traversal's `navigate` event spends stays for the next one; past a push, a
287
+ queued one stays while its entry is before the current one. A call whose
288
+ traversal fires the page none -- the browser applies it to another frame's history
289
+ (an iframe that navigated since, or the parent's when the page is itself a
290
+ frame), or drops it -- leaves its note so, and a traversal the browser
291
+ makes to the entry a call named, before the call's own move, takes it:
292
+ each is then recorded as the script's. MEASURED in Chromium, Firefox and
293
+ WebKit: after an in-app Back moved a same-origin iframe's history,
294
+ Playwright's `page.goBack()` to the entry it named is recorded with
295
+ `initiator: "script"`. The next call also counts on from such a call's
296
+ entry, as from a pending one's: after that in-app Back, a second one's move
297
+ is the script's but leaves the entry before it noted, and a later traversal
298
+ there that says `userInitiated: false` is the script's. MEASURED in
299
+ Firefox, where `page.goBack()` says `false`: it is recorded with
300
+ `initiator: "script"`. And the calls WebKit drops: its one move for
301
+ overlapping calls made with no user gesture says `userInitiated: false`, as
302
+ Chromium's first of several does, and calls whose last names no entry from
303
+ where the page is move nothing, so the entries the dropped calls named stay
304
+ noted, and a later traversal to one that says `false` is the script's.
305
+ MEASURED in WebKit: after two `history.back()` from a timer 1.5 s after a
306
+ click, which WebKit runs with no user gesture, and after `back()` then
307
+ `forward()` from the last entry in a click handler, `page.goBack()` (which
308
+ says `false` there) is recorded with `initiator: "script"`. During a user
309
+ gesture WebKit says `true` for its one move, and the notes go with it. And
310
+ where Chromium and Firefox count differently, after a call that names no
311
+ entry from where the page is, the SDK counts as Chromium does: a move of
312
+ Firefox's that it did not count, and an earlier move of the same calls to
313
+ the same entry, are recorded with no `initiator`. MEASURED in Firefox:
314
+ `back()`, `forward()`, `back()` from the last entry moves to the entry
315
+ before it twice, and `back()`, `back()`, `forward()` moves to the two
316
+ entries before it and forward again; those moves to the entry before the
317
+ last carry no `initiator`. And Firefox drops the calls pending at a
318
+ `pushState` in their task (with a push a task later it moves too), which
319
+ nothing tells from Chromium's move to come when the push is made. Their
320
+ notes stay at the head of the queue until its next traversal, which spends
321
+ them, and the notes of calls queued behind them, unless it goes straight to
322
+ such an entry and says `userInitiated: false`. MEASURED in Firefox: after
323
+ `back()` then a push, `page.goBack()` (to the entry before the pushed one)
324
+ carries no `initiator`, and of two `back()` in a later click the first move
325
+ carries it and the second does not. A fragment push in the calls' task
326
+ (`location.hash`, `navigation.navigate("#x")`) moves Firefox one back from
327
+ the pushed entry, which no call named, with no `initiator`, and a push a
328
+ `popstate` listener makes before Firefox's next move commits spends that
329
+ move's credit. WebKit also drops the calls pending at an intercepted
330
+ `navigation.navigate()`, and their notes stay. And WebKit's move for overlapping
331
+ calls with no user gesture, when it goes past the first note, loses its
332
+ note at a push, which says `false` then: `go(-1)`, `go(-2)` and a push from a
333
+ timer carry no `initiator`.
334
+
335
+ Where the browser has the
336
+ Navigation API (the Chromium, Firefox and WebKit builds Playwright 1.63
337
+ ships all do), its `currententrychange` decides: it comes
338
+ before `popstate`, so Back is a `traverse` even when a router re-stamps or
339
+ redirects from its own `popstate` listener (the redirect is then a
340
+ `replace` of its own), and it also reports a navigation that calls no
341
+ `pushState`, such as one an app intercepts with `navigation.navigate()`.
342
+ Without it, the History API calls and the `popstate` and `hashchange`
343
+ events decide. The SDK's listeners are capture listeners, which the DOM
344
+ standard runs before every non-capture listener the page added (Firefox
345
+ and WebKit do), so Back is still a `traverse` before a router's redirect;
346
+ a History API call at the URL Back reached, from a listener that ran
347
+ first, is read as Back too. Chromium runs the listeners at the window in
348
+ the order they were added, which matters only without the Navigation API,
349
+ and every Chromium that ships has it. And a fragment navigation, which fires `popstate` before
350
+ `hashchange` as Back between two fragments does, reads as `traverse` --
351
+ `hash` is recorded only where the browser has the Navigation API. The SDK
352
+ wraps `pushState` and `replaceState` (and `back`, `forward` and `go`, and
353
+ `navigation.back`, `forward` and `traverseTo`) once per page and records a
354
+ change only once the URL has changed; a router that wraps any of them
355
+ after the SDK keeps its wrapper when the capture stops, and so does a page
356
+ that made the SDK's wrapper impossible to put back. It wraps all of them
357
+ or none, so that a route Meta without `initiator` means the same on every
358
+ page: a page that made one impossible to replace and put back before
359
+ `init()` (an own property neither writable nor configurable, a `history`
360
+ or `navigation` that takes no new property) gets no wrapper at all, and
361
+ the capture says so once on the console as `KUI_E_NAVIGATION_UNWRAPPED`
362
+ (below). Its route changes are still recorded, from its navigation events,
363
+ with less detail: no traversal carries `initiator`; where the browser has
364
+ the Navigation API, a `pushState` to a fragment reads as `hash`; where it
365
+ has none, a `pushState` or `replaceState` is found only at the next
366
+ recorded event, as a `push`, two before it read as one, and a credential
367
+ the page pushed into its URL and hid again before that event is not
368
+ collected, so it is not scrubbed. A router that calls a
369
+ `pushState` or `replaceState` it kept from before `init()` (SvelteKit
370
+ does) passes no wrapper: the Navigation API still reports the move, and
371
+ without it the move is found when the next event is recorded and is
372
+ recorded before that event: as a `traverse` when that event comes inside
373
+ a `popstate` (a listener the page runs before the SDK's re-rendered),
374
+ otherwise as a `push`, a `replace` included (it can no longer be told
375
+ from one).
376
+
377
+ One page load can stay open for hours, and a capture otherwise ends at
378
+ `maxSessionDuration`. Set `continuous: true` to keep recording it in
379
+ sessions of that length; each becomes flows on its own. A session the
380
+ server says it has completed or filled (the refusal's `reason` is
381
+ `session_completed` or `session_full`, which the ingest server sends
382
+ from the api-server release that stores UI capture data in its own
383
+ collections) is followed the same way; a server that predates that
384
+ field keeps the refusal terminal. With a `sessionIdGenerator`,
385
+ `continuous` has no effect: the capture ends at `maxSessionDuration`
386
+ and at those refusals as it does without it, because the id is yours --
387
+ usually one per visit -- and a second session under it would be
388
+ refused. A
389
+ `KeployCapture.pause()` in force when a session ends -- or made while
390
+ the next one waits -- carries into the next one, which records nothing
391
+ until `resume()`, even when that next one is started by an explicit
392
+ `init()`. `stop()` ends the capture for good, waiting included.
393
+
123
394
  A hidden tab pauses DOM recording and nothing else — the exchanges the
124
395
  page makes are still recorded, because the page still makes them and
125
396
  they are what a replay needs. When the tab comes back, the SDK takes a
126
397
  fresh full snapshot **only if the paused recording dropped something**:
127
398
  rrweb has no pause, so it kept observing while the tab was hidden, and
128
399
  the mutations that were dropped would otherwise leave the events after
129
- them naming nodes the recording never showed. A hide that dropped
400
+ them naming nodes the recording never showed -- or if a snapshot the
401
+ recording is still waiting for (one too big to send, retried on its
402
+ backoff) has not been sent. While uploads to the ingest are failing, or after
403
+ an event was dropped while the browser said it was offline, that snapshot
404
+ waits until the outage ends. A hide that dropped
130
405
  nothing has nothing to re-baseline and takes none, so a visitor who
131
406
  alt-tabs thirty times on a page that is not mutating uploads no
132
- snapshots for it. `pause()` is the stronger one and stops everything,
133
- and `resume()` re-snapshots under the same condition.
407
+ snapshots for it. `pause()` is the stronger one: nothing more is
408
+ recorded -- no DOM event, and no network exchange that starts or is
409
+ answered while paused, even one whose answer arrives after `resume()` --
410
+ and `resume()` re-snapshots under the same condition. An exchange still
411
+ reading its body at `pause()` (a stream, a long download) is recorded
412
+ then, with what had arrived, cut and marked `...[truncated]` as when the
413
+ page leaves, and nothing of it after, `resume()` included; the page's
414
+ own read of it goes on untouched.
134
415
 
135
416
  What network capture **is** gated on is the rrweb import. `init()`
136
417
  awaits `import("rrweb")` before it patches `fetch` and
@@ -141,6 +422,42 @@ in that window is not recorded at all, in a hidden tab exactly as in a
141
422
  visible one. Calling `init()` as early in startup as you can narrows
142
423
  that window; nothing closes it.
143
424
 
425
+ An `init()` called while the browser is offline is the exception: it
426
+ does not ask for rrweb until the browser is back online (a browser keeps
427
+ a failed module import for the life of the page), patches `fetch` and
428
+ `XMLHttpRequest` at once, and sends nothing it records until rrweb has
429
+ loaded -- if it cannot, the capture is refused with
430
+ `KUI_E_DOM_RECORDER_UNAVAILABLE` and what was recorded meanwhile is
431
+ dropped. That the browser is back is heard as the `online` event or
432
+ read, once a second while the capture waits, from `navigator.onLine`: a
433
+ page whose own listener stops the event (`stopImmediatePropagation`) is
434
+ recorded all the same. Unless a service worker controls the page
435
+ (`navigator.serviceWorker.controller`): a worker can answer the import
436
+ with no network, and a page that starts offline at all is most often
437
+ one a worker served, so there `init()` asks for rrweb at once and
438
+ records what the visitor does offline. Precache rrweb's chunk with the
439
+ rest of the app. ANY worker in control counts, one with no `fetch`
440
+ handler included: an `init()` called offline under it asks at once, a
441
+ worker that cannot answer fails the import, and the capture is refused
442
+ at `init()` -- and again at an `init()` made once the browser is back
443
+ online (MEASURED in review, in Chromium, with a push-only worker, 4
444
+ times of 4): the browser keeps the failed import until the page is
445
+ loaded again.
446
+
447
+ Once rrweb has loaded, what was held is sent in order, one batch
448
+ (`batchSize` events) per round trip, and a visitor who leaves while
449
+ more is still waiting than one unload request carries (32 KiB, below)
450
+ loses the first event that does not fit and everything behind it: a
451
+ snapshot larger than that by itself, or a smaller one whose backlog has
452
+ not gone yet. MEASURED in review, in Chromium, when that request carried
453
+ 64 KiB (before 3.1.0-rc.2; the 51 KB and 53 KB snapshots below are now
454
+ over it, so they are sent the moment they are queued), with a navigation 100 ms
455
+ after the network came back: a 141 KB snapshot behind the requests a
456
+ page made offline was lost 4 times of 4 (an ingest answering in
457
+ 150 ms), and a 51 KB one 3 times of 3 behind 95 requests, where behind
458
+ 30 it arrived 3 of 3; a 53 KB one behind 95 requests, with the visitor
459
+ leaving 0.8 s after the network came back, arrived 4 of 4.
460
+
144
461
  ## Privacy
145
462
 
146
463
  Masking happens in the browser, before transport. Nothing here can be
@@ -170,10 +487,10 @@ Those two are the reason this SDK hands rrweb its own map: rrweb's
170
487
  `maskAllInputs` covers the other sixteen rows and neither of these.
171
488
 
172
489
  `radio`, `checkbox`, `submit`, `button`, `reset` and `image` are **not**
173
- in that table: their `value` is recorded verbatim in every mode,
174
- `strict` included. For the first four nothing can reach it —
175
- rrweb serialises those four before masking is consulted, so no option
176
- this SDK could pass would change them. `reset` and `image` could be
490
+ in that table: their `value` is recorded verbatim under `balanced` and
491
+ `off`, and blanked under `strict` (below). For the first four rrweb
492
+ serialises the value before masking is consulted, so no option this
493
+ SDK could pass rrweb would change them; strict blanks them after. `reset` and `image` could be
177
494
  masked and deliberately are not: a reset button's value is the caption
178
495
  it shows, and an image button's is metadata the page's author wrote,
179
496
  neither being anything the person using the page entered. For the
@@ -182,6 +499,84 @@ whose value is an email address, say — the only lever is
182
499
  `privacy.blockSelectors`, and that removes the element from the
183
500
  recording altogether.
184
501
 
502
+ **Strict records no page text in the DOM.** Text lives in more places
503
+ than text nodes, and a page can copy a visitor's search into any of them
504
+ (a search page's `<title>` and `<meta name="description">`). Under
505
+ `strict`, attributes are read by an ALLOW-LIST: an attribute keeps its
506
+ value only when its name is the page's structure -- `id`, `class`,
507
+ `role`, `name`, `type`, `data-testid`, ARIA state and relationships
508
+ (`aria-expanded`, `aria-labelledby`), form and layout attributes (`for`,
509
+ `disabled`, `colspan`, `width`), SVG geometry and paint (`d`,
510
+ `viewBox`, `fill`) and rrweb's own -- or when its own rule reads it: a
511
+ URL (query values replaced), CSS, a `srcset`, a `srcdoc` (its text and
512
+ attributes masked the same way, its scripts included). Every other
513
+ value is recorded as `""`: `title`, `alt`, `placeholder`, `aria-label`
514
+ and the other `aria-*` text, every `data-*` but `data-testid`, every
515
+ `value` rrweb records in clear (a field's that rrweb masked keeps its
516
+ asterisks), a framework's state (`wire:snapshot`, `x-data`, `hx-vals`,
517
+ an Astro island's `props`), a custom element's attributes but its
518
+ global ones (`id`, `class`, `slot`, ARIA state), an input's `min`,
519
+ `max` and `pattern` (a date range copies the start the visitor picked
520
+ into the end's `min`; a confirm field copies a typed email into
521
+ `pattern`) and `aria-valuenow` (a slider's chosen value). SVG geometry
522
+ and paint are kept on SVG elements only, by exact name. A `<meta>`'s
523
+ `content` is blanked unless the meta configures the page (`http-equiv`,
524
+ or a `name` of `viewport`, `color-scheme`, `theme-color`, `referrer`,
525
+ `robots` or `format-detection`) -- in a mutation, unless the change itself carries that `http-equiv` or
526
+ `name`, and in a `srcdoc`, always. A comment is blanked; a checkbox's or
527
+ radio's value in an Input event is asterisks. The `<title>` element's
528
+ text and SVG `<text>` are text nodes, masked as every other.
529
+
530
+ The allow-list is a chunk of its own, `dist/strict-attributes.mjs`
531
+ (`.js` for CommonJS), which only `strict` loads: `balanced` and `off`
532
+ never ask for it and carry none of its bytes. Under `strict` the SDK
533
+ imports it at `init()`, in parallel with rrweb, and records nothing
534
+ until both have loaded, so no snapshot is ever taken without it. A
535
+ bundler emits it as a chunk; with no bundler, serve dist/ as it is and
536
+ the SDK loads it from beside `dist/index.mjs`. If it cannot be loaded (a
537
+ Content-Security-Policy, a network failure, a deployment that drops the
538
+ file), the capture ends before anything is recorded or sent, with
539
+ `KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE` (see [When the server rejects a batch](#when-the-server-rejects-a-batch)): strict
540
+ records nothing rather than attributes it cannot read.
541
+
542
+ ARIA under strict keeps what describes the widget -- its structure
543
+ (`aria-level`, `aria-posinset`, row and column counts), its relationships
544
+ (`aria-labelledby`, `aria-controls` and the other id references), its
545
+ configuration (`aria-haspopup`, `aria-orientation`, `aria-required`) and
546
+ `aria-expanded`/`aria-hidden` -- and blanks every one that reflects what
547
+ the visitor chose or entered: `aria-valuenow`, `aria-valuemin`,
548
+ `aria-valuemax` (a two-thumb slider's bounds are the other thumb's chosen
549
+ value), `aria-valuetext`, `aria-checked`, `aria-selected`,
550
+ `aria-pressed`, `aria-current`, `aria-sort`, `aria-invalid` and
551
+ `aria-activedescendant`; HTML's `checked` and `selected` are dropped
552
+ (rrweb records `checked` as a boolean, and its presence is the choice).
553
+ A checkbox's or radio's Input event still says whether it is checked
554
+ (`isChecked`): the replay needs it to click it. A
555
+ URL-named attribute (`href`, `src`, `action`, `data`, `cite` and the
556
+ rest) keeps a value only when it can be a URL -- no space, quote or
557
+ brace -- through the URL rule (path kept, query values replaced), on a
558
+ custom element as on any other; text in one is blanked.
559
+
560
+ What strict still records, so do not put a visitor's text there: URL
561
+ PATHS (`/search/<term>`, a `#/search/<q>` route, a `<link
562
+ rel="canonical">`; only query and fragment-pair values are replaced),
563
+ `id`s and `class`es, `data-testid` (an app that builds one from user
564
+ data, `row-${email}`, records it), a field's `name`, SVG geometry (a
565
+ signature pad's strokes are its `d`) and text under `unmaskSelectors`. A comment
566
+ outside `<html>` that changes after the snapshot is recorded as rrweb
567
+ records it. And the replay's look pays for it: CSS keyed on a `data-*`
568
+ (`[data-theme=dark]`, Radix's `data-state=open`) or on a `title` no
569
+ longer matches in a strict recording, and a `<progress>` or `<meter>`
570
+ shows no value; an animated or filtered SVG (SMIL `from`/`to`/`dur`,
571
+ filter `basefrequency`/`tablevalues`) and legacy table attributes
572
+ (`bgcolor`, `cellpadding`) replay without them. MEASURED on keploy.io/docs (Docusaurus), replayed
573
+ with rrweb: the layout, colours, cards and icons render and the text is
574
+ asterisks; the themed logo and the colour-mode toggle's icon are gone,
575
+ because Docusaurus shows them by `[data-theme]` CSS. Blank, not asterisks: the flow engine reads an empty
576
+ `aria-label` as none, so a strict recording never names an element by
577
+ a label it does not have; give a control that has only a label a
578
+ `data-testid`.
579
+
185
580
  `privacy.blockSelectors` names elements whose content is never
186
581
  recorded — a video, a chat widget, a wall of customer names — rrweb
187
582
  records an empty box of the same size in their place.
@@ -193,6 +588,21 @@ only: nothing you can name a selector for will un-mask an input value.
193
588
  Each has a top-level spelling and a `privacy.` one, and the two lists
194
589
  are merged rather than one taking precedence.
195
590
 
591
+ **Editors.** Text typed into a `contenteditable` — TipTap, Quill,
592
+ Lexical, ProseMirror — is typed text: masked under `balanced` and
593
+ `strict` as an input's value is, whatever `unmaskSelectors` says, and
594
+ recorded under `off`.
595
+
596
+ **Privacy signals.** Do Not Track and Global Privacy Control are
597
+ honoured by default: when the browser sends either, nothing is
598
+ recorded, patched or sent, and the SDK says so once with
599
+ `KUI_E_CAPTURE_DECLINED` (see `honorPrivacySignals`). The values that
600
+ count are `navigator.doNotTrack === "1"` -- or as older browsers spell
601
+ it: `"yes"` (Firefox before 32), `window.doNotTrack === "1"` (Safari,
602
+ IE 11), `navigator.msDoNotTrack === "1"` (IE 10) -- and
603
+ `navigator.globalPrivacyControl === true`; `onError` hears every
604
+ declined `init()`, and the console line is written once per page.
605
+
196
606
  **On the network.** For every recorded exchange:
197
607
 
198
608
  - Headers named in `privacy.sensitiveHeaders` have their values
@@ -200,34 +610,723 @@ are merged rather than one taking precedence.
200
610
  `set-cookie`, `x-api-key`, `x-auth-token` and `proxy-authorization`;
201
611
  a list you pass **extends** it and cannot shrink it: those six are
202
612
  redacted whatever you configure, because no redacted header value is
203
- ever needed for replay. Every other header value is scanned for the
204
- PII patterns below.
613
+ ever needed for replay. So is any header whose NAME reads as a
614
+ credential's, as a body's key does (`X-Access-Token`, `X-Csrf-Token`,
615
+ `Api-Key`, `X-Goog-Api-Key`, `X-Amz-Security-Token`, `Token`,
616
+ `X-Password`, `X-Secret`), or whose last word does (a token, an auth,
617
+ a secret, a password (`pass`, `pwd`, `passcode`), a PIN, a JWT, a
618
+ credential, an authorization or an authentication, a bearer, a
619
+ session, a `sid`, a CSRF or XSRF value, a cookie, a signature, an
620
+ HMAC, an OTP or TOTP; a session id in one word; a `key` after a word
621
+ such as auth, secret, access, API or subscription; a `code` after a
622
+ word such as MFA, OTP, SMS, auth, reset or verification; an `id`
623
+ after a session or a token -- `X-Auth`,
624
+ `X-Auth-Key`, `X-Forwarded-Authorization`, `X-Session-Id`,
625
+ `X-Auth-Token-V2`, `Ocp-Apim-Subscription-Key`, `X-Mfa-Code`). A word
626
+ that only describes one stays (`X-Session-Timeout`,
627
+ `X-Tokens-Remaining`, `X-Password-Policy`, `X-Error-Code`), and so
628
+ does a CORS header (`Access-Control-Allow-Credentials`); a mock keeps
629
+ `content-type` and `cache-control` alone, and the replay key is the
630
+ method, the URL and, for a GraphQL body, the operation it names (its
631
+ `requestTerm`, below). A header that is or carries a URL —
632
+ `Location`, `Content-Location`, each `<...>` of a `Link`, the `url=` of
633
+ a `Refresh` — has that URL's query values redacted as a request URL's
634
+ are (see the URL bullet below). Every other header value is scanned for the
635
+ PII patterns below, and is otherwise recorded as it is: a header your
636
+ own code fills with what a person typed is yours to name in
637
+ `privacy.sensitiveHeaders`. Under `strict` that is not left to you:
638
+ only the values of headers that describe the exchange rather than the
639
+ person are kept — `accept`, `accept-encoding`, `accept-ranges`, `age`,
640
+ `cache-control`, `connection`, `content-encoding`, `content-language`,
641
+ `content-length`, `content-type`, `date`, `etag`, `expires`,
642
+ `keep-alive`, `last-modified`, `pragma`, `transfer-encoding` and
643
+ `vary` — and every other value is replaced with `[REDACTED]`, its
644
+ name kept.
645
+ - Names. One rule reads every name the SDK records a value under: a
646
+ JSON body's key, a form's field, a multipart part's name, a
647
+ `name=value` pair in a text body, a header's name, and a query or
648
+ fragment parameter of every URL the SDK records (below).
649
+ A credential's names are `token`, `password`, `passwd`, `pwd`,
650
+ `secret`, `apikey`, `authorization`, `auth`, `session`, `cookie`,
651
+ `pin`, `code_verifier`, `private_key`, `passphrase`, `ssn`,
652
+ `cardnumber`, `cvv`, `rawKey` (the field Keploy's api-server returns a
653
+ freshly minted API, ingest or service-account key in) and the like; a
654
+ one-time code's (`invite_code`, `reset_code`, `verification_code`,
655
+ `auth_code`, `oobCode` and the like; never a bare `code`, `zip_code`
656
+ or `country_code`); any name ending in `token`, `secret`, `password`
657
+ (and its confirmation fields, `password_confirmation`, `password2`),
658
+ `passwd`, `signature`, `apikey`, `privatekey`, `passphrase`,
659
+ `sessionid`, `jwt`, `otp`, `credential` or `curl` (a recorded curl
660
+ command carries its `Authorization` header and form body) — an
661
+ `auth_token`, an `email_otp`, S3's `X-Amz-Signature`, Magic's
662
+ `magic_credential`, a `JSESSIONID`; SAML's `SAMLResponse`,
663
+ WordPress's `confirm_key`, Supabase's `token_hash`, Clerk's
664
+ `__clerk_ticket`, a sign-in link's `nonce`, `hmac`, `login_hash`,
665
+ `magic_link`, `PHPSESSID` and `oauth_verifier`, and Azure's SAS `sig`;
666
+ and a card's expiry by a card's own name (`exp_month`, `ccExp`). A name
667
+ is read percent-decoded, at each `[...]` (`user[password]`),
668
+ lower-cased and without `-`, `_`, `$`, `+` and whitespace, and — but
669
+ for a JSON key, whose dots are part of one flat key
670
+ (`"auth.login.title"`) — at each `.` (`user.password`); a name of more
671
+ than one part is also read as one word (`api[key]` is an `apikey`). A
672
+ flag under a credential's name is kept: it holds no secret, and
673
+ `"[REDACTED]"` in its place reads as true. Under `credentials`,
674
+ `authentication` and `pass`, which an app's data uses as often for a
675
+ list, a method or a count, only a string goes; any other value is read
676
+ on, its own credentials redacted. KNOWN OVER-REDACTION: a few names the
677
+ rule takes are some apps' public or plain data -- Adyen's public
678
+ `clientKey`, a `tokenId`, Twilio's `sid` -- and their value is
679
+ recorded as `[REDACTED]`, an object or a list under them as that
680
+ string, so a replay serves the string where the app had its value. A paging
681
+ cursor is never a credential (`pageToken`, `nextPageToken`,
682
+ `NextToken`, `continuationToken`, `syncToken`, OData's `$skiptoken`
683
+ and the like): a response's `nextPageToken` is recorded as sent, so a
684
+ replayed page asks for the next page the recording holds. Two
685
+ exceptions, each for a reason: the page's own URL and every URL its
686
+ DOM holds keep `auth`, `session`, `cookie`, `pin` and `sig` by name, as
687
+ an app's own parameters (`?auth=1`, a talk's `?session=`), and scrub
688
+ such a value when it looks generated; and a text body reads as a
689
+ pair's name only letters, digits, `_`, `-`, `%` and closed brackets
690
+ (below).
205
691
  - Request and response bodies are redacted structurally: JSON is
206
- parsed and every value under a sensitive key — `password`, `token`,
207
- `secret`, `apikey`, `session`, `cookie`, `ssn`, `cardnumber`, `cvv`
208
- and the rest of that family, including suffix forms like
209
- `userPassword` and `authToken` — is replaced, then the JSON is
210
- re-serialised so the recording still parses. Other bodies are scanned
211
- as text for JWTs, email addresses, SSNs, phone numbers, IPv4
212
- addresses and card numbers. `privacy.maskNetworkBodies: true` replaces every body
213
- wholesale with `[MASKED]` instead.
214
- - URLs keep their path — it is what the replay key is computed from —
215
- and the values of query parameters named like `token`, `password`,
216
- `secret`, `apikey`, `signature` or `sessionid` are redacted by name.
217
- The fragment (`#...`) is dropped entirely: it never reaches a server,
218
- so no replay needs it, and single-page routers put user state there.
219
-
220
- The built-in patterns match JWTs, email addresses, US phone numbers,
221
- US social-security numbers and IPv4 addresses; card numbers are
222
- detected structurally (issuer prefix, length and Luhn), because a
223
- length-only pattern matched every 13-digit timestamp. The same set runs
224
- over header values, over string values inside JSON bodies, and over
225
- non-JSON bodies as a whole — one scanner, three places.
692
+ parsed and every value under a credential's name (Names, above) is
693
+ replaced, and the JSON stays valid; a card's bare `expiry` /
694
+ `expirationDate` goes only beside a card field (`cardNumber`, `cvv`),
695
+ so a token's or a cookie's expiry keeps its value. Under `otp`,
696
+ `totp`, `passcode` and a name ending in `otp`, which settings use too,
697
+ only a string or a number goes: a flag stays, and an object is read
698
+ on, where its `code` goes (`{"totp":{"enabled":true}}` and
699
+ `{"email_otp":{"enabled":true}}` are kept). The redaction is made in the body's own text: only
700
+ the values it replaces change, and every other byte — numbers (a
701
+ 64-bit id past 2^53 included), whitespace, key order, escapes — is
702
+ recorded as the server sent it. A string value that is itself JSON (a
703
+ test case's `header` or `body` stored as text) is redacted the same
704
+ way, and any other string has its pairs read by the text pair rule
705
+ below, with a string's own leads only: its start, a `?`, a `&`, or a
706
+ `#` after a path (`"see /cb?token=… now"`, a stored
707
+ `"grant_type=password&password=…"`, `"Location: /cb#access_token=…"`).
708
+ A credential's value there runs to the next `&` or the string's end,
709
+ its spaces and line breaks its own (`"password=correct horse battery
710
+ staple"` records `"password=[REDACTED]"`, a PEM key goes whole), so
711
+ what follows it before the next `&` goes with it; one that starts
712
+ where a text body's value cannot -- a space, a quote, a backtick, a
713
+ bracket, `<`, `>`, `,`, `;` or a backslash -- is code's and is kept
714
+ (`fetch('/api?token='+t)`), and so is a quoted one
715
+ (`"password=\"correct horse\""`). A string's
716
+ content-type says nothing of what it holds, and code and SQL keep
717
+ their bytes (`let a=1;token=getToken()`, `SET password=?`, a class's
718
+ `#token=null`) -- so a pair a string's prose starts after a `;`, a
719
+ space or a line break (`"user=bob; password=…"`, `"go to
720
+ #access_token=…"`) is not read there, as it is in a text body. Every URL a body holds is read by the one URL rule below: each
721
+ line of a JSON string, a form value or a body that starts with a URL
722
+ (`https://…?…`, `./cb#…`, `cb?jwt=…`, `/cart;jsessionid=…`), read
723
+ whole to the line's end — a raw space in a query is its value's, and a
724
+ credential's value runs to the next pair, a space in it its own; in a
725
+ text body that is not read as a form it ends at its first space, `,`,
726
+ `;`, quote, `<`, `>`, backslash or backtick, or a `)`, `]` or `}` it
727
+ does not open (`?sig=(…)` is one value), and in a form at its first
728
+ space, as a form's value is then read to its `&`; in a text the
729
+ line's text after it
730
+ kept (a CSV row's later columns, CSS's `);color:red}`), so a value
731
+ that holds one of those keeps what follows it (`?password=a,b`
732
+ records `password=[REDACTED],b`), and one that starts with one is
733
+ kept whole (`?token="abc"`, `?sig=,1`); what it leaves is read as a
734
+ text, each URL of a list its own (`?token=…,https://b/y?next=…`
735
+ scrubs the second URL too) — and in any text — a JSON string's prose, an HTML, XML, RSC, CSS
736
+ or text body, a multipart part — each URL with a scheme and an
737
+ authority (`https://`, `wss://`, `myapp://`), each URL a link's
738
+ attribute (`href`, `src`, …), a URL any other attribute's quoted value
739
+ holds (`data-next="/x?…"`: a `/`, `./`, `../`, `?`, `#` or a scheme as
740
+ below first -- a style's value is CSS, not a URL), a meta refresh's `url=`
741
+ or a CSS `url()` holds (after a property's name too, or as an
742
+ attribute's whole value, `background="url(…)"`), to its first
743
+ space or, outside a quoted attribute, the first `)` or `]` it does not
744
+ open (CSS's `url(/x?token=…);color:red` keeps its `);color:red`), and
745
+ each URL a
746
+ script or JavaScript writes with its slashes escaped
747
+ (`"https:\/\/app\/cb#…"`, `\u002f`), to its first space, quote,
748
+ parenthesis, bracket or a plain `/` that closes a regular expression
749
+ (`/https:\/\/x\/cb#access_token=([^&]+)/` keeps its group and its
750
+ closing `/`), read unescaped, only the stretch from its first change to
751
+ its last written anew;
752
+ a URL in a template literal ends at its `${` (code, not a value); a
753
+ scheme at a line's start is one a `/` follows, one whose name holds a
754
+ `.` or `+`, `localhost` and its port (`localhost:3000/`), or one of a
755
+ list with no authority (`mailto:`, `tel:`, `xmpp:`, `intent:`, `data:`
756
+ …), never a CSS property's name (`grid-area:1/2` either); a relative URL inside prose is not told from the
757
+ prose, and is not read, nor is another attribute's unquoted value. A
758
+ nested URL is written back as it came, raw or encoded, or its value
759
+ replaced whole where its encoding cannot be kept. A form value written
760
+ encoded is redacted in place, or replaced whole where its encoded text
761
+ cannot be. A presigned S3, GCS or Azure link has
762
+ its signing parameters replaced (`X-Amz-Signature`, `X-Amz-Credential`,
763
+ `X-Amz-Security-Token`, `sig`), every other byte kept, and a pagination
764
+ link's `pageToken` is not touched. Such a link is no longer the one the
765
+ server sent, so replaying a request for it relies on the replay key
766
+ treating a redacted value as a wildcard. JSON inside a form value or a
767
+ multipart part (a GraphQL upload's `operations`) is redacted by key in
768
+ its own text when it was written as it is; a URL-encoded one with
769
+ anything in it to redact — a password, an email — is replaced whole,
770
+ since its encoded text cannot be redacted in place.
771
+ A name/value pair whose name is a secret's — `{key: "Authorization",
772
+ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
773
+ has its `value`, `values`, `expected` and `actual` replaced. A body
774
+ that is not
775
+ JSON gets the same rule (Names) for its `name=value` pairs — a form post, an
776
+ OAuth token request, `FormData` (passed directly or inside a
777
+ `Request`), `URLSearchParams` or an XHR string body: a value under a sensitive name — or under a name with a
778
+ sensitive part, like `password[0]` or `user[password_confirmation]` —
779
+ becomes `[REDACTED]`. In a FORM — a body sent as
780
+ `application/x-www-form-urlencoded` or `multipart/form-data`, or one
781
+ made only of such pairs with no raw spaces in them — that value runs
782
+ to the next `&`, spaces and all, and every other value is scanned for
783
+ the patterns below, raw and URL-decoded; a pair nothing matched is
784
+ kept byte for byte. `FormData` and `URLSearchParams` bodies are
785
+ recorded encoded, so they are forms whatever their content-type, but
786
+ one: sent under a JSON content-type the body is read as JSON, does not
787
+ parse, and is refused whole as `[UNPARSEABLE_BODY_NOT_REDACTED]`. ANY
788
+ OTHER BODY — HTML, XML, prose, or pairs with raw spaces in them posted
789
+ without a form content-type (the browser sends a string as
790
+ `text/plain`) — is kept byte for byte except for a URL it holds
791
+ (above) and a pair that starts
792
+ the body or follows `?`, `&`, `;`, a newline, a tag's `>`
793
+ (`<p>password=...</p>`), a `#` (`Location: /cb#access_token=…`) or a
794
+ space that follows no bracket and no `var`, `let` or `const`
795
+ (`user=bob; password=...` is found; neither a JavaScript body nor a
796
+ `<script>`'s text has a space or a tag start one, nor a `#` after
797
+ anything but a path's character or after a block comment's close,
798
+ `static` or `accessor` -- a class's `#token=` and `static#token=` are
799
+ private fields, and
800
+ `location.replace("/cb#access_token=…")` loses its token; nor is a
801
+ template literal's `${…}` part of a value, which ends before it
802
+ (`` `/api?token=abc${t}` `` records `` `/api?token=[REDACTED]${t}` ``); a body is JavaScript by its content-type, so `f(a, token=1)` in
803
+ `text/plain` loses its default) directly, and whose name is made only
804
+ of letters, digits, `_`, `-`, `%` and closed brackets (so minified
805
+ JavaScript's `e.token=t` and CSS's `[data-token=x]` are left alone);
806
+ its value ends at the first space, quote, backtick, bracket,
807
+ backslash, `&`, `;` or comma. So in such a body
808
+ `password=correct horse` records `password=[REDACTED] horse`, and
809
+ `user.password=`, `new+password=` and `"token=..."` are not found at
810
+ all: post a form with its content-type. A credential pair inside a form VALUE — a
811
+ redirect URL's `?token=` — is found the same way, raw and URL-decoded.
812
+ A multipart body written out by hand as a string (or served as a
813
+ response) under a `multipart/form-data` content-type is read part by
814
+ part: a part under a sensitive name, and any file part, has its value
815
+ replaced whole, and every other part is scanned like other text, every
816
+ other byte kept. A body under that content-type that is neither
817
+ multipart text nor a `FormData`'s fields — its boundary not the
818
+ declared one, or plain text — is recorded as `[Unreadable body]`,
819
+ never as it came. Every body that is not JSON
820
+ is then scanned as text for JWTs, email addresses, SSNs, phone
821
+ numbers, IPv4 addresses and card numbers; inside JSON the patterns
822
+ run on each string value. An OAuth token exchange's `code` goes too,
823
+ and a device flow's `device_code`, in a form and in JSON alike: in a
824
+ body (or a JSON object) with `grant_type=authorization_code` or the
825
+ device code grant, a `code_verifier`, or a code beside a
826
+ `redirect_uri`, a `client_id` or a `verification_uri`, or a code of
827
+ 10 characters or more beside a generated `state` (16 or more of a
828
+ token's characters, letters with a digit or both cases, no word or
829
+ slug; that state goes too) -- a SPA
830
+ finishing a PKCE flow posts the code it was handed. Elsewhere `code`
831
+ is an app's own (`?code=US`, a promo code) and stays. A RESPONSE body
832
+ is redacted the same way,
833
+ and a replay serves what was recorded: a token the app reads from a
834
+ redacted pair and sends back later replays as `[REDACTED]`. A body cut
835
+ at `maxBodySize` is read as a form when its cut-off end could be one,
836
+ so it may lose everything from its first sensitive `=` to the cut;
837
+ that is the price of never keeping half a credential the cut split.
838
+ `privacy.maskNetworkBodies: true` replaces every body wholesale with
839
+ `[MASKED]` instead, decided without the SDK reading it: the page's
840
+ Response is the network's own, never read, cloned or relayed, a body
841
+ passed in `fetch()`'s `init` or to `send()` is decided from its kind
842
+ and size, never serialised or decoded (only a string one is scanned,
843
+ for its `requestTerm`, below), and the body chunk is never loaded.
844
+ The browser still makes a body passed in `fetch()`'s `init` the body
845
+ of the `Request` the SDK builds from the call for its URL and headers,
846
+ so it byte-copies a buffer, UTF-8 encodes a string or URLSearchParams
847
+ and multipart-encodes a FormData once more than the page's own
848
+ `fetch()` does (a Blob or a stream is taken as it is); the SDK reads
849
+ none of it. One body is still read: a `Request` object's own
850
+ (`fetch(new Request(url, { body }))`, as ky and axios's fetch adapter
851
+ send one) is copied and read for its `requestTerm` (below), only as
852
+ far as the term needs -- whole when it starts as a JSON object, to its
853
+ first character otherwise (where a `Request` has no body stream, as
854
+ in Firefox, the copy is taken whole as a Blob and only its first KiB
855
+ decoded), and a multipart one is parsed. A body that is absent keeps `null`: a
856
+ request sent with none or an empty one (but an XHR's Blob, which is
857
+ named however small), and a response to a HEAD, a 204, 205 or 304,
858
+ or one whose `Content-Length` is 0. A response that does not declare
859
+ its length is `[MASKED]`, even one that turns out empty.
860
+ `privacyMode: "strict"` forces that: no body is recorded, and an
861
+ explicit `privacy.maskNetworkBodies: false` beside it is refused with
862
+ `KUI_E_PRIVACY_CONFLICT` before anything is recorded — neither option
863
+ silently wins.
864
+ - Every network event carries `requestTerm` in EVERY privacy mode,
865
+ strict included: the GraphQL operation a request body runs, as its
866
+ `operationName` and 16 hex of SHA-256 over its document with every
867
+ string and number literal blanked first (`graphql:GetApps#…`), `""` for
868
+ a body that is no GraphQL, or `body:*` for one the SDK could not read
869
+ or hash. It is computed over the body before redaction and never holds
870
+ a variable or a literal: it is what replay tells GraphQL calls apart by
871
+ (spec/canonical-key.v2.json).
872
+ - One rule reads every URL the SDK records: a request's URL and every
873
+ URL its request and response headers carry (`Location`,
874
+ `Content-Location`, `Link` and `Refresh` -- its delay first or not --
875
+ as a request's URL is, the page's next request; any other header's, a
876
+ `Referer` or a CSP's `report-uri`, by a credential's name, its own
877
+ value ended as a text body's is, so a list's next URL and a CSP's next
878
+ directive are kept -- and a
879
+ header's pairs, a relative URL's among
880
+ them, where its start, a `?`, a `&`, a `;`, a `,`, a space or a `#`
881
+ after a path leads one: `a=1, token=…`, `0; url=/next?a=1;sig=…`),
882
+ every URL a body holds (above), the page's own URL and every URL its
883
+ DOM holds (a link attribute's, and any other attribute's whose value
884
+ is wholly a URL: a scheme, `/`, `./` or `../` first and a query, a
885
+ fragment or a `;` parameter in it, or a `?` or `#` first, with no
886
+ space, a scheme being one a line's start takes (above) -- `data-next="/x?…"`,
887
+ an input's `value`; a path alone, `data-reset="/reset-password/<token>"`,
888
+ and CSS, `data-s="background:url(…)"`, are not read as one). A URL's path is kept — it is what
889
+ the replay key is computed from — and a value is redacted where its
890
+ name is a credential's (Names, above): a query's pair after `&`, or
891
+ after a `;` a `name=` follows; a fragment's (an OAuth implicit grant's
892
+ `#access_token=…`, a hash route's `#/cb?token=…` or `#/cb&token=…`);
893
+ a path's `;jsessionid=`; and a URL nested or
894
+ encoded in a value (`?next=/reset?token=…`,
895
+ `?redirect=https%3A%2F%2F…%3Ftoken%3D…`, `?a=1%26token%3D…`, a second
896
+ `?`), one level down. Deeper, and in a value encoded more than once
897
+ (`?redirect=https%253A%252F%252F…`), the value is replaced whole when a
898
+ credential's name is in it, decoded up to four times and escape by
899
+ escape, so a malformed escape beside it (`%25zz`) hides nothing; in the page's URL
900
+ and the DOM's a URL nested deeper with a query of its own is replaced
901
+ whole, unread. A URL's user name and password are dropped. Every scheme is
902
+ read so — `https:`, `wss:`, `myapp://`, `mailto:`,
903
+ `com.example.app:/oauth2redirect#access_token=…` — but for a script's or an
904
+ inline object's (`javascript:`, `data:`, `blob:`), which is kept. In a
905
+ request's URL a pair
906
+ runs from `&` to `&`, as the replay key reads one, and a credential
907
+ anywhere in it (`?a=1;auth_token=…`, a nested URL's) replaces the
908
+ pair's whole value; elsewhere only the credential's own value goes. A request's own fragment
909
+ (`#...`) is dropped entirely: it never reaches a server, so no replay
910
+ needs it, and single-page routers put user state there.
911
+ Under `privacyMode: "strict"` every query value is replaced, whatever
912
+ its name, and every name kept: `/search?q=ada%40example.com&page=2`
913
+ is recorded as `/search?q=[REDACTED]&page=[REDACTED]`; an empty value
914
+ and a bare name (`?flag`, recorded as written, whatever it holds) are
915
+ kept. Replaying such a request needs a replay key that matches a value
916
+ redacted at record against any live value (canonical-key.v2, not yet
917
+ specified in spec/); with
918
+ it, two requests that differ only in a redacted value
919
+ (`?session=morning` and `?session=evening`, two `?pin=`s) are one
920
+ request to the replay, answered in the order they were recorded.
921
+ Under canonical-key.v1, which generated tests use today, a request
922
+ whose redacted value v1 does not leave out of its key does not match
923
+ at replay.
924
+ - The PAGE's URL -- what every recorded page change carries, rrweb's
925
+ own included, the session's starting URL and its referrer -- is read
926
+ by the same rule. A value in the query
927
+ is redacted up to the next `&`, `;` or `#`, and one in the path
928
+ (matrix parameters, `/reset;token=`) or in a route up to the next `?`
929
+ as well, so a token holding `/` goes whole. A credential that itself
930
+ holds a literal `;` or `&` is cut there, and the rest is recorded
931
+ unless the value scrub below finds it. The page's own fragment is
932
+ kept only when it is a hash router's route (`#/cart`, `#!/cart`), up
933
+ to a second `#`, with the route's own pairs redacted the same way; any
934
+ other fragment, an OAuth implicit-flow `#access_token=...` included,
935
+ is dropped.
936
+ - A credential the page's URL carries is scrubbed from every event the
937
+ SDK sends, wherever the page or rrweb copies it: rrweb makes every
938
+ link absolute against the page and builds a CSS `url()` by cutting the
939
+ page URL at a `/`, a share link copies the page URL encoded, and the
940
+ page puts tokens in its DOM and its requests. So the VALUE is replaced
941
+ with `[REDACTED]` in the DATA of every event -- DOM, network and the
942
+ rest -- as written, percent-decoded (the way `decodeURIComponent` and
943
+ `URLSearchParams` read it, `+` as a space), percent-encoded, and cut
944
+ at each of its last four `/` (where rrweb's CSS `url()` cuts it). The
945
+ names an event is built of are left as its reader reads them: a name is
946
+ touched only where the page or you wrote it, only for a
947
+ generated-looking value, and never one rrweb writes for itself (`rr_*`,
948
+ `_cssText`) -- in a DOM event, an element's attribute or a style's
949
+ property so named is DROPPED, since no attribute or property name holds
950
+ `[REDACTED]`; a request's or response's header and a custom event's
951
+ payload key are RENAMED. rrweb's tag names, a style declaration's
952
+ property, the values of attributes HTML defines a vocabulary for
953
+ (`type`, `rel`, `role` and the like) and the network record's `method`
954
+ and `type` are never scrubbed; CSS -- a style attribute, a `<style>`'s
955
+ text whenever it is written, a stylesheet's rules and its `replace()` --
956
+ is scrubbed inside its `url()`s, quoted strings and comments, and of a
957
+ generated-looking value anywhere. A request or response body that is
958
+ JSON, and any other string that is a JSON object or array, is scrubbed
959
+ token by token, so it still parses: a value inside a JSON string is
960
+ replaced there (and a JSON text inside that string is scrubbed as JSON
961
+ again), a JSON number a value is found in becomes the string
962
+ `"[REDACTED]"`, a string a value is found in is written again as
963
+ `JSON.stringify` writes it, and every other token is kept byte for
964
+ byte; two names of one object that become one are both kept, the
965
+ second suffixed `#2`. The credential is
966
+ collected from each URL the SDK sees the page on. In a browser without
967
+ the Navigation API it does not see a URL the page reaches with a
968
+ `pushState` it has not wrapped -- one a router kept from before `init()`
969
+ (SvelteKit does), or any on a page whose methods it could not wrap (see
970
+ [Single-page apps](#single-page-apps)) -- and leaves again before the
971
+ next recorded event, so that URL's credential is not collected.
972
+ - The values scrubbed are the ones named above, an OAuth callback's
973
+ `code` and `state` (a code of at least 10 characters beside a
974
+ generated-looking state, or a generated-looking code of at least 20
975
+ alone on a callback's path -- one with `callback` or `oauth` in it, or
976
+ a segment that is `cb`, `auth`, `sso`, `signin`, `sign-in`,
977
+ `authorize(d)` or `redirect`, in the path or a hash router's route --
978
+ as GitHub and a PKCE callback send it), a CAS `ticket` (`ST-`, `PT-`, `TGT-`),
979
+ Supabase's `token_hash`, Clerk's `__clerk_ticket`, Magic's
980
+ `magic_credential`, a link page's `key`, `t`, `hash` and `code`
981
+ whatever they look like, in its own URL and in a link to one (and
982
+ WordPress's `wp-login.php?action=rp&key=...`), Auth0's
983
+ `?invitation=` beside an `organization`, a link's path token,
984
+ and each of those inside a URL nested in a parameter (a
985
+ `returnTo=%2Faccept-invite%3Ftoken%3D...`, two levels deep).
986
+ - A link's path token is told from an app's own id by the words of the
987
+ segment it follows and by its own shape, in the path or in a hash
988
+ router's route. Every word of that segment must be a link's own (a
989
+ file extension, as in `reset.php`, is not a word). A STRONG segment
990
+ names the act: reset, verify, unlock, activate, invite, forgot,
991
+ recover, a magic or login link, set or create a password
992
+ (`/set-password/<t>`), accept an invitation, or confirm an
993
+ email, account, registration or sign-up, named in its segment or the
994
+ one before it (`/reset-password/<t>`, `/password_resets/<t>/edit`,
995
+ `/forgotten-password/<t>`, `/accept-invitation/<id>`,
996
+ `/confirm-email/<t>`, `/email/confirm/<t>`). A WEAK one names a thing
997
+ a token or an id may follow: a confirmation, an invitation, a
998
+ verification, an activation, a password, a sign-up, a log-in
999
+ (`/users/confirm/<t>`, `/users/log-in/<t>`, `/passwords/<t>/edit`).
1000
+ An ID is digits, a UUID, a 24-hex ObjectId, a ULID or a cuid (each in
1001
+ its own case), or a user's uid (Django's and Djoser's base64 pk,
1002
+ whatever the pk) where one is expected -- before a token, or after a
1003
+ strong segment; a TOKEN-SHAPED value is any other generated-looking one
1004
+ of 16 characters or more, 20 after a weak segment. A shape a token can
1005
+ take is a token's: a prefixed id (`inv_…`, a TypeID) after a link word
1006
+ is scrubbed, because 1-4% of real nanoid and base64url tokens take
1007
+ that shape too -- keep your own with `privacy.keepRoutes`. The token is the first token-shaped value after the segment,
1008
+ past short ids, ids and the link's own words
1009
+ (`/password/reset/confirm/<uid>/<t>`,
1010
+ `/reset-password/<ObjectId>/<JWT>`, `/account/reset/<customerId>/<t>`).
1011
+ When the path ends with ids alone after a strong segment, the last of
1012
+ them is the token (`/invite/<uuid>`) -- not when a word follows them
1013
+ (`/invite/<uuid>/members`). After a weak segment an id is the token
1014
+ only when an accept or join acts on it (`/invitations/<uuid>/accept`).
1015
+ After an invitation's segment, a shorter generated-looking code --
1016
+ `Ab3dE5gH` -- is a token wherever an id would be one
1017
+ (`/invite/<code>`, `/invitations/<code>/accept`); after any other
1018
+ link word a short segment stays. A word that names a credential
1019
+ outright -- set, create, reset, forgot or lost password, verify email
1020
+ -- hands on the next segment whatever its length or shape, in the
1021
+ page's URL and in a link a visitor follows (an `<a>`'s or `<area>`'s
1022
+ `href`, a form's `action` or `formaction`); what a page loads, an
1023
+ image or a stylesheet, keeps the token-shape rule, so a replay can
1024
+ load `/img/set-password/hero`. A page of the link stays (`sent`,
1025
+ `done`, `success`, `complete`, `confirm`, `confirmed`, `new`,
1026
+ `error`, `expired`, `failed`, `invalid`), and so do a file
1027
+ (`hero.png`), a step of the link (`/reset-password/confirm/<t>`) and
1028
+ an id with more path after it (`/verify-email/42/<hash>`). Any other
1029
+ word there goes (`/reset-password/pending`), and
1030
+ `privacy.keepRoutes` keeps it. Unless it looks generated, such a
1031
+ segment is held there alone: `pending` is not taken out of the page.
1032
+ So `/admin/invitations/<uuid>/edit`, `/order/confirmation/<uuid>`,
1033
+ `/settings/verification/<id>`, `/login/<uuid>`,
1034
+ `/products/apple-magic-mouse/<id>` and `/order-confirmation/<id>` are
1035
+ an app's own resources, and their ids, which appear in its requests,
1036
+ are kept.
1037
+ - Only a GENERATED-LOOKING value is scrubbed everywhere: 8 characters or
1038
+ more mixing two of lower case, upper case and digits, not a
1039
+ capitalised word and not a slug of words and numbers
1040
+ (`annual-meeting-2024-berlin`) -- every form of it included (decoded,
1041
+ encoded, cut at a `/`). A word -- `delivered`, `California`, `required`,
1042
+ `two-factor-authentication` -- also appears in the page's own text,
1043
+ classes and requests, and so do digits alone (an order number, a
1044
+ price), so an app's own `?code=ORD-2024-000123&state=delivered` or
1045
+ `/settings/activate/two-factor-authentication` is recorded as it is,
1046
+ and a credential value that is a word, digits alone, or shorter than
1047
+ 8 characters is redacted only in the URL that names it (above) --
1048
+ unless a route you declare names it (below). A
1049
+ value that is a URL is never a credential, nor is an OAuth `code` or
1050
+ `state` that is a path (a `state` carrying the return URL); a value a
1051
+ credential's name shows is one even when it begins with `/`, as a
1052
+ standard-base64 token can. No part of the page's own origin is ever
1053
+ scrubbed.
1054
+ - The values are kept for the life of the page, not for as long as the
1055
+ address bar shows them: an auth library or a reset page that hides the
1056
+ token with `history.replaceState` still holds it, so the URL the page
1057
+ was LOADED with is read too (even when the token was hidden before
1058
+ `init()`), and so is every URL the page moves to while a capture is
1059
+ open -- pushed, replaced or reached by the visitor going back or
1060
+ forward, paused or not -- and the session's URL and referrer are
1061
+ recorded without any of them. A continuous capture keeps collecting
1062
+ them between its sessions; once `stop()` has settled (at most a
1063
+ second, while exchanges already answered finish their bodies) nothing
1064
+ watches the page, so a URL it moves to and away from before the next
1065
+ capture starts is never read. Routes a later capture declares are applied to the newest
1066
+ 64 URLs already read (512 KB of them at most) as well as to the one
1067
+ the page loaded with. The newest 256 forms are kept, 64 KB of them at
1068
+ most, and the forms of the URL the page is on now are always kept; a
1069
+ value is cut at its last four `/` only, where rrweb's CSS url() cuts
1070
+ it.
1071
+ - A CRAFTED URL is recorded as its origin and `/[REDACTED]`: one whose
1072
+ path, query and route are longer than 64 KiB (it is then not read,
1073
+ but for the values your declared routes name in its path and route),
1074
+ or that carries more than 32 credential values. The values your
1075
+ declared routes name in the URL's own path and route are always held;
1076
+ 32 more at most -- the rest of the URL's, declared ones in a nested
1077
+ URL included, and each other segment a declared value is named after
1078
+ (a link's spellings of one segment, in any case and encoding, are
1079
+ one) -- are held and scrubbed, so a link cannot make every event pay
1080
+ for thousands. A value past those 32 is NOT held: the page's URL is
1081
+ still recorded as its origin, but a link, a request or a text that
1082
+ carries that value again is recorded with it (measured: a 33rd
1083
+ `…_token=` value in the page's URL stays in every link rrweb resolves
1084
+ against that URL). Declare the route of any value that must never be
1085
+ recorded: a declared value in the URL's own path is held whatever
1086
+ else the URL carries. A
1087
+ fragment that is no route (a playground's `#code/…`) is not recorded
1088
+ and does not count toward 64 KiB, but it is read, in linear time, for
1089
+ the credentials it hands the page (`#access_token=…`). Each URL is
1090
+ read once, in time linear in its length, for as long as the page is
1091
+ on it.
1092
+ - The scrub reads an event's JSON and never the integrator's own objects:
1093
+ a custom event that is cyclic, frozen or has a throwing getter is left
1094
+ to the transport, which drops what JSON refuses. Two names that become
1095
+ one are both kept (the second suffixed `#2`), and an event the scrub
1096
+ cannot read is dropped rather than sent.
1097
+ - THIS IS RECOGNITION, NOT A GUARANTEE. A credential the URL carries in
1098
+ a shape the rules above do not recognise -- an unusual parameter name,
1099
+ a token that is a dictionary word or digits alone, a token shorter than
1100
+ 16 characters in a path (Discourse's 10-character `/invites/<key>`), a
1101
+ token that is a UUID or an ObjectId after a weak segment
1102
+ (`/invitations/<uuid>`) -- is recorded; and an app's own id right after
1103
+ a strong link segment (`/teams/invite/<id>`, `/devices/reset/<uuid>`),
1104
+ a generated id of no known shape after a weak one (a nanoid, a KSUID,
1105
+ a prefixed id or a Firestore id in `/invitations/<id>`) or a
1106
+ link page's `?code=` that is a promo code (`/signup?code=FRIEND10`)
1107
+ is scrubbed, because neither the words nor the shape tell the two
1108
+ apart. Where they cannot, a credential wins: an id scrubbed by mistake
1109
+ is kept by a declared route, a credential recorded by mistake is not
1110
+ taken back. DECLARE THEM: see
1111
+ the next item. Name a credential parameter like one (anything ending
1112
+ in `token`) or keep it out of the URL. And a request that carries the
1113
+ page's credential is recorded with it redacted, so its replay key
1114
+ cannot match a live request carrying a real one -- which a one-time
1115
+ token never would anyway.
1116
+ - `privacy.secretRoutes` names the routes whose segments are
1117
+ credentials the rules above miss, and `privacy.keepRoutes` the routes
1118
+ whose segments are your app's own ids they would take for one:
1119
+
1120
+ ```ts
1121
+ await KeployCapture.init({
1122
+ endpoint,
1123
+ apiKey,
1124
+ privacy: {
1125
+ secretRoutes: ["/invites/:key", "/*/change-email/:token"],
1126
+ keepRoutes: ["/teams/invite/:teamId", "/invites/settings"],
1127
+ },
1128
+ });
1129
+ ```
1130
+
1131
+ A route is `/`-separated segments from the path's start (empty ones
1132
+ ignored), each a literal (matched in any case, decoded), `*` (any one
1133
+ segment) or `:name` (the value the route names); it matches a path
1134
+ that begins with it -- the page's path, a hash router's route (`#/…`
1135
+ or `#!/…`), and a URL nested in a parameter -- and a segment's matrix
1136
+ parameters (`;jsessionid=…`) are not part of its value. A SECRET
1137
+ route names at least one `:name`. What it names is kept out of the
1138
+ recorded URL and every event -- the DOM, inputs, requests and
1139
+ responses, their URLs and bodies -- each form of it (as the URL
1140
+ spells it, decoded, encoded) by the rule its own text calls for. A
1141
+ value that holds no letter or digit once decoded -- read through up to
1142
+ sixteen encodings -- is not held at all: `/`, `%2f`, `-~_`, `$$$$$$`,
1143
+ `€€€€€€`, emoji, a full-width space. No credential is spelt that way,
1144
+ and such a value would otherwise match every separator or symbol of
1145
+ the page; one still encoded after sixteen decodings is not held
1146
+ either. The rules:
1147
+ - generated-looking (above): as it is, wherever it appears, and in any
1148
+ case where no ASCII letter or digit touches it;
1149
+ - any other of at least 6 characters, decoded, WHATEVER ITS LETTERS (`QX7P2K`,
1150
+ `482913`, `QxPkZmA`, `notifications`): in any case, wherever no
1151
+ ASCII letter or digit touches it -- `{"code":"QX7P2K"}`,
1152
+ `Code: QX7P2K.`, `?code=qx7p2k`, after a string's escape
1153
+ (`\nQX7P2K`, `%5CnQX7P2K`), as a JSON writer escapes it
1154
+ (`Q\u00e9X7P2`), a share link encoding the page URL up to three
1155
+ times (any number of times for a code of ASCII letters and digits,
1156
+ which encoding leaves as it is); a JSON number holding one becomes
1157
+ the string `"[REDACTED]"`, so the body still parses. No shape tells
1158
+ a random code from a word
1159
+ (`qxpkzm` from `create`), so a credential wins: a page of your own
1160
+ that a secret route also matches (`/invites/notifications` under
1161
+ `/invites/:key`) has its name scrubbed as a credential from every
1162
+ event of the page from then on -- a single-page app keeps it after
1163
+ navigating away, so `/api/notifications` and the text
1164
+ `Notifications` are `[REDACTED]` on every later route -- until you
1165
+ declare it as a keep route (`/invites/notifications`), and then it is
1166
+ your page again;
1167
+ - a shorter value, decoded (`new`, `Edit`, `ab-cd`, `新規` however
1168
+ long its encoded form): only as the path segment
1169
+ after the one its route puts before it (`invites/new`), after every
1170
+ such segment the routes name, in any case, separated by `/`, `\/` or
1171
+ a `/` encoded up to three times, and ended by any character that
1172
+ cannot continue a word (`.json`, a `)` closing a CSS `url()`, a
1173
+ space). A short value is also your app's own text, so `new` in the
1174
+ page and `/projects/new` stay; that also means it is NOT scrubbed
1175
+ from a request body or the page's text, nor from a URL that does not
1176
+ put its route's segment before it, so a credential of fewer than 6
1177
+ characters is held in URLs alone. A route whose `:name` is the
1178
+ path's first segment (`/:space`) holds it as any whole segment after
1179
+ a `/`.
1180
+
1181
+ A KEEP route has at least one literal: what its `:name`s name is never
1182
+ taken for a token by the rules above (a value a credential's name
1183
+ shows, `?token=`, or a secret route names too, is still a
1184
+ credential). A keep route's literal is your app's own name for its
1185
+ position, so no secret route takes it for a value there:
1186
+ `/invites/settings` keeps `/invites/settings` and
1187
+ `/invites/settings/billing` from `/invites/:key`. A keep route of
1188
+ literals alone also names ONE page, the path it spells and not the
1189
+ pages under it, where no segment is taken for a token either --
1190
+ `/account` keeps `/account` and not `/account/reset/<token>`; a value
1191
+ a credential's name shows is still redacted. A route outside the rule refuses to start the
1192
+ capture (`KUI_E_PRIVACY_ROUTE_INVALID`): one the SDK cannot match would
1193
+ protect nothing -- on every load, whatever `sampleRate` leaves out.
1194
+ Routes are declared when a capture starts and kept for the page; a
1195
+ second `init()` while a capture is live returns that capture, and its
1196
+ routes are not added.
1197
+
1198
+ KNOWN LIMIT, with declared routes only: scrubbing a string costs time
1199
+ in proportion to its length times the number of long declared values
1200
+ (longer than `[REDACTED]`) it holds, and a crafted link can declare up
1201
+ to 32. That is the bound: 32 passes over an event's strings, which end
1202
+ at the 10 MiB cap. MEASURED in Node 24 on a link with 31 nested values,
1203
+ each a run of one digit, beside a longer run of that digit: a page of
1204
+ 110 relative links (0.96 MB of link text) scrubbed in 6 ms without the
1205
+ nested values and in 0.9 s with them, and one of 1,100 (9.6 MB, just
1206
+ under the cap) in 64 ms and in 9.3 s. In Chromium, in review, 300 such
1207
+ links made `init()` take 2.6 s where it took 0.18 s without the nested
1208
+ values -- and a snapshot dropped for size is retaken on a backoff.
1209
+ Reading every long value in one pass over the string is the planned
1210
+ fix.
1211
+
1212
+ - Beside the rules above, and never undoing what they keep, the page's
1213
+ URL -- the session's URL and referrer and every Meta event's -- and
1214
+ the URLs in the DOM listed below are scrubbed by their shape: in a
1215
+ query and in a route's or a fragment's pairs (a `;` followed by a
1216
+ `name=` separates pairs as `&` does), a value is replaced
1217
+ when it is shaped like a token (a JWT, or 32 or more letters and
1218
+ digits that are not a slug; a canonical UUID, and any value under an
1219
+ `*id` name, is taken for an id and kept) or when a PII pattern matches
1220
+ it (`?email=ada%40x.com`). A URL inside a value -- absolute, or a path
1221
+ with its own query -- is scrubbed the same way, one level deep, and a
1222
+ URL inside that one which carries a query or a fragment of its own is
1223
+ replaced whole; a JWT
1224
+ path segment is replaced; user name and password never leave. An
1225
+ OAuth authorization response is redacted in every mode: every `code`
1226
+ and `state` (and `session_state`), when a code is not a path and
1227
+ either the URL's path or route is a callback's (a segment with
1228
+ `callback` or `oauth` in it, or `cb`, `auth`, `sso`, `signin`,
1229
+ `authorize(d)` or `redirect`) or a state is not a plain word (letters,
1230
+ or words joined by `-` or `_`, of at most 16 characters, or longer
1231
+ camelCase or joined words); a `state` beside an id, access or refresh
1232
+ token, which go by name; and OAuth 1.0a's `oauth_verifier`. An app's
1233
+ `?code=ORD-2024-000123&state=delivered` or `?code=US&state=CA` stays.
1234
+ This scrub runs on what the page holds, before the credential scrub,
1235
+ and knows the page URL's credentials by their values: a CSS
1236
+ `url(img.png)` rrweb resolved against a page reached with `?token=`
1237
+ loses the token and keeps its file name, under any name, unless a PII
1238
+ pattern touches what follows it. A `[REDACTED]` the page
1239
+ itself wrote is text like any other, and shields nothing. Under
1240
+ `privacyMode: "strict"` every query value and fragment-pair value is
1241
+ replaced and every name kept, since a search box puts what was typed
1242
+ in `?q=` -- so a page with a query is recorded under a URL it never
1243
+ had (`?page=[REDACTED]`). The DOM's URLs -- `href`, `src`, `action`,
1244
+ `formaction`, each `srcset` and `imagesrcset` candidate, `poster`,
1245
+ `cite`, `data`, `xlink:href`, `background`, `longdesc`, each URL of a
1246
+ `ping`, a lazy loader's `data-src`, `data-srcset` and `data-href`, each
1247
+ `url(...)` or `@import` in an inline `style`, in a `<style>`'s text
1248
+ and in the stylesheet rrweb inlines for a `<link>`, a `<meta http-equiv=refresh>`
1249
+ target and a `content` that is a URL (`og:url`), in the full snapshot
1250
+ and in every node a mutation adds or attribute it changes -- are also
1251
+ scrubbed by the page URL's names, plus the code and hash names of
1252
+ verification, reset and sign-in links (`verification_code`,
1253
+ `reset_code`, `invite_code`, `mfa_code`, `nonce`, `hmac`,
1254
+ `magic_link`), so a reset
1255
+ link's `?token=` or a signed media URL's signature on the page is
1256
+ recorded scrubbed. A token a link carries in its PATH after a reset,
1257
+ invite, verify or magic-link word (`/reset-password/<token>`,
1258
+ `/invitations/<uuid>/accept`) is replaced when the page URL rule would
1259
+ replace it in the page's own URL and it is shaped like a token (a
1260
+ UUID, or a part of 8 characters or more that looks generated, an
1261
+ invitation's short code among them) or, in a link a visitor follows,
1262
+ comes after a word that names a credential outright, `;` parameters
1263
+ after it or not, so an app's own ids and slugs stay
1264
+ (`/order/confirmation/<uuid>`, `/products/apple-magic-mouse/<id>`,
1265
+ `/login/apple-iphone-15-pro-max-256gb`). An `iframe`'s `srcdoc` is
1266
+ read as a browser reads it -- comments and raw text (`<script>`,
1267
+ `<textarea>`, `<title>`) passed over, character references decoded
1268
+ however they are written -- with each of those attributes and its CSS
1269
+ scrubbed in its own markup, and then read again for any URL, style or
1270
+ srcdoc attribute the first read passed over (an SVG `<title>` holds
1271
+ markup). CSS -- a style attribute (or a style a script sets through
1272
+ `element.style`, which rrweb records as an object), a `<style>`'s
1273
+ text, the stylesheet rrweb inlines for a `<link>`, and what changes
1274
+ after the snapshot: a `<style>`'s text, a rule a script inserts or
1275
+ replaces through the CSSOM, a declaration it sets, an adopted
1276
+ stylesheet, a font it loads -- has each URL in a `url()`, closed or
1277
+ not, and in a quoted string (`@import`, `image-set()`) scrubbed the
1278
+ same way, read through its escapes (a `url(` whose name is escaped
1279
+ included) and past its comments. A `javascript:`, `data:` or `blob:`
1280
+ URL is kept; a URL with
1281
+ nothing to scrub is recorded exactly as it was, and an event the scrub
1282
+ cannot read is dropped rather than sent, as one the credential scrub
1283
+ cannot read is. A test holds a 50,000-node page with 20,000 such URLs
1284
+ under a second.
1285
+ - The page's TEXT -- each text node of the full snapshot and of a node
1286
+ added after it, each text change, a value typed under `off`, a
1287
+ `srcdoc`'s markup -- has every JWT and provider-prefixed key in it
1288
+ (the token patterns below: a Keploy `kep_` key, GitHub, Stripe, AWS
1289
+ and the rest) replaced with `[REDACTED]`, in every mode: the dashboard
1290
+ shows a freshly minted key as text, once. Text nodes side by side
1291
+ are read together, in a snapshot and in the nodes one mutation adds,
1292
+ so a key rendered in pieces goes too. Other text is recorded as
1293
+ the privacy mode masks it; under `privacyMode: "strict"` that includes
1294
+ a `srcdoc`'s text, between tags and in a `<title>`, `<textarea>` or
1295
+ `<xmp>`, masked as rrweb masks a text node's. Every attribute's value
1296
+ is read for those tokens too, and one that holds text -- `title`,
1297
+ `alt`, `placeholder`, `label`, `summary`, `abbr`, `aria-label` and the
1298
+ other `aria-*` text, a `data-*` that is no URL, a meta `content`, the
1299
+ `value` of an element that is no field (a button's, an option's) --
1300
+ for every built-in pattern below as well; a field's value is what the
1301
+ mask map above decides, and any other attribute (an `id`, an SVG
1302
+ path's numbers, a URL, CSS, a `srcdoc`) is read for tokens alone.
1303
+ rrweb's own `rr_*` attributes (a canvas's image data) are left alone.
1304
+
1305
+ The built-in patterns match JWTs (starting at a token boundary: one
1306
+ glued straight onto a preceding `-` is not seen), tokens whose provider
1307
+ prefix names them (Keploy `kep_` keys, GitHub, GitLab, Slack, Stripe,
1308
+ OpenAI and Anthropic keys, npm tokens, webhook signing secrets, AWS
1309
+ access key ids, Google API keys), email addresses, US
1310
+ phone numbers, US social-security numbers and IPv4 addresses, each in
1311
+ time linear in the text it scans, since they run on the page's main
1312
+ thread; card numbers are detected structurally (issuer prefix, length
1313
+ and Luhn), because a length-only pattern matched every 13-digit
1314
+ timestamp. The same set runs over header values, over string values
1315
+ inside JSON bodies, over form bodies as sent and decoded, and over
1316
+ other bodies as a whole — one scanner, four places.
226
1317
 
227
1318
  `privacy.piiPatterns: [{ name, pattern }]` adds your own, and they run
228
1319
  wherever that scanner does. Every occurrence is replaced whether or not
229
1320
  your pattern carries `g`, and never a JSON key or a number, so the body
230
- still parses.
1321
+ still parses. In a form body they run over the whole body, as it was
1322
+ sent and decoded, so a pattern may span `name=value` or several fields,
1323
+ and one written against a decoded value (`dob=01/02/1990` in a
1324
+ `FormData`) matches it. Every pattern and every built-in detector runs
1325
+ over the original text, never over another's result: a pattern whose
1326
+ match holds an email or a phone number hides its whole match, and
1327
+ overlapping matches become one `[REDACTED]`. An empty match replaces
1328
+ nothing (a `\d*` adds no marker between characters), and text no
1329
+ pattern matched is kept exactly as it was.
231
1330
 
232
1331
  They do **not** run over URLs, and that is deliberate: the path and the
233
1332
  query values are what the replay key is computed from, so rewriting
@@ -243,6 +1342,199 @@ import { PrivacyEngine } from "@keploy/capture-sdk";
243
1342
  new PrivacyEngine().maskText("contact user@example.com now"); // "contact [REDACTED] now"
244
1343
  ```
245
1344
 
1345
+ `maskNetworkData(event)` masks a network event's headers and URL as the
1346
+ capture does; its BODIES are redacted by the SDK's body code, which is not
1347
+ in the main bundle (it runs in the body worker, see [Your page's own
1348
+ network](#your-pages-own-network)). Called directly, it redacts them once
1349
+ a capture on the page has loaded that code -- which it loads at the
1350
+ capture's start, beside rrweb, when bodies are not masked whole -- and
1351
+ until then
1352
+ records each body `[MASKED]`, never in the clear. Changed in this version: it used to redact them itself, always.
1353
+
1354
+ ## Your page's own network
1355
+
1356
+ With network capture on, `fetch()` resolves when the response's headers
1357
+ arrive, exactly as without the SDK, and the body reaches the page as the
1358
+ network delivers it: a streamed response -- SSE over `fetch`, NDJSON, an
1359
+ LLM's tokens, a live log view read with `getReader()` -- streams. The SDK
1360
+ reads each body once (none when bodies are masked whole), as its only
1361
+ reader, and hands every chunk on to
1362
+ the page; it reads ahead of the page only until it has the recording
1363
+ (the whole body, or `maxBodySize` of it), so a body the page reads slowly
1364
+ is not buffered for it, and a page that cancels (`reader.cancel()`, a
1365
+ `for await` `break`, an aborted pipe) or aborts (`AbortSignal`) stops
1366
+ the download at once. A body the page never reads is still recorded. A
1367
+ page that stops reading before the body has ended (and before
1368
+ `maxBodySize`) is recorded with exactly what it read; once the SDK has
1369
+ the whole body, the whole body is what is recorded. A body that fails
1370
+ part-way -- an abort, a dropped connection, a navigation (Firefox and
1371
+ WebKit abort a page's fetches as it leaves) -- is recorded with what had
1372
+ arrived, cut and marked `...[truncated]`; the SDK may have read that far
1373
+ ahead of the page. Each of these, whole or cut, is redacted exactly as
1374
+ any other recorded body is.
1375
+
1376
+ The page has its body first. The SDK hands each body to a Web Worker,
1377
+ which redacts it off your page's main thread. It does so in a task of
1378
+ its own, after the page's stream has ended and its Response resolved
1379
+ (in an idle period where the browser has `requestIdleCallback`, at most
1380
+ a second later), never inside the relay: the page's thread copies the
1381
+ body over there (0.04 to 0.14 ms for 64 to 256 KB, MEASURED) and, in
1382
+ another idle period after the relay is over, records the answer. A
1383
+ browser with no idle periods (Safari) copies the body inside the relay
1384
+ instead, as the SDK reads its end or its cap -- while the page may still
1385
+ be reading the rest of a body past the cap -- since a task of its own
1386
+ would fall inside the page's work all the same. So a burst of responses or a
1387
+ run of large POSTs costs it no redaction, and nothing the SDK does can
1388
+ interleave with a page's `text()`. MEASURED before the page-first
1389
+ change: 50 parallel 64 KB JSON fetches took 32 ms without the SDK and
1390
+ 382 ms with it in Chromium. The exchange keeps its time and its place
1391
+ in the recording. The page leaving and `stop()`'s one-second bound
1392
+ record at once every body still in the worker, on the main thread up to
1393
+ 64 KiB in all and cut past it -- with the main thread's chunk, which
1394
+ `init()` asks for at once, beside rrweb, for a capture that redacts
1395
+ bodies. Neither moment can wait for it,
1396
+ so a body they find before it has arrived (it arrives once its fetch is
1397
+ over; offline, once the browser is back) is recorded as not captured, and
1398
+ never in the clear: the cut note with nothing kept, then a second line
1399
+ that says why. A page whose chunk could not load at all (a CSP that
1400
+ refuses it, a 404 after a deploy, `dist/index.mjs` served alone) records
1401
+ each body the main thread must redact the same way, with its own reason
1402
+ (and logs `KUI_E_BODY_WORKER_UNAVAILABLE` once per page):
1403
+
1404
+ ```
1405
+ [Body cut: 0 of N characters kept, unverified]
1406
+ [Body not captured: the page left or the capture stopped before redaction was ready]
1407
+
1408
+ [Body cut: 0 of N characters kept, unverified]
1409
+ [Body not captured: the redaction code could not load]
1410
+ ```
1411
+
1412
+ (`notCapturedBodyNote(N, why)` in `@keploy/contract/privacy`, `why`
1413
+ being `"left"` or `"code-failed"`, and `isNotCapturedBody(body, why?)`,
1414
+ which tells either from a body cut at the budget, and one cause from the
1415
+ other). Replay never serves it, as any cut body.
1416
+
1417
+ A page that is leaving starts none of the SDK's own loads (its chunks,
1418
+ rrweb's import and the body worker), and a load its leave refused or
1419
+ cancelled is held, not judged failed: a body the page leaves on is
1420
+ recorded with the first reason, and nothing is logged. A single-page
1421
+ app's route the Navigation API intercepted is no leave (the SDK reads
1422
+ `navigation.transition` a task after the `navigate`). The leave ends only
1423
+ on something a navigation still on its way cannot produce: Chromium's
1424
+ abort of the leaving navigation when no navigate came after it (an
1425
+ "unsaved changes" prompt the visitor cancelled; a link clicked twice,
1426
+ Enter pressed twice and the page's own `history.replaceState` in its
1427
+ `beforeunload` abort it too, each followed by a navigate, so none ends
1428
+ it), `pageshow` from the back/forward cache, or a capture start by the
1429
+ page's script (never a continuous capture's next session, which the
1430
+ visitor's input starts).
1431
+ The SDK then asks once more for what it held -- a worker whose script had
1432
+ not run yet included (Firefox cancels that load and says nothing; the
1433
+ worker says it runs as its first act). Neither `navigatesuccess` nor the
1434
+ visitor's input ends it: the page's own `pushState` or `replaceState`
1435
+ fires a `navigatesuccess` while a real navigation still loads, and the
1436
+ old page gets every click and key then, also after a prompt the visitor
1437
+ accepted. An app's route that comes after a navigation has begun ends no
1438
+ leave either. So a prompt cancelled in Firefox or WebKit, a download, a
1439
+ 204 and a `mailto:` link in Chromium keep the page leaving until a
1440
+ `pageshow` from the back/forward cache or a capture start by the page's
1441
+ script, its bodies recorded with the first reason and nothing logged.
1442
+ While the page leaves, a body of the leave (its exchange answered after
1443
+ the leave began) goes to the worker only if one runs: with none
1444
+ running, it is recorded with the first reason at once and its string
1445
+ dropped, so no body waits on a load the leave holds, and none
1446
+ goes to the main thread's budget because of a leave (a page with no
1447
+ worker at all redacts there as ever). A body the page was still reading
1448
+ (a fetch or an XHR whose headers had arrived), or already waiting for the
1449
+ worker's start, as the leave began is
1450
+ recorded when it can wait no longer -- so one the leave cut (Firefox
1451
+ and WebKit abort a page's fetches as it navigates, before `pagehide`)
1452
+ is recorded cut where the page left, and an XHR the leave aborts as the
1453
+ browser leaves it, status 0 and no response body (XMLHttpRequest drops
1454
+ what had arrived), its request body redacted -- on the main thread once the body code is there: a hidden tab
1455
+ records only those that fit whole, and its session's end or the page
1456
+ leaving the rest, within 64 KiB shared by all of them (those that fit
1457
+ whole first, the rest cut to what is left); with the first reason
1458
+ while the code is not there. A continuous capture's later sessions are
1459
+ no exception: the visitor's input starts each, so none ends that
1460
+ leave. A worker running as the page leaves is kept across their ends
1461
+ and redacts their bodies as ever; a session live or waiting as the
1462
+ leave ends takes it over, and it goes when no capture is live and none
1463
+ waits (the leave's end or `stop()`), at `pagehide` whatever waits (a page
1464
+ entering the back/forward cache keeps no thread; a body after a persisted
1465
+ `pageshow` starts one again), or at a session's end outside a leave, as
1466
+ ever. Without one, their bodies are recorded with
1467
+ the first reason until the leave ends. A body's strings go as it is
1468
+ recorded, so nothing the SDK holds grows with the sessions. Nothing is
1469
+ logged. `init()` never
1470
+ waits on a held load: when a leave holds rrweb's import, `init()`
1471
+ resolves once the capture is set up, and rrweb records from when its
1472
+ import lands after the leave ends; until then no DOM events are recorded,
1473
+ and nothing is logged. The same holds for a continuous capture's session
1474
+ the visitor's input starts while the page is leaving: it opens at once.
1475
+ And no GraphQL request waits on a held load: one whose term code has not
1476
+ loaded is recorded with the term `body:*` at once while the page is
1477
+ leaving, and nothing is logged; once the leave ends the code is asked
1478
+ for, and later requests carry their term. A navigate the app intercepts
1479
+ (a single-page app's route) is no leave: a request the route sends as it
1480
+ begins waits the one task it takes to know that, and has its term.
1481
+
1482
+ The browser coming back online (before
1483
+ the upload that ends an outage, when the body code had loaded before
1484
+ it went offline: nothing is fetched offline, so a page that went
1485
+ offline before its first body records it once back online), a hidden tab before its last upload
1486
+ and `stop()` record at once what fits in that budget and leave the rest
1487
+ to the worker; `pause()` cuts a body still arriving and records it when
1488
+ the worker answers.
1489
+
1490
+ The Response your page gets is one the SDK built around that body
1491
+ (unless bodies are masked whole, or it answers a HEAD or is a 204,
1492
+ 205 or 304, which have no body: then it is the network's own, and
1493
+ none of what follows applies). Its
1494
+ `url`, `redirected`, `type`, `headers` and `clone()` answer as the
1495
+ network's do, and `instanceof Response`, `bodyUsed` and BYOB readers
1496
+ behave as usual. Three things differ:
1497
+
1498
+ - A **Cache API** round trip (`cache.put()`, then `cache.match()`) keeps
1499
+ the body, status and headers but not the network's `url` and `type`:
1500
+ they come back `""` and `"default"`. That is the platform's limit, not
1501
+ a choice: the Cache API stores a Response's internal URL list and type,
1502
+ which a Response built in JavaScript cannot be given, and a clone --
1503
+ the only way to keep the network's own object -- cannot keep the
1504
+ page's backpressure in Chromium. MEASURED in Chromium, the same page
1505
+ with and without the SDK: every other member equal, these two not.
1506
+ `WebAssembly.instantiateStreaming()` likewise does not see the
1507
+ response's URL (it still compiles).
1508
+ - A **streamed upload built into a `Request`** (`new Request(url, { body:
1509
+ stream, duplex: "half" })`) that the server answers early is pulled
1510
+ further than without the SDK -- up to the chunk that crosses
1511
+ `3 x maxBodySize + 4` bytes (about `maxBodySize` bytes for ASCII). The
1512
+ SDK records a Request's body from a copy of it, and that copy reads the
1513
+ page's stream until it has what the recording keeps -- all of it for
1514
+ one declared `multipart/form-data`, which is parsed into its fields
1515
+ whole, as a FormData's is, so that it is redacted by name. That is
1516
+ the platform's limit, not a choice: no API says how much of a body the
1517
+ network consumed, a Request built on a stream cannot be told from one
1518
+ built on a Blob or FormData, and handing the network a relay instead
1519
+ would turn every ordinary Blob or FormData POST into a streamed upload,
1520
+ which Chromium refuses over HTTP/1.1. MEASURED in Chromium over HTTP/2,
1521
+ a server answering 413 after the first 64 KiB chunk: 3 chunks pulled
1522
+ without the SDK, 10 with it at the default cap. A stream passed as
1523
+ `init.body` is not read at all (recorded `[ReadableStream]`) and is
1524
+ pulled exactly as without the SDK; only Chromium streams request bodies.
1525
+ - A **`fetch` wrapper installed before the SDK** that reads or clones the
1526
+ network's Response later than the moment it hands it on finds its body
1527
+ already taken by the SDK. Wrappers that clone at once (most APM and
1528
+ error-tracking SDKs) are unaffected; initialise this SDK first if
1529
+ yours does not.
1530
+
1531
+ `KeployCapture.stop()` waits up to one second for exchanges already
1532
+ answered to finish their bodies, and records any still open then (an
1533
+ endless stream) cut at that point and marked `...[truncated]` -- as it
1534
+ does for exchanges still open when the page leaves. `KeployCapture.pause()`
1535
+ cuts them the same way at once, with no wait: a pause records nothing
1536
+ more.
1537
+
246
1538
  ## What a large body looks like
247
1539
 
248
1540
  `maxBodySize` is a bound on what is recorded, not an exact byte
@@ -287,8 +1579,28 @@ Over the bound, there are three answers, not one:
287
1579
  `responseType` makes `responseText` throw. No size: the response
288
1580
  is there in a form this note does not measure.
289
1581
  - `[Unreadable body]` — the fail-closed answer: a body that could not
290
- be read at all is never passed through. No size: nothing here was
291
- read, so there was nothing to measure.
1582
+ be read at all is never passed through, and neither is a body sent
1583
+ as `multipart/form-data` that does not parse into its fields. No
1584
+ size: nothing here was read as a body, so there was nothing to
1585
+ measure.
1586
+
1587
+ A file inside `FormData` is not one of these: the body is still
1588
+ recorded, and that field's value is `[File: name, N bytes]`, URL-encoded
1589
+ with the rest of the form. The file's bytes are never read.
1590
+
1591
+ **Where the page has no body worker** (see [Install](#install)), a
1592
+ body is redacted on the page's main thread, and only up to 64 KiB of
1593
+ it: a body over that is recorded cut, its first 64 KiB redacted as
1594
+ above under a first line that says so, `[Body cut: 65536 of N
1595
+ characters kept, unverified]`. The same note marks a body still in the
1596
+ worker when the page leaves, past the 64 KiB the page's last moment
1597
+ redacts (0 kept when nothing was left), and, with nothing kept and a
1598
+ second line saying why, a body the SDK did not capture: the page left
1599
+ before the body chunk had arrived, or the chunk could not load (see
1600
+ [Your page's own network](#your-pages-own-network)).
1601
+ It is not the response the server sent, and replay never serves it as
1602
+ one: the request is answered as a failed one and a test that reaches it
1603
+ is reported `unproven`.
292
1604
 
293
1605
  Lower `maxBodySize` to save bandwidth and you will get the second
294
1606
  answer for most large JSON, not a shorter body. If you need the shape
@@ -307,6 +1619,12 @@ origin, a start timestamp, and a nonce minted with
307
1619
  is still made; it is just not joinable). Payloads are gzipped when the
308
1620
  browser has `CompressionStream`.
309
1621
 
1622
+ Each input event rrweb records carries `userTriggered`, from the
1623
+ browser event's `isTrusted`: `true` for the visitor's own input, `false`
1624
+ for a value the page's script wrote (a form cleared after a submit) and
1625
+ for any other change no trusted event made, such as the other radios of
1626
+ a group or a date picker's write.
1627
+
310
1628
  The metadata and the capture identity ride on **every** batch, not just
311
1629
  the first. A batch is the only thing the server is guaranteed to
312
1630
  receive, and either of them arriving only with the first one is lost
@@ -322,7 +1640,7 @@ than thrown back into the code that emitted it; so is an event that
322
1640
  alone is over the ingest server's 10 MiB body cap (an rrweb snapshot
323
1641
  of a very large page, a captured body under a raised `maxBodySize`),
324
1642
  which no batch could carry. The first of each kind in a capture logs a
325
- `console.error`; any after it are dropped silently, because an emitter in a render loop
1643
+ `console.warn`; any after it are dropped silently, because an emitter in a render loop
326
1644
  would otherwise write a line every few milliseconds into the page the
327
1645
  SDK is there to record. `onError` is not called — that is reserved
328
1646
  for a condition that ENDS the capture, and this session goes on
@@ -334,16 +1652,112 @@ notice — which is why it carries a code and its evidence:
334
1652
  [keploy] KUI_E_EVENT_OVERSIZED: dropped an event: 11059200 bytes in a body, over the ingest server's 10485760-byte cap, so no batch could carry it. The capture continues; any further such events in this capture are dropped silently. evidence={"eventId":"7","eventType":"dom","bytes":11059200,"cap":10485760}
335
1653
  ```
336
1654
 
1655
+ An event is dropped the same way, and said once per capture as
1656
+ `KUI_E_EVENT_OVERSIZED_SCRUBBING`, when scrubbing the page URL's
1657
+ credentials out of it (below) would write more than that cap: the SDK
1658
+ stops as it writes, once what it has written -- less what a later
1659
+ replacement can still take off it -- passes the cap -- before
1660
+ reading a string at all when what that string must write cannot fit, at
1661
+ each place it replaces a credential in a string that could pass the cap
1662
+ or that holds an escape, after each token of JSON text and after each
1663
+ piece of CSS -- rather than spend the page's time and memory on an event
1664
+ no batch could carry. A credential is replaced by `[REDACTED]`, so
1665
+ a short declared value repeated through a crafted URL makes every link,
1666
+ `srcset` and `url()` rrweb resolves against that URL grow; `atLeast` is
1667
+ the size the scrubbed event was certain to reach when the SDK stopped.
1668
+ A dropped DOM event -- dropped here, refused at the queue for its size,
1669
+ or evicted when `maxQueueSize` or the 16 MiB cap on what is held unsent
1670
+ is passed -- leaves the recording without
1671
+ the nodes it showed, so rrweb's later DOM changes and interactions,
1672
+ which name nodes by it, are held until a full snapshot is sent again:
1673
+ sent, a click on a node only the dropped snapshot held would have been
1674
+ recorded as a click on the page body. The SDK retakes one at once when
1675
+ the event dropped was a change (a snapshot of the page may well fit),
1676
+ and 5 s after a dropped snapshot, then at doubling waits up to every 60
1677
+ s, because the page has to shrink before one fits and each attempt
1678
+ serialises the whole document; showing the tab or resuming takes one
1679
+ too. While uploads to the ingest fail, or the browser says it is offline
1680
+ and an event is dropped, none of these is taken: the hold stays, and ONE snapshot is taken when the outage ends, so an outage costs the
1681
+ page one re-serialisation, not one per dropped event -- except on a page
1682
+ whose only traffic is DOM events: there the queue can run empty, the
1683
+ outage then ends without an upload, and the snapshot is taken again
1684
+ each time the 16 MiB cap refills. rrweb's DOM changes still queued behind a dropped one are dropped
1685
+ with it, up to the next snapshot; page, network and custom events stay.
1686
+ A page whose snapshot never fits records no DOM changes or interactions
1687
+ at all, and is serialised again every 60 s for as long as it stays that
1688
+ big -- the console line above is the notice, and nothing in the
1689
+ recording itself marks the hold.
1690
+
1691
+ Two more console lines drop nothing. When the page made a History or
1692
+ Navigation API method the SDK wraps impossible to replace and put back,
1693
+ the SDK wraps none of them (see [Single-page apps](#single-page-apps)) and
1694
+ says so once per capture, naming the method:
1695
+
1696
+ ```
1697
+ [keploy] KUI_E_NAVIGATION_UNWRAPPED: the page made a History or Navigation API method impossible to replace and put back, so the SDK wrapped none of them. The capture continues: route changes are still recorded, with less detail, and none says that the page's script asked for it. evidence={"method":"history.back"}
1698
+ ```
1699
+
337
1700
  `KUI_E_EVENT_UNSERIALISABLE` (evidence `eventId`, `eventType`,
338
- `reason`) and `KUI_E_EVENT_OVERSIZED` (evidence `eventId`,
339
- `eventType`, `bytes`, `cap`) are warning-severity entries of the same
340
- error corpus as the codes above, and `SDK_WARNINGS` is the SDK's copy
341
- of their summaries and remedies; a program that only has the console
1701
+ `reason`), `KUI_E_EVENT_OVERSIZED` (evidence `eventId`, `eventType`,
1702
+ `bytes`, `cap`), `KUI_E_EVENT_OVERSIZED_SCRUBBING` (evidence
1703
+ `eventType`, `atLeast`, `cap` -- no id: the event never reached the
1704
+ queue), `KUI_E_NAVIGATION_UNWRAPPED` (evidence `method`) and
1705
+ `KUI_E_REQUEST_TERM_FAILED` (evidence `method`, `reason`; below) and
1706
+ `KUI_E_BODY_WORKER_UNAVAILABLE` (below) are written with `console.warn`, never `console.error`: the capture goes on,
1707
+ and a page whose tests or error tracker fail on `console.error` must
1708
+ not fail on one. `console.error` is kept for a capture that ENDS (an
1709
+ `init()` refused, a server rejection, both below). They are
1710
+ warning-severity entries of the same error corpus as the codes above, and `SDK_WARNINGS` carries a short summary of each and the
1711
+ link to its corpus page, where the remedy is; a program that only has the console
342
1712
  can match the token and parse the JSON after the first `evidence=`
343
1713
  (the line is one line, and nothing before the marker is yours: the
344
1714
  event's id and type are in the JSON, not in the prose). A new
345
1715
  `init()` starts a new count: once per capture, not once per page.
346
1716
 
1717
+ A request whose GraphQL term the SDK could not compute (the term is
1718
+ what replay tells GraphQL operations apart by; computing it threw: the
1719
+ SDK's own lexer or parser, or the page's SubtleCrypto) is still
1720
+ recorded, without the term, as an SDK older than the term records it, and
1721
+ the page's own request is never affected; at replay, in a recording where
1722
+ another call carries a term, it keys as `body:*`, and in one where none
1723
+ does it is answered by order as before. The term code is a chunk of its own
1724
+ (`dist/request-term`, the package's `./request-term` export), which the
1725
+ SDK loads, once, the first time a body could be a GraphQL request, so a
1726
+ page that sends none never loads it; your bundler resolves it as it
1727
+ resolves rrweb. Where it does not load (a Content-Security-Policy, offline,
1728
+ a 404), each such request is recorded `body:*`, as a page with no
1729
+ SubtleCrypto records it, and the load is not retried for the life of the
1730
+ page. While the page is leaving, a request is recorded `body:*` the same
1731
+ way if the code has not loaded, without the warning; a load the leave
1732
+ held, not yet failed, is asked for when the leave ends. At replay `body:*` matches a live request of the same method and
1733
+ URL whatever its term; a recorded key equal to the live one is chosen
1734
+ first. The first
1735
+ such request in a capture logs
1736
+ `KUI_E_REQUEST_TERM_FAILED` (evidence `method`, `reason`), a warning
1737
+ entry of the same corpus, on one line of the same shape:
1738
+
1739
+ ```
1740
+ [keploy] KUI_E_REQUEST_TERM_FAILED: recorded a request without its term, or body:*: computing it failed; the request itself was not affected. The capture continues; any further such requests in this capture are recorded that way, silently. evidence={"method":"POST","reason":"RangeError: Maximum call stack size exceeded"}
1741
+ ```
1742
+
1743
+ A page that cannot run the SDK's body worker or load its body chunk (see
1744
+ [Install](#install): a Content-Security-Policy that refuses the worker,
1745
+ webpack 4, esbuild without the file copied, a build served from another
1746
+ origin or from a CDN, a page without a bundler that serves
1747
+ `dist/index.mjs` alone) still records every
1748
+ exchange: without the worker it redacts bodies on the main thread and
1749
+ records a body over 64 KiB cut; without the body chunk too, a body the
1750
+ main thread must redact is recorded as not captured, with nothing kept,
1751
+ under `[Body not captured: the redaction code could not load]`. Replay
1752
+ reports a test over a cut or not-captured body `unproven`. It
1753
+ logs `KUI_E_BODY_WORKER_UNAVAILABLE` (evidence `part`: `worker` or
1754
+ `code`, and `reason`: what the browser said), a warning entry of the same
1755
+ corpus, once per page for each part, at its first failure:
1756
+
1757
+ ```
1758
+ [keploy] KUI_E_BODY_WORKER_UNAVAILABLE: could not run the body worker or load the body chunk (evidence.part): without the worker, a body over 64 KiB is recorded cut; without the chunk, a body the main thread must redact is recorded with nothing kept; replay reports a test over a cut body unproven. Allow worker-src 'self' in the page's CSP, use a bundler that emits the worker (or copy dist/body-worker.js beside the bundle), serve it from the page's origin, or serve the SDK's dist/ as it is. Said once per page for each part. evidence={"part":"worker","reason":"the worker's script did not load or run (refused by the page's CSP, a 404, or a script that does not parse)"}
1759
+ ```
1760
+
347
1761
  ### The last batch
348
1762
 
349
1763
  When the page unloads — a navigation, a tab close — whatever is still
@@ -351,8 +1765,22 @@ queued is sent in one `keepalive` request from the `pagehide` handler.
351
1765
  Browsers cap the sum of a document's in-flight keepalive bodies at
352
1766
  64 KiB (MEASURED in Chromium 145: 65,536 bytes accepted, 65,537
353
1767
  refused), and a request over that is refused before it leaves, losing
354
- everything in it. So that last request is cut at the first event that
355
- does not fit, oldest first, and what does not fit stays behind — an
1768
+ everything in it. That quota is the PAGE's as well: a lead form's
1769
+ keepalive POST or an analytics `sendBeacon` is refused while the SDK
1770
+ holds it (MEASURED with a 63 KB upload on the wire: the page's 2 KB
1771
+ beacon refused in Chromium and WebKit, its keepalive fetch in WebKit).
1772
+ So the SDK keeps its own keepalive bodies in flight to half of it,
1773
+ 32 KiB, counting what is still on the wire, and leaves the page the
1774
+ rest. An upload over 32 KiB gzipped goes without `keepalive`, so a
1775
+ navigation before it completes cancels it (a tab close does not). A
1776
+ queue past what the pagehide request can carry is sent at once, as a
1777
+ plain fetch -- never `keepalive`, so the pagehide request keeps the
1778
+ SDK's whole share -- one upload at a time, ending once the queue is back
1779
+ under. Events queued behind an upload still on the wire when the visitor
1780
+ leaves go in the pagehide request, up to 32 KiB; the upload on the wire
1781
+ is cancelled by the navigation (a tab close lets it finish). The
1782
+ pagehide request is cut at 32 KiB, at the first event that does not fit,
1783
+ oldest first, and what does not fit stays behind — an
356
1784
  event held back is one whose node ids the events after it depend on,
357
1785
  so shipping past it would be worse than stopping there.
358
1786
 
@@ -365,12 +1793,15 @@ sees the session in order.
365
1793
  What is **not**: a request already on the wire when the document dies.
366
1794
  A keepalive request survives the document, so it usually arrives — but
367
1795
  if it does not, the SDK cannot know and cannot resend it. And an event
368
- whose JSON, with the envelope that wraps it, exceeds the 64 KiB cap
1796
+ whose JSON, with the envelope that wraps it, exceeds the SDK's 32 KiB
369
1797
  cannot travel this way at all; the SDK posts such an event the moment
370
1798
  it is queued rather than leaving it to be cut here — but not while the
371
- browser reports itself offline. The post is deferred then to the
372
- `online` event, which drains the queue rather than sending the one
373
- batch a timed flush sends. A navigation before that event still runs
1799
+ browser reports itself offline (`navigator.onLine`, read each time: the
1800
+ `online` and `offline` events are when the SDK acts, not what it
1801
+ believes). The post is deferred then until the browser is back: to the
1802
+ `online` event or, on a page that stops that event, to the next timed
1803
+ flush, either of which then drains the queue rather than sending one
1804
+ batch. A navigation before that still runs
374
1805
  the unload flush, and this event is precisely what that flush cannot
375
1806
  carry: it is lost, with everything queued behind it and anything ahead
376
1807
  of it that does not fit the single batch that flush sends — the
@@ -382,7 +1813,11 @@ post that did go out. `maxBodySize` bounds a network event's size, and
382
1813
  ## When the server rejects a batch
383
1814
 
384
1815
  A `4xx` other than `429` is terminal: a revoked key, a key for another
385
- app, or a second run claiming a session id that is already live. The
1816
+ app, or a second run claiming a session id that is already live (with
1817
+ `continuous` and session ids the SDK minted, a refusal whose `reason`
1818
+ is `session_completed` or `session_full` is not: the server completed
1819
+ or filled that session, and the next one starts at the visitor's next
1820
+ interaction). The
386
1821
  SDK ends the CAPTURE — recording stops, `fetch` and `XMLHttpRequest`
387
1822
  are unpatched, and the singleton is released — logs a `console.error`
388
1823
  carrying the server's own explanation, and calls `onError` once with a
@@ -394,34 +1829,61 @@ rather than handing back the one that failed.
394
1829
  The `CaptureError` is for the program, not just the person reading the
395
1830
  console. Branch on `code`, never on the message:
396
1831
 
397
- | `code` | the server answered | what to do (`remedy.manual`, in short) |
398
- | --------------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
399
- | `KUI_E_INGEST_KEY_REJECTED` | 401 or 403 | the key is missing, unknown, expired, revoked, or not a UI ingest key (a personal access token is refused) — mint one with the api-server GraphQL mutation `createUIIngestKey(appId, name, ttlDays)` and pass it as `apiKey` |
400
- | `KUI_E_INGEST_ENDPOINT_NOT_FOUND` | 404 or 405 | `endpoint` is wrong, not the key — the ingest route is `<api-server>/ui/v1/ingest`. Only a typo under `/ui/v1/` or a same-origin proxy produces this; a wrong endpoint on another origin fails its CORS preflight, which the SDK can only retry as a network error, so silence is not proof the endpoint is right |
401
- | `KUI_E_SESSION_CONFLICT` | 409 | this session id is already claimed — give each run its own, usually by removing a fixed-value `sessionIdGenerator` |
402
- | `KUI_E_INGEST_REJECTED` | any other terminal 4xx | read `serverMessage`; `ui session has reached its size limit` means stop and re-init for a new session, anything else is an SDK/server version mismatch (the SDK checks the session id, clamps `batchSize` and cuts every batch at the 10 MiB body cap before sending, so nothing you configure produces one) and `issues` names the field |
403
- | `KUI_E_SESSION_ID_INVALID` | nothing — raised before the first byte | `sessionIdGenerator` returned a string outside the server's rule (`evidence.rule`), returned a non-string, or threw — `evidence.received` says which; make it return a string inside the rule, or remove the override |
404
-
405
- `onError` receives one of two subclasses of `CaptureError`, and
1832
+ | `code` | the server answered | what to do (in short; see `remedy.docs`) |
1833
+ | ------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1834
+ | `KUI_E_INGEST_KEY_REJECTED` | 401 or 403 | the key is missing, unknown, expired, revoked, or not a UI ingest key (a personal access token is refused) — mint one with `POST <api-server>/client/v1/apps/<appId>/ui/ingest-keys` and a personal access token (the MCP tool `uiCaptureSetup` does the same) and pass it as `apiKey` |
1835
+ | `KUI_E_INGEST_ENDPOINT_NOT_FOUND` | 404 or 405 | `endpoint` is wrong, not the key — the ingest route is `<api-server>/ui/v1/ingest`. Only a typo under `/ui/v1/` or a same-origin proxy produces this; a wrong endpoint on another origin fails its CORS preflight, which the SDK can only retry as a network error, so silence is not proof the endpoint is right |
1836
+ | `KUI_E_SESSION_CONFLICT` | 409 | this session id is already claimed — give each run its own, usually by removing a fixed-value `sessionIdGenerator` |
1837
+ | `KUI_E_INGEST_REJECTED` | any other terminal 4xx | read `serverMessage`; `ui session has reached its size limit` means stop and re-init for a new session; a 413 holding neither of the server's sentences is a proxy's own body limit, so raise it to at least 10 MiB; anything else is an SDK/server version mismatch (the SDK checks the session id, clamps `batchSize` and cuts every batch at the 10 MiB body cap before sending, so nothing you configure produces one) and `issues` names the field |
1838
+ | `KUI_E_SESSION_ID_INVALID` | nothing — raised before the first byte | `sessionIdGenerator` returned a string outside the server's rule (`evidence.rule`), returned a non-string, or threw — `evidence.received` says which; make it return a string inside the rule, or remove the override |
1839
+ | `KUI_E_DOM_RECORDER_UNAVAILABLE` | nothing — raised before anything is sent | rrweb could not be imported in the browser (`evidence.reason` says why) — load the SDK through a bundler, or map `rrweb` with an import map; a blocked chunk (CSP, network) is refused the same way |
1840
+ | `KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE` | nothing — raised before anything is recorded | under `privacyMode: "strict"`, its attribute allow-list (`dist/strict-attributes.mjs`, a chunk only strict loads) could not be loaded (`evidence.reason` says why) — serve every chunk your bundler emits, or, with no bundler, dist/ as it is; a browser keeps a failed import for the page, so reload |
1841
+ | `KUI_E_PRIVACY_ROUTE_INVALID` | nothing — raised before the first byte | a `privacy.secretRoutes` or `privacy.keepRoutes` entry is no route (`evidence.option`, `evidence.received`, `evidence.rule`) — rewrite it inside the rule (`/invites/:key`) or remove it |
1842
+ | `KUI_E_CAPTURE_DECLINED` | nothing — raised before anything is recorded | the browser sent Do Not Track or Global Privacy Control (`evidence.signal`) and `honorPrivacySignals` is on: the person using the page said no, and nothing needs fixing |
1843
+ | `KUI_E_PRIVACY_CONFLICT` | nothing — raised before anything is recorded | `privacyMode: "strict"` records no body and `privacy.maskNetworkBodies` is `false`, which asks for them (`evidence.option`): remove that option, or use `"balanced"` if the recording needs bodies |
1844
+
1845
+ `onError` receives one of seven subclasses of `CaptureError`, and
406
1846
  branching on `code` narrows to it, so a TypeScript handler can read the
407
1847
  evidence the remedy names. An `IngestRejection` (the four
408
1848
  server-answered codes) carries `status`, `serverMessage` (the `error`
409
1849
  field of the server's JSON body, or the body's text, or `null`),
410
1850
  `issues` (the server's `[{ path, message }]` when its body had them — a
411
- 400 says which field — or `null`), `remedy` (`{ command, manual }` —
412
- `command` is `null` on all five, because no build has a verb that mints
413
- a key, edits the endpoint or rotates a session), and `evidence`
1851
+ 400 says which field — or `null`), `remedy` (`{ command, manual, docs }`
1852
+ — `docs` is the error's page in the Keploy docs, where the remedy is;
1853
+ `manual`, deprecated, holds the same link (3.0 carried the remedy's
1854
+ prose there); and `command` is `null`
1855
+ on every code, because no `keploy` CLI verb mints a key, edits the
1856
+ endpoint or rotates a session), and `evidence`
414
1857
  (`{ status, serverMessage, endpoint, sessionId }` plus `issues` when
415
1858
  sent, exactly the fields the corpus declares). A `SessionIdRefusal`
416
1859
  (`KUI_E_SESSION_ID_INVALID`) is raised by the SDK itself before anything
417
1860
  is sent, so its `status` is `null` and its evidence is
418
1861
  `{ sessionId, received, rule }` — the string the generator returned or
419
1862
  `null`, what it produced (`number 42`, `object {}`, `threw Error: boom`),
420
- and the rule. The five codes, their summaries, remedies and evidence
421
- are the entries of the same name in `@keploy/contract`'s error corpus;
422
- the SDK carries a copy because rrweb is its only runtime dependency,
423
- and a test holds the copy to the corpus. The status-to-code mapping is
424
- `spec/sdk-errors.v1.json`; the session-id rule is
1863
+ and the rule. A `DomRecorderRefusal` (`KUI_E_DOM_RECORDER_UNAVAILABLE`)
1864
+ is raised in a browser, before anything is sent, when rrweb cannot be
1865
+ imported; its evidence is `{ reason }`, the browser's error. A
1866
+ `StrictAttributesRefusal` (`KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE`) is
1867
+ raised the same way under `strict` when its attribute allow-list cannot
1868
+ be imported, with the same `{ reason }`. A
1869
+ `PrivacyRouteRefusal` (`KUI_E_PRIVACY_ROUTE_INVALID`) is raised before
1870
+ anything is sent when a declared privacy route is no route; its evidence
1871
+ is `{ option, received, rule }`. A `CaptureDeclined`
1872
+ (`KUI_E_CAPTURE_DECLINED`) is the browser's privacy signal, not a
1873
+ failure: it is logged with `console.info`, its `status` is `null`, and
1874
+ its evidence is `{ signal }` — `doNotTrack` or `globalPrivacyControl`.
1875
+ A `PrivacyConflict` (`KUI_E_PRIVACY_CONFLICT`) is the site's own config
1876
+ contradicting itself: its `status` is `null` and its evidence is
1877
+ `{ privacyMode, option }` — `"strict"` and the option that asks for
1878
+ what strict leaves out. The ten
1879
+ codes and their evidence are the entries of the same name in
1880
+ `@keploy/contract`'s error corpus. The SDK carries each entry's code, a
1881
+ short summary of what happened and the link to the entry's page, and
1882
+ no remedy text, which stays on that page; a test holds the summary, the
1883
+ link and the evidence to the corpus. The `docs` pages are published
1884
+ with the same docs release as the guide above, and answer 404 until
1885
+ then. The status-to-code mapping is
1886
+ `spec/sdk-errors.v4.json`; the session-id rule is
425
1887
  `spec/session-id.v1.json`, the api-server's rule stated once — the
426
1888
  SDK and the sidecar execute the file today, and the api-server's own
427
1889
  executor lands with its next vendoring of the corpus. `onError` runs
@@ -435,26 +1897,42 @@ await KeployCapture.init({
435
1897
  endpoint,
436
1898
  apiKey,
437
1899
  onError: (err) => {
1900
+ // The person using the page said no (Do Not Track or Global Privacy
1901
+ // Control). Not a failure: keep it out of your error tracker --
1902
+ // Brave and DuckDuckGo send GPC by default.
1903
+ if (err.code === "KUI_E_CAPTURE_DECLINED") return;
438
1904
  if (err.code === "KUI_E_SESSION_ID_INVALID")
439
1905
  fixGenerator(err.evidence.received);
1906
+ else if (
1907
+ err.code === "KUI_E_DOM_RECORDER_UNAVAILABLE" ||
1908
+ err.code === "KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE"
1909
+ )
1910
+ report(err.code, err.evidence.reason);
1911
+ else if (err.code === "KUI_E_PRIVACY_ROUTE_INVALID")
1912
+ report(err.code, err.evidence.option, err.evidence.received);
1913
+ else if (err.code === "KUI_E_PRIVACY_CONFLICT")
1914
+ fixConfig(err.evidence.option);
440
1915
  else if (err.code === "KUI_E_INGEST_KEY_REJECTED") rotateKeyAndReload();
441
1916
  else
442
- report(
443
- err.code,
444
- err.serverMessage,
445
- err.evidence.issues,
446
- err.remedy.manual,
447
- );
1917
+ report(err.code, err.serverMessage, err.evidence.issues, err.remedy.docs);
448
1918
  },
449
1919
  });
450
1920
  ```
451
1921
 
452
- A `429`, a `5xx` or a network failure gets three attempts:
453
- up to 1 s between the first and the second, up to 2 s between the
454
- second and the third, and then — if the third fails too — up to a
455
- further 4 s before the batch goes back to the front of the queue. Two
456
- gaps between three attempts; the last wait delays the re-queue rather
457
- than an attempt.
1922
+ A `429`, a `5xx` or a network failure gets three attempts: up to 1 s
1923
+ between the first and the second, up to 2 s between the second and the
1924
+ third, and then the batch goes back to the front of the queue. From then
1925
+ on uploads are failing: each later batch gets ONE attempt, and the timer,
1926
+ a filled batch and a large event start none until 2 s, then 4, 8, 16, 32
1927
+ and at most 60 s (each up to half again, at random) have passed since the
1928
+ last failure, so a dead ingest gets about one request a minute (a page whose only
1929
+ traffic is DOM events also restarts the wait each time its queue runs
1930
+ empty). `stop()`,
1931
+ a hidden tab, `online` and the page's unload still send at once. The
1932
+ first batch accepted ends it: what piled up is sent, and if DOM events were dropped meanwhile, one fresh snapshot is taken. What is held unsent is
1933
+ capped at 16 MiB as well as at `maxQueueSize`; past either, the oldest
1934
+ is dropped (a batch that failed and goes back to the queue past
1935
+ `maxQueueSize` drops the newest queued events instead).
458
1936
 
459
1937
  ## What it deliberately does not do
460
1938
 
@@ -464,13 +1942,17 @@ than an attempt.
464
1942
  - **No `Math.random` fallback for the session nonce**, so a recording
465
1943
  is either joinable or says why it is not.
466
1944
  - **No sampling by user.** `sampleRate` is decided per session start.
1945
+ - **No guessing which generic field holds a secret.** A name/value pair
1946
+ is read by its `key`, `name` or `header`; a pair spelled otherwise
1947
+ (`{field, val}`), or one whose name is not a secret's own (an
1948
+ extracted variable called `x` holding a bearer token), is left to the
1949
+ pattern detectors. Name such a field in `privacy.piiPatterns` if its
1950
+ values need to go.
467
1951
 
468
1952
  ## Docs and help
469
1953
 
470
- - [UI Flow Capture overview](https://keploy.io/docs/ui-capture/overview/) — how recordings
471
- become flows, generated tests and verdicts
472
- - [Installing the SDK](https://keploy.io/docs/ui-capture/install-sdk/) — this page, in
473
- more detail
1954
+ - [UI Capture guide](https://keploy.io/docs/running-keploy/ui-capture/) — set up capture
1955
+ from the dashboard, the REST API or an AI agent, and read the flows
474
1956
  - [Keploy documentation](https://keploy.io/docs/)
475
1957
  - [Keploy community Slack](https://join.slack.com/t/keploy/shared_invite/zt-3zcnuqfgl-WYK1NMhslVHsCtNcA1ULwA)
476
1958
  - <support@keploy.io>
@@ -478,5 +1960,10 @@ than an attempt.
478
1960
  ## License
479
1961
 
480
1962
  Apache-2.0. The full text ships in this package: see
481
- [LICENSE](./LICENSE). The rest of Keploy UI Flow Capture is
1963
+ [LICENSE](./LICENSE). The rest of Keploy UI Capture is
482
1964
  proprietary; this package is the part that runs in your own bundle.
1965
+ The bundle inlines one file from outside this package, the
1966
+ credential-name rule shared with Keploy's replay
1967
+ (`packages/contract/src/privacy.ts` in the source repository), and that
1968
+ file is Apache-2.0 too: its text, with its SPDX header, is in the
1969
+ source maps beside the bundle.