@keploy/capture-sdk 3.1.0-rc.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +597 -121
  2. package/body-redact/package.json +6 -0
  3. package/body-worker-start/package.json +6 -0
  4. package/dist/body-jobs.d.ts +230 -0
  5. package/dist/body-redact.d.ts +29 -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 +38 -6
  27. package/dist/index.bundler.mjs +1 -0
  28. package/dist/index.bundler.mjs.map +1 -0
  29. package/dist/index.d.ts +74 -9
  30. package/dist/index.js +1 -11
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +1 -11
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/leave.d.ts +67 -0
  35. package/dist/module-of.d.ts +62 -0
  36. package/dist/network.d.ts +87 -60
  37. package/dist/page-stream.d.ts +24 -0
  38. package/dist/privacy.d.ts +27 -3
  39. package/dist/recorder.d.ts +30 -6
  40. package/dist/redact.d.ts +25 -2
  41. package/dist/request-term.d.ts +2 -0
  42. package/dist/request-term.js +1 -2
  43. package/dist/request-term.js.map +1 -1
  44. package/dist/request-term.mjs +1 -2
  45. package/dist/request-term.mjs.map +1 -1
  46. package/dist/strict-attributes.d.ts +9 -0
  47. package/dist/strict-attributes.js +1 -0
  48. package/dist/strict-attributes.js.map +1 -0
  49. package/dist/strict-attributes.mjs +1 -0
  50. package/dist/strict-attributes.mjs.map +1 -0
  51. package/dist/transport.d.ts +35 -3
  52. package/dist/types.d.ts +44 -7
  53. package/package.json +31 -4
  54. package/strict-attributes/package.json +6 -0
package/README.md CHANGED
@@ -5,9 +5,10 @@ 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; 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).
8
+ Keploy. Keploy turns the recordings into deduplicated flows and, in
9
+ beta, into Playwright tests that replay recorded journeys against
10
+ recorded mocks. This package only records: generating and running the
11
+ tests is Keploy's side, not the SDK's (see below).
11
12
 
12
13
  This package runs inside your bundle, on your users' machines, which is
13
14
  why it is **Apache-2.0** while the rest of the product is proprietary.
@@ -35,8 +36,10 @@ over the REST API (`/client/v1/apps/<appId>/ui/capture-status` and
35
36
  [UI Capture guide](https://keploy.io/docs/running-keploy/ui-capture/)
36
37
  walks through all three.
37
38
 
38
- Not in this release: generating Playwright tests from flows and running
39
- them. Flows are what you get today.
39
+ In beta: generating Playwright tests from recorded journeys (a visit's
40
+ flows, chained in order) and running them against recorded mocks. That
41
+ is Keploy's side, not this package's: the SDK only records, and nothing
42
+ in it generates or runs a test.
40
43
 
41
44
  ## What you get
42
45
 
@@ -58,23 +61,38 @@ npm install @keploy/capture-sdk
58
61
  A runtime dependency, not a dev one: it runs in production, on the
59
62
  page. Its only dependency is `rrweb`, which your bundler resolves; there
60
63
  are no peer dependencies. The package ships ESM and CommonJS
61
- (`dist/index.mjs`, `dist/index.js`) with types. The bundle is 41.4 kB
64
+ (`dist/index.mjs`, `dist/index.js`) with types, and a second ESM build,
65
+ `dist/index.bundler.mjs`, for the bundlers that read the `module` field
66
+ rather than the `exports` map (webpack 4, Parcel by default): the same
67
+ SDK without the worker start a page with no bundler loads from beside
68
+ it (see below), so webpack 4 never reads `import.meta`, for the web or
69
+ for node. The bundle is 40.9 kB
62
70
  (decimal) gzipped with rrweb excluded -- the ESM build; the CommonJS
63
- build is 41.7 kB -- MEASURED on the repository's build at its
64
- placeholder version (`tsup src/index.ts --minify --sourcemap --platform browser`);
71
+ build is 41.1 kB and the `module` field's build is 40.9 kB, and
72
+ `privacyMode: "strict"` alone loads its 1.3 kB attribute allow-list
73
+ beside it -- MEASURED on the repository's build at its
74
+ placeholder version (`pnpm build`, which runs `node scripts/build-main.mjs`);
65
75
  the published build carries its version in place of the placeholder,
66
76
  which moves both figures by a few bytes either way (MEASURED for
67
77
  3.1.0-rc.1: 2 B more on each build). It is fully minified, so its
68
78
  local names are shortened: that is what keeps an SDK that redacts what
69
- it records, in the browser, near its budget: 40 KiB, the CommonJS build
70
- plus the 356 B its format costs, with a TEMPORARY 464 B allowance on both
71
- builds until the Web Worker redaction PR. On the repository's build the
72
- ESM build is 415 B over its base budget and the CommonJS build 416 B. The source maps ship
73
- beside it as separate files, `dist/index.mjs.map` and
74
- `dist/index.js.map`, never inlined and carrying the SDK's own sources,
79
+ it records, in the browser, within its budget: 40 KiB, and 41,316 B for
80
+ the CommonJS build, set on 2026-11-11 as 40 KiB plus the 356 B its
81
+ format cost then (as built now, the format costs 194 B). Body
82
+ redaction is not in it: it runs in
83
+ a Web Worker, `dist/body-worker.js` (9.3 kB gzipped), which your bundler
84
+ emits beside your app and the SDK starts when a capture that redacts
85
+ bodies starts, in the page's next idle period; its main-thread copy,
86
+ `dist/body-redact.mjs` (9.7 kB gzipped), is a chunk `init()` asks for at once
87
+ for such a capture, beside rrweb, while your page's network is recorded
88
+ from the start (see [Your page's own network](#your-pages-own-network)).
89
+ A capture that masks bodies whole (`privacy.maskNetworkBodies`, which
90
+ `privacyMode: "strict"` sets) loads neither. The source maps ship
91
+ beside it as separate files, `dist/index.mjs.map`,
92
+ `dist/index.bundler.mjs.map` and `dist/index.js.map`, never inlined and carrying the SDK's own sources,
75
93
  so a stack trace from the page decodes back to the SDK's functions and
76
- lines in any tool that reads source maps. A test holds the figure, the maps and the limit: the 40 KiB
77
- budget this package is held to, plus the temporary 464 B allowance. There is no
94
+ lines in any tool that reads source maps. A test holds the figures, the maps and the limits: the 40 KiB
95
+ budget this package is held to, and 12 KiB for each body chunk. There is no
78
96
  script-tag build: the only way in is an `import`, and the SDK loads
79
97
  `rrweb` with `import("rrweb")`, which a bundler resolves. Without one,
80
98
  map the
@@ -86,12 +104,64 @@ than recording nothing in silence.
86
104
 
87
105
  A bundler that ignores a package's `exports` map -- webpack 4, as under
88
106
  Create React App 4, or Parcel 2 by default -- resolves the SDK's
89
- `request-term` subpath through the `request-term/package.json` the
107
+ `request-term` and `strict-attributes` subpaths through the
108
+ `request-term/package.json` and `strict-attributes/package.json` the
90
109
  package ships. **Parcel 2 needs the `buffer` package installed** (`npm
91
110
  install buffer`): rrweb's build reads Node's `Buffer`, and Parcel
92
111
  polyfills no Node built-in it is not given. That is rrweb's need, not
93
112
  new in this version; 3.0.1 has it too.
94
113
 
114
+ The body worker is started as `new Worker(new URL("./body-worker.js",
115
+ import.meta.url))`, which webpack 5, Next.js (webpack and Turbopack),
116
+ Vite and Parcel 2 turn into a file of your build (each is built in the
117
+ SDK's tests). These setups have no worker, and redact bodies on the
118
+ page's main thread instead, each body only up to 64 KiB (see [What a
119
+ large body looks like](#what-a-large-body-looks-like)):
120
+
121
+ - **webpack 4** cannot parse `import.meta`, so the SDK keeps it out of
122
+ every file webpack 4 reads.
123
+ - **esbuild** does not emit the worker: copy
124
+ `node_modules/@keploy/capture-sdk/dist/body-worker.js` beside your
125
+ bundle and it runs.
126
+ - **A build whose assets are served from another origin** (webpack's
127
+ `publicPath` or Next's `assetPrefix` on a CDN): a browser runs a
128
+ worker only from the page's own origin.
129
+ - **A Content-Security-Policy that does not let your origin run it**:
130
+ allow `worker-src 'self'` (or the `child-src` or `script-src` it falls
131
+ back to).
132
+ - **The SDK's files served from another origin without a bundler** (a
133
+ CDN): the chunks load from there (it must send CORS headers, as CDNs
134
+ do), the worker cannot. Import `dist/index.mjs` by its path. unpkg's
135
+ package root redirects there too; jsDelivr's answers with the file at
136
+ the root's own URL, where no chunk is beside it, so name the path
137
+ there. The SDK loads only chunks of its own version: unpkg's `?module`
138
+ rewrites the SDK's imports of its own name to the `@latest` version's
139
+ files, which `dist/index.mjs` refuses, loading its own from beside it.
140
+ A package-root URL with `?module` serves the `module` field instead,
141
+ `dist/index.bundler.mjs` (webpack 4's build), which loads no chunk from
142
+ beside it, and records every body as not captured (see below) -- and
143
+ refuses
144
+ every strict capture with `KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE`,
145
+ having no allow-list to load.
146
+
147
+ **Without a bundler**, serve the package's `dist/` directory as it is
148
+ and import `dist/index.mjs` from it, with an import map for `rrweb`
149
+ alone: the SDK loads its chunks and the worker from beside
150
+ `dist/index.mjs` (`dist/body-redact.mjs`, `dist/request-term.mjs`,
151
+ `dist/strict-attributes.mjs` under strict, and
152
+ `dist/body-worker-unbundled.mjs`, which starts `dist/body-worker.js`),
153
+ and an import map that maps `@keploy/capture-sdk/body-redact`,
154
+ `/body-worker-start`, `/request-term` or `/strict-attributes` is
155
+ honoured first. A page that serves `dist/index.mjs` alone has no code
156
+ to redact a body with, and records each body as not captured, never in
157
+ the clear (under strict it records nothing, refused with
158
+ `KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE`):
159
+
160
+ ```
161
+ [Body cut: 0 of N characters kept, unverified]
162
+ [Body not captured: the redaction code could not load]
163
+ ```
164
+
95
165
  ## Use
96
166
 
97
167
  One call, as early in your app's startup as you can make it:
@@ -117,8 +187,8 @@ SDK uses when you leave them out:
117
187
 
118
188
  | option | default | what it does |
119
189
  | --------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120
- | `privacyMode` | `"balanced"` | `"balanced"` masks every typed input value; `"strict"`, for public sites, also masks every visible text node, records no request or response body and replaces every query value in a URL; `"off"` masks only password and hidden fields — see [Privacy](#privacy) |
121
- | `sampleRate` | `1` | fraction of sessions recorded, decided once when a session starts. `0.1` records one visitor in ten; the rest never start |
190
+ | `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) |
191
+ | `sampleRate` | `1` | fraction of captures recorded, rolled when `init()` starts one: `0.1` records one in ten; the rest never start. A later `init()` returns the same capture, sampled out or not, and rolls again only after `stop()` or the session's end. Under `continuous`, each session after a recorded one is recorded too, with no new roll |
122
192
  | `networkCapture` | `true` | record `fetch` and `XMLHttpRequest` exchanges. `false` records the DOM only |
123
193
  | `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 |
124
194
  | `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) |
@@ -130,7 +200,7 @@ SDK uses when you leave them out:
130
200
  | `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 |
131
201
  | `privacy` | — | a `Partial<PrivacyConfig>`: `maskSelectors`, `unmaskSelectors`, `blockSelectors`, `maskNetworkBodies`, `sensitiveHeaders`, `piiPatterns`, `secretRoutes`, `keepRoutes` — see [Privacy](#privacy) |
132
202
  | `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`) |
133
- | `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 |
203
+ | `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` a task later, paced, for every declined `init()` but one made while 16 wait (see `onError` below), 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 |
134
204
  | `onError` | — | called once when a terminal condition ends the capture — see [When the server rejects a batch](#when-the-server-rejects-a-batch) |
135
205
 
136
206
  After `init`, the static surface is:
@@ -140,6 +210,7 @@ KeployCapture.pause(); // keep the session, record nothing more
140
210
  KeployCapture.resume();
141
211
  KeployCapture.getSessionId(); // "" when no session is live
142
212
  KeployCapture.getCaptureIdentity(); // the browser half of the backend join, or why there is none
213
+ KeployCapture.getInstance(); // the capture, sampled out too; null before init(), after stop(), a declined or refused init(), between sessions
143
214
  KeployCapture.stop(); // stop recording and send what is queued
144
215
  ```
145
216
 
@@ -379,10 +450,12 @@ loaded again.
379
450
 
380
451
  Once rrweb has loaded, what was held is sent in order, one batch
381
452
  (`batchSize` events) per round trip, and a visitor who leaves while
382
- more is still waiting than one unload request carries (64 KiB, below)
453
+ more is still waiting than one unload request carries (32 KiB, below)
383
454
  loses the first event that does not fit and everything behind it: a
384
455
  snapshot larger than that by itself, or a smaller one whose backlog has
385
- not gone yet. MEASURED in review, in Chromium, with a navigation 100 ms
456
+ not gone yet. MEASURED in review, in Chromium, when that request carried
457
+ 64 KiB (before 3.1.0-rc.2; the 51 KB and 53 KB snapshots below are now
458
+ over it, so they are sent the moment they are queued), with a navigation 100 ms
386
459
  after the network came back: a 141 KB snapshot behind the requests a
387
460
  page made offline was lost 4 times of 4 (an ingest answering in
388
461
  150 ms), and a 51 KB one 3 times of 3 behind 95 requests, where behind
@@ -418,10 +491,10 @@ Those two are the reason this SDK hands rrweb its own map: rrweb's
418
491
  `maskAllInputs` covers the other sixteen rows and neither of these.
419
492
 
420
493
  `radio`, `checkbox`, `submit`, `button`, `reset` and `image` are **not**
421
- in that table: their `value` is recorded verbatim in every mode,
422
- `strict` included. For the first four nothing can reach it —
423
- rrweb serialises those four before masking is consulted, so no option
424
- this SDK could pass would change them. `reset` and `image` could be
494
+ in that table: their `value` is recorded verbatim under `balanced` and
495
+ `off`, and blanked under `strict` (below). For the first four rrweb
496
+ serialises the value before masking is consulted, so no option this
497
+ SDK could pass rrweb would change them; strict blanks them after. `reset` and `image` could be
425
498
  masked and deliberately are not: a reset button's value is the caption
426
499
  it shows, and an image button's is metadata the page's author wrote,
427
500
  neither being anything the person using the page entered. For the
@@ -430,6 +503,89 @@ whose value is an email address, say — the only lever is
430
503
  `privacy.blockSelectors`, and that removes the element from the
431
504
  recording altogether.
432
505
 
506
+ **Strict records no page text in the DOM.** Text lives in more places
507
+ than text nodes, and a page can copy a visitor's search into any of them
508
+ (a search page's `<title>` and `<meta name="description">`). Under
509
+ `strict`, attributes are read by an ALLOW-LIST: an attribute keeps its
510
+ value only when its name is the page's structure -- `id`, `class`,
511
+ `role`, `name`, `type`, `data-testid`, ARIA state and relationships
512
+ (`aria-expanded`, `aria-labelledby`), form and layout attributes (`for`,
513
+ `disabled`, `colspan`, `width`), SVG geometry and paint (`d`,
514
+ `viewBox`, `fill`) and rrweb's own -- or when its own rule reads it: a
515
+ URL (query values replaced), CSS, a `srcset`, a `srcdoc` (its text and
516
+ attributes masked the same way, its scripts included). Every other
517
+ value is recorded as `""`: `title`, `alt`, `placeholder`, `aria-label`
518
+ and the other `aria-*` text, every `data-*` but `data-testid`,
519
+ `data-src`, `data-href` and `data-srcset` (a lazy loader's URLs:
520
+ `data-srcset` read by the `srcset` rule, and `data-src` and `data-href`
521
+ by the URL rule when the value can be a URL -- no space, quote or brace;
522
+ text in one is blanked), every `value` rrweb records in clear (a field's
523
+ that rrweb masked keeps its asterisks), a framework's state
524
+ (`wire:snapshot`, `x-data`, `hx-vals`, an Astro island's `props`), a
525
+ custom element's attributes but its global ones (`id`, `class`, `slot`,
526
+ ARIA state), an input's `min`,
527
+ `max` and `pattern` (a date range copies the start the visitor picked
528
+ into the end's `min`; a confirm field copies a typed email into
529
+ `pattern`) and `aria-valuenow` (a slider's chosen value). SVG geometry
530
+ and paint are kept on SVG elements only, by exact name. A `<meta>`'s
531
+ `content` is blanked unless the meta configures the page (`http-equiv`,
532
+ or a `name` of `viewport`, `color-scheme`, `theme-color`, `referrer`,
533
+ `robots` or `format-detection`) -- in a mutation, unless the change itself carries that `http-equiv` or
534
+ `name`, and in a `srcdoc`, always. A comment is blanked; a checkbox's or
535
+ radio's value in an Input event is asterisks. The `<title>` element's
536
+ text and SVG `<text>` are text nodes, masked as every other.
537
+
538
+ The allow-list is a chunk of its own, `dist/strict-attributes.mjs`
539
+ (`.js` for CommonJS), which only `strict` loads: `balanced` and `off`
540
+ never ask for it and carry none of its bytes. Under `strict` the SDK
541
+ imports it at `init()`, in parallel with rrweb, and records nothing
542
+ until both have loaded, so no snapshot is ever taken without it. A
543
+ bundler emits it as a chunk; with no bundler, serve dist/ as it is and
544
+ the SDK loads it from beside `dist/index.mjs`. If it cannot be loaded (a
545
+ Content-Security-Policy, a network failure, a deployment that drops the
546
+ file), the capture ends before anything is recorded or sent, with
547
+ `KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE` (see [When the server rejects a batch](#when-the-server-rejects-a-batch)): strict
548
+ records nothing rather than attributes it cannot read.
549
+
550
+ ARIA under strict keeps what describes the widget -- its structure
551
+ (`aria-level`, `aria-posinset`, row and column counts), its relationships
552
+ (`aria-labelledby`, `aria-controls` and the other id references), its
553
+ configuration (`aria-haspopup`, `aria-orientation`, `aria-required`) and
554
+ `aria-expanded`/`aria-hidden` -- and blanks every one that reflects what
555
+ the visitor chose or entered: `aria-valuenow`, `aria-valuemin`,
556
+ `aria-valuemax` (a two-thumb slider's bounds are the other thumb's chosen
557
+ value), `aria-valuetext`, `aria-checked`, `aria-selected`,
558
+ `aria-pressed`, `aria-current`, `aria-sort`, `aria-invalid` and
559
+ `aria-activedescendant`; HTML's `checked` and `selected` are dropped
560
+ (rrweb records `checked` as a boolean, and its presence is the choice).
561
+ A checkbox's or radio's Input event still says whether it is checked
562
+ (`isChecked`): the replay needs it to click it. A
563
+ URL-named attribute (`href`, `src`, `action`, `data`, `cite` and the
564
+ rest) keeps a value only when it can be a URL -- no space, quote or
565
+ brace -- through the URL rule (path kept, query values replaced), on a
566
+ custom element as on any other; text in one is blanked.
567
+
568
+ What strict still records, so do not put a visitor's text there: URL
569
+ PATHS (`/search/<term>`, a `#/search/<q>` route, a `<link
570
+ rel="canonical">`; only query and fragment-pair values are replaced),
571
+ `id`s and `class`es, `data-testid` (kept as written because the replay
572
+ finds elements by it; an app that builds one from user data,
573
+ `row-${email}`, records it), a field's `name`, SVG geometry (a
574
+ signature pad's strokes are its `d`) and text under `unmaskSelectors`. A comment
575
+ outside `<html>` that changes after the snapshot is recorded as rrweb
576
+ records it. And the replay's look pays for it: CSS keyed on a `data-*`
577
+ (`[data-theme=dark]`, Radix's `data-state=open`) or on a `title` no
578
+ longer matches in a strict recording, and a `<progress>` or `<meter>`
579
+ shows no value; an animated or filtered SVG (SMIL `from`/`to`/`dur`,
580
+ filter `basefrequency`/`tablevalues`) and legacy table attributes
581
+ (`bgcolor`, `cellpadding`) replay without them. MEASURED on keploy.io/docs (Docusaurus), replayed
582
+ with rrweb: the layout, colours, cards and icons render and the text is
583
+ asterisks; the themed logo and the colour-mode toggle's icon are gone,
584
+ because Docusaurus shows them by `[data-theme]` CSS. Blank, not asterisks: the flow engine reads an empty
585
+ `aria-label` as none, so a strict recording never names an element by
586
+ a label it does not have; give a control that has only a label a
587
+ `data-testid`.
588
+
433
589
  `privacy.blockSelectors` names elements whose content is never
434
590
  recorded — a video, a chat widget, a wall of customer names — rrweb
435
591
  records an empty box of the same size in their place.
@@ -454,7 +610,8 @@ count are `navigator.doNotTrack === "1"` -- or as older browsers spell
454
610
  it: `"yes"` (Firefox before 32), `window.doNotTrack === "1"` (Safari,
455
611
  IE 11), `navigator.msDoNotTrack === "1"` (IE 10) -- and
456
612
  `navigator.globalPrivacyControl === true`; `onError` hears every
457
- declined `init()`, and the console line is written once per page.
613
+ declined `init()` but one made while 16 wait for their hand-over (it
614
+ resolves at once, untold), and the console line is written once per page.
458
615
 
459
616
  **On the network.** For every recorded exchange:
460
617
 
@@ -560,7 +717,7 @@ declined `init()`, and the console line is written once per page.
560
717
  `"grant_type=password&password=…"`, `"Location: /cb#access_token=…"`).
561
718
  A credential's value there runs to the next `&` or the string's end,
562
719
  its spaces and line breaks its own (`"password=correct horse battery
563
- staple"` records `"password=[REDACTED]"`, a PEM key goes whole), so
720
+ staple"` records `"password=[REDACTED]"`, a PEM key goes whole), so
564
721
  what follows it before the next `&` goes with it; one that starts
565
722
  where a text body's value cannot -- a space, a quote, a backtick, a
566
723
  bracket, `<`, `>`, `,`, `;` or a backslash -- is code's and is kept
@@ -570,7 +727,7 @@ declined `init()`, and the console line is written once per page.
570
727
  their bytes (`let a=1;token=getToken()`, `SET password=?`, a class's
571
728
  `#token=null`) -- so a pair a string's prose starts after a `;`, a
572
729
  space or a line break (`"user=bob; password=…"`, `"go to
573
- #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
730
+ #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
574
731
  line of a JSON string, a form value or a body that starts with a URL
575
732
  (`https://…?…`, `./cb#…`, `cb?jwt=…`, `/cart;jsessionid=…`), read
576
733
  whole to the line's end — a raw space in a query is its value's, and a
@@ -689,7 +846,25 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
689
846
  so it may lose everything from its first sensitive `=` to the cut;
690
847
  that is the price of never keeping half a credential the cut split.
691
848
  `privacy.maskNetworkBodies: true` replaces every body wholesale with
692
- `[MASKED]` instead (a request that had no body keeps `null`).
849
+ `[MASKED]` instead, decided without the SDK reading it: the page's
850
+ Response is the network's own, never read, cloned or relayed, a body
851
+ passed in `fetch()`'s `init` or to `send()` is decided from its kind
852
+ and size, never serialised or decoded (only a string one is scanned,
853
+ for its `requestTerm`, below), and the body chunk is never loaded.
854
+ One body is still read: a `Request` object's own
855
+ (`fetch(new Request(url, { body }))`, as ky and axios's fetch adapter
856
+ send one) is copied as the page calls `fetch()` and read for its
857
+ `requestTerm` (below) after that call returns, only as far as the
858
+ term needs -- whole when it starts as a JSON object, its first KiB
859
+ otherwise, however the browser hands the copy over (whole, as WebKit
860
+ does a body it holds in memory, in chunks of its own size, as
861
+ Chromium does, or, where a `Request` has no body stream, as in
862
+ Firefox, whole as a Blob), and a
863
+ multipart one is parsed. A body that is absent keeps `null`: a
864
+ request sent with none or an empty one (but an XHR's Blob, which is
865
+ named however small), and a response to a HEAD, a 204, 205 or 304,
866
+ or one whose `Content-Length` is 0. A response that does not declare
867
+ its length is `[MASKED]`, even one that turns out empty.
693
868
  `privacyMode: "strict"` forces that: no body is recorded, and an
694
869
  explicit `privacy.maskNetworkBodies: false` beside it is refused with
695
870
  `KUI_E_PRIVACY_CONFLICT` before anything is recorded — neither option
@@ -701,7 +876,27 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
701
876
  a body that is no GraphQL, or `body:*` for one the SDK could not read
702
877
  or hash. It is computed over the body before redaction and never holds
703
878
  a variable or a literal: it is what replay tells GraphQL calls apart by
704
- (spec/canonical-key.v2.json).
879
+ (spec/canonical-key.v2.json). A `Request` object's own body
880
+ (`fetch(new Request(url, { body }))`) is read for it in a microtask
881
+ queued right after the page's `fetch()` call returns, in every mode:
882
+ never inside the call, and never behind a timer, which a hidden tab
883
+ throttles. One whose `body` is `null` is recorded with none (`null`,
884
+ `""`) at once, whatever its `Content-Type`. Keploy's hosted service
885
+ does not use the term yet: it keys the flows it stores, and so the
886
+ beta tests that replay them, by canonical-key.v1
887
+ (spec/canonical-key.v1.json), with no term: GraphQL calls of one
888
+ method and URL are answered in the order they were recorded, whatever
889
+ operation each runs, and a redacted query value (under strict, every
890
+ one with a value) that v1 keeps in its key stays the literal
891
+ `[REDACTED]` there, matching only itself, never the live value (below).
892
+ - In every mode, the SDK copies no body passed in `fetch()`'s `init` to
893
+ record the call: the `Request` it builds for the call's URL, method
894
+ and headers is given an empty body of the same kind when `init` is a
895
+ plain object (each of its own members kept as it is), so the browser
896
+ copies or encodes nothing the page's own `fetch()` does not. Any other
897
+ `init` (a class's, or another realm's, as from an iframe), and a body
898
+ of another realm (a `FormData`, `URLSearchParams` or buffer from an
899
+ iframe), is passed as it is, and copied once more as before.
705
900
  - One rule reads every URL the SDK records: a request's URL and every
706
901
  URL its request and response headers carry (`Location`,
707
902
  `Content-Location`, `Link` and `Refresh` -- its delay first or not --
@@ -746,8 +941,8 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
746
941
  is recorded as `/search?q=[REDACTED]&page=[REDACTED]`; an empty value
747
942
  and a bare name (`?flag`, recorded as written, whatever it holds) are
748
943
  kept. Replaying such a request needs a replay key that matches a value
749
- redacted at record against any live value (canonical-key.v2, not yet
750
- specified in spec/); with
944
+ redacted at record against any live value (canonical-key.v2,
945
+ spec/canonical-key.v2.json); with
751
946
  it, two requests that differ only in a redacted value
752
947
  (`?session=morning` and `?session=evening`, two `?pin=`s) are one
753
948
  request to the replay, answered in the order they were recorded.
@@ -1113,8 +1308,9 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
1113
1308
  URL is kept; a URL with
1114
1309
  nothing to scrub is recorded exactly as it was, and an event the scrub
1115
1310
  cannot read is dropped rather than sent, as one the credential scrub
1116
- cannot read is. A test holds a 50,000-node page with 20,000 such URLs
1117
- under a second.
1311
+ cannot read is. A unit test scrubs a synthetic tree of 50,000 elements
1312
+ holding 30,000 URLs, 20,000 of them with a query, in under a second of
1313
+ CPU time in Node: a bound the test holds, not a measurement on a page.
1118
1314
  - The page's TEXT -- each text node of the full snapshot and of a node
1119
1315
  added after it, each text change, a value typed under `off`, a
1120
1316
  `srcdoc`'s markup -- has every JWT and provider-prefixed key in it
@@ -1175,57 +1371,242 @@ import { PrivacyEngine } from "@keploy/capture-sdk";
1175
1371
  new PrivacyEngine().maskText("contact user@example.com now"); // "contact [REDACTED] now"
1176
1372
  ```
1177
1373
 
1374
+ `maskNetworkData(event)` masks a network event's headers and URL as the
1375
+ capture does; its BODIES are redacted by the SDK's body code, which is not
1376
+ in the main bundle (it runs in the body worker, see [Your page's own
1377
+ network](#your-pages-own-network)). Called directly, it redacts them once
1378
+ a capture on the page has loaded that code -- which it loads at the
1379
+ capture's start, beside rrweb, when bodies are not masked whole -- and
1380
+ until then
1381
+ records each body `[MASKED]`, never in the clear. Changed in this version: it used to redact them itself, always.
1382
+
1178
1383
  ## Your page's own network
1179
1384
 
1180
1385
  With network capture on, `fetch()` resolves when the response's headers
1181
1386
  arrive, exactly as without the SDK, and the body reaches the page as the
1182
1387
  network delivers it: a streamed response -- SSE over `fetch`, NDJSON, an
1183
- LLM's tokens, a live log view read with `getReader()` -- streams. The SDK
1184
- reads each body once, as its only reader, and hands every chunk on to
1185
- the page; it reads ahead of the page only until it has the recording
1186
- (the whole body, or `maxBodySize` of it), so a body the page reads slowly
1187
- is not buffered for it, and a page that cancels (`reader.cancel()`, a
1188
- `for await` `break`, an aborted pipe) or aborts (`AbortSignal`) stops
1189
- the download at once. A body the page never reads is still recorded. A
1190
- page that stops reading before the body has ended (and before
1191
- `maxBodySize`) is recorded with exactly what it read; once the SDK has
1192
- the whole body, the whole body is what is recorded. A body that fails
1193
- part-way -- an abort, a dropped connection, a navigation (Firefox and
1194
- WebKit abort a page's fetches as it leaves) -- is recorded with what had
1195
- arrived, cut and marked `...[truncated]`; the SDK may have read that far
1196
- ahead of the page. Each of these, whole or cut, is redacted exactly as
1197
- any other recorded body is.
1198
-
1199
- The page has its body first. The SDK redacts and records an exchange in
1200
- a task of its own, after the page's stream has ended and its Response
1201
- resolved (in an idle period where the browser has
1202
- `requestIdleCallback`, at most a second later), never inside the relay.
1203
- In Firefox a page's `text()` or `json()` can still resolve just after
1204
- the redaction, which Firefox finishes through tasks of its own; moving
1205
- the redaction into a Web Worker, next, removes that. MEASURED before
1206
- this: 50 parallel 64 KB JSON fetches took 32 ms without the SDK and
1388
+ LLM's tokens, a live log view read with `getReader()` -- streams. The
1389
+ page gets the network's own `Response`, and the SDK reads nothing until
1390
+ the page reads (none when bodies are masked whole):
1391
+
1392
+ - read whole -- `text()`, `json()`, `arrayBuffer()`, `bytes()`,
1393
+ `blob()` -- the browser's own method answers (`json()` is its
1394
+ `text()`, parsed by `JSON.parse`). The SDK records what your app gets:
1395
+ the text or bytes before your app's own code after the read runs, a
1396
+ `Blob` read back from that same `Blob`. Bytes are decoded only as far
1397
+ as `maxBodySize` needs. `formData()`, whose result is not the body's
1398
+ text, and a `json()` your app put on `Response.prototype` (a reviver,
1399
+ a lossless parser), which answers as your app's own, are recorded from
1400
+ a clone taken just before, read only as far as `maxBodySize` needs and
1401
+ then cancelled: the SDK holds no more of the body than that while your
1402
+ app reads the rest. A clone's read (`res.clone().text()`, as ky does)
1403
+ records the same way; the first read to complete is the recording. No
1404
+ JavaScript stream reader touches the body your app reads, so the
1405
+ request ends as it does without the SDK: in Chromium a load whose body
1406
+ a stream reader takes to its end before the load completes is
1407
+ reported `net::ERR_ABORTED`, though the page has every byte.
1408
+ - read through `body` -- the SDK reads the network once for each read
1409
+ of the page's, nothing ahead, so a body the page reads slowly is not
1410
+ buffered for it, and a page that cancels (`reader.cancel()`, a
1411
+ `for await` `break`, an aborted pipe) or aborts (`AbortSignal`) stops
1412
+ the download at once. A page that stops reading before the body has
1413
+ ended (and before `maxBodySize`) is recorded with exactly what it
1414
+ read. A clone's `body` is the browser's own, never relayed nor
1415
+ recorded: monitoring tools (Datadog RUM, Sentry) read a clone of every
1416
+ response through its stream, and the recording stays your app's own
1417
+ read. A body your app reads only through a clone's `body` is recorded
1418
+ as not read. This relay is part of the body code's chunk, which
1419
+ `init()` asks for at once: a `body` your app takes before that chunk
1420
+ has arrived (or while the page is leaving) is the browser's own
1421
+ stream, handed over at once -- the SDK never makes a read wait for a
1422
+ chunk. Taking it records nothing: an app that only looks at `body`
1423
+ and then reads whole (ofetch, Nuxt's `$fetch`: `response.body ||`,
1424
+ then `text()`) is recorded as ever. One that reads nothing of it whole
1425
+ is recorded with its body as not captured (below, with `N` 0, the SDK
1426
+ having seen none of it, and its own reason, `early`). `body` is the
1427
+ stream the browser has for the response at each look: after `clone()`
1428
+ it is the new one, as without the SDK. Bodies read whole need no chunk.
1429
+ - never read -- the SDK never reads it either. It is recorded as
1430
+ `[Response body not read by the page]`, with its status and headers,
1431
+ once the page's `Response`, its clones and its `body` stream are
1432
+ collected (Chromium aborts that load then), or when the tab is hidden,
1433
+ the page leaves, the capture pauses or `stop()` ends; replay sends
1434
+ that text as the body. A tab may be discarded once hidden (mobile
1435
+ browsers do) with no further event, so a body first read after the
1436
+ tab is shown again stays recorded as not read. A body a browser API
1437
+ reads past JavaScript (`cache.put(req, res)`,
1438
+ `WebAssembly.instantiateStreaming(res)`) is read by the browser
1439
+ itself, untouched, and recorded as not read too. Changed in this
1440
+ version: such a body used to be read and recorded whole.
1441
+
1442
+ A body that fails part-way -- an abort, a dropped connection, a
1443
+ navigation (Firefox and WebKit abort a page's fetches as it leaves) --
1444
+ is recorded with what had arrived, cut and marked `...[truncated]`
1445
+ (nothing of it, for a body the page was reading whole). Each of these,
1446
+ whole or cut, is redacted exactly as any other recorded body is.
1447
+
1448
+ The page has its body first. The SDK hands each body to a Web Worker,
1449
+ which redacts it off your page's main thread. It does so in a task of
1450
+ its own, after the page's stream has ended and its Response resolved
1451
+ (in an idle period where the browser has `requestIdleCallback`, at most
1452
+ a second later), never inside the relay: the page's thread copies the
1453
+ body over there (0.04 to 0.14 ms for 64 to 256 KB, MEASURED) and, in
1454
+ another idle period after the relay is over, records the answer. A
1455
+ browser with no idle periods (Safari) copies the body inside the relay
1456
+ instead, as the SDK reads its end or its cap -- while the page may still
1457
+ be reading the rest of a body past the cap -- since a task of its own
1458
+ would fall inside the page's work all the same. So a burst of responses or a
1459
+ run of large POSTs costs it no redaction, and nothing the SDK does can
1460
+ interleave with a page's `text()`. MEASURED before the page-first
1461
+ change: 50 parallel 64 KB JSON fetches took 32 ms without the SDK and
1207
1462
  382 ms with it in Chromium. The exchange keeps its time and its place
1208
- in the recording; `stop()`, `pause()`, the session's end and the page
1209
- leaving record at once any exchange whose task has not run yet, and a
1210
- hidden tab does before its last upload.
1211
-
1212
- The Response your page gets is one the SDK built around that body. Its
1213
- `url`, `redirected`, `type`, `headers` and `clone()` answer as the
1214
- network's do, and `instanceof Response`, `bodyUsed` and BYOB readers
1215
- behave as usual. Three things differ:
1216
-
1217
- - A **Cache API** round trip (`cache.put()`, then `cache.match()`) keeps
1218
- the body, status and headers but not the network's `url` and `type`:
1219
- they come back `""` and `"default"`. That is the platform's limit, not
1220
- a choice: the Cache API stores a Response's internal URL list and type,
1221
- which a Response built in JavaScript cannot be given, and a clone --
1222
- the only way to keep the network's own object -- cannot keep the
1223
- page's backpressure in Chromium. MEASURED in Chromium, the same page
1224
- with and without the SDK: every other member equal, these two not.
1225
- `WebAssembly.instantiateStreaming()` likewise does not see the
1226
- response's URL (it still compiles).
1463
+ in the recording. What the SDK holds for redaction is bounded, across
1464
+ every worker the page makes, from the moment it takes a body: waiting for
1465
+ its idle task, for the worker's start, for the body chunk on a page with no
1466
+ worker, or for the worker's answer. Each copy counts -- the SDK's own, and
1467
+ the one posted to the worker, which the browser keeps until the worker
1468
+ answers -- with 1,024 UTF-16 units more each. The SDK takes an exchange
1469
+ only while the copies come to under 8 Mi units (16 MiB of strings,
1470
+ beside the 16 MiB cap on the events it holds unsent): with one body of the
1471
+ default `maxBodySize` each, 8 exchanges posted to the worker, or 16 waiting
1472
+ for its start or their idle task. Its own copies come to at most 8 Mi units
1473
+ and one exchange, and with the copies posted to the worker at most twice
1474
+ that, 16 Mi units and two exchanges; they come nearest that ceiling when
1475
+ everything the SDK holds is posted before the worker answers (for example
1476
+ the exchanges that waited for its start, as it lands). An exchange that
1477
+ comes once the copies are at 8 Mi units or more -- a burst before your
1478
+ page is idle, a chunk or the
1479
+ worker's script not yet arrived, or a worker behind your page -- leaves
1480
+ none of its bodies in the SDK's events or jobs: the SDK drops the
1481
+ exchange's job as it comes, and records it in its own task, as any
1482
+ exchange, with the cut note and nothing kept,
1483
+ `[Body cut: 0 of N characters kept, unverified]`,
1484
+ which replay never serves as a body, with no redaction and nothing logged.
1485
+ So a healthy page can lose bodies this way: with the default `maxBodySize`,
1486
+ past 16 exchanges in a burst before it is idle, or past 8 a slower worker
1487
+ has not answered. An exchange is taken whatever its size when nothing else
1488
+ is held. The page leaving and `stop()`'s one-second bound
1489
+ record at once every body still in the worker, on the main thread up to
1490
+ 64 KiB in all and cut past it -- with the main thread's chunk, which
1491
+ `init()` asks for at once, beside rrweb, for a capture that redacts
1492
+ bodies. Neither moment can wait for it,
1493
+ so a body they find before it has arrived (it arrives once its fetch is
1494
+ over; offline, once the browser is back) is recorded as not captured, and
1495
+ never in the clear: the cut note with nothing kept, then a second line
1496
+ that says why. A page whose chunk could not load at all (a CSP that
1497
+ refuses it, a 404 after a deploy, `dist/index.mjs` served alone) records
1498
+ each body the main thread must redact the same way, with its own reason
1499
+ (and logs `KUI_E_BODY_WORKER_UNAVAILABLE` once per page):
1500
+
1501
+ ```
1502
+ [Body cut: 0 of N characters kept, unverified]
1503
+ [Body not captured: the page left or the capture stopped before redaction was ready]
1504
+
1505
+ [Body cut: 0 of N characters kept, unverified]
1506
+ [Body not captured: the redaction code could not load]
1507
+ ```
1508
+
1509
+ A body your app took through `res.body` before the body code had loaded,
1510
+ and that nothing read whole (see above), says so, with `N` 0:
1511
+
1512
+ ```
1513
+ [Body cut: 0 of 0 characters kept, unverified]
1514
+ [Body not captured: the page took the body's stream before the redaction code had loaded]
1515
+ ```
1516
+
1517
+ (`notCapturedBodyNote(N, why)` in `@keploy/contract/privacy`, `why`
1518
+ being `"left"`, `"code-failed"` or `"early"`, and
1519
+ `isNotCapturedBody(body, why?)`, which tells each from a body cut at the
1520
+ budget, and one cause from another). Replay never serves it, as any cut
1521
+ body.
1522
+
1523
+ A page that is leaving starts none of the SDK's own loads (its chunks,
1524
+ rrweb's import and the body worker), and a load its leave refused or
1525
+ cancelled is held, not judged failed: a body the page leaves on is
1526
+ recorded with the first reason, and nothing is logged. A single-page
1527
+ app's route the Navigation API intercepted is no leave: a task after
1528
+ each `navigate`, the SDK judges it by what became of it in this
1529
+ document -- the app cancelled it, it committed here
1530
+ (`currententrychange`; an intercepted navigate commits as its dispatch
1531
+ ends, before its handler runs), or its transition is still under way (a
1532
+ commit the app deferred) -- never by `navigation.transition` alone,
1533
+ which a route whose handler has already settled no longer has. The leave ends only
1534
+ on something a navigation still on its way cannot produce: Chromium's
1535
+ abort of the leaving navigation when no navigate came after it (an
1536
+ "unsaved changes" prompt the visitor cancelled; a link clicked twice,
1537
+ Enter pressed twice and the page's own `history.replaceState` in its
1538
+ `beforeunload` abort it too, each followed by a navigate, so none ends
1539
+ it), `pageshow` from the back/forward cache, or a capture start by the
1540
+ page's script (never a continuous capture's next session, which the
1541
+ visitor's input starts).
1542
+ The SDK then asks once more for what it held -- a worker whose script had
1543
+ not run yet included (Firefox cancels that load and says nothing; the
1544
+ worker says it runs as its first act). Neither `navigatesuccess` nor the
1545
+ visitor's input ends it: the page's own `pushState` or `replaceState`
1546
+ fires a `navigatesuccess` while a real navigation still loads, and the
1547
+ old page gets every click and key then, also after a prompt the visitor
1548
+ accepted. An app's route that comes after a navigation has begun ends no
1549
+ leave either. So a prompt cancelled in Firefox or WebKit, a download, a
1550
+ 204 and a `mailto:` link in Chromium keep the page leaving until a
1551
+ `pageshow` from the back/forward cache or a capture start by the page's
1552
+ script, its bodies recorded with the first reason and nothing logged.
1553
+ While the page leaves, a body of the leave (its exchange answered after
1554
+ the leave began) goes to the worker only if one runs: with none
1555
+ running, it is recorded with the first reason at once and its string
1556
+ dropped, so no body waits on a load the leave holds, and none
1557
+ goes to the main thread's budget because of a leave (a page with no
1558
+ worker at all redacts there as ever). A body the page was still reading
1559
+ (a fetch or an XHR whose headers had arrived), or already waiting for the
1560
+ worker's start, as the leave began is
1561
+ recorded when it can wait no longer -- so one the leave cut (Firefox
1562
+ and WebKit abort a page's fetches as it navigates, before `pagehide`)
1563
+ is recorded cut where the page left, and an XHR the leave aborts as the
1564
+ browser leaves it, status 0 and no response body (XMLHttpRequest drops
1565
+ what had arrived), its request body redacted -- on the main thread once the body code is there: a hidden tab
1566
+ records only those that fit whole, and its session's end or the page
1567
+ leaving the rest, within 64 KiB shared by all of them (those that fit
1568
+ whole first, the rest cut to what is left); with the first reason
1569
+ while the code is not there. A continuous capture's later sessions are
1570
+ no exception: the visitor's input starts each, so none ends that
1571
+ leave. A worker running as the page leaves is kept across their ends
1572
+ and redacts their bodies as ever; a session live or waiting as the
1573
+ leave ends takes it over, and it goes when no capture is live and none
1574
+ waits (the leave's end or `stop()`), at `pagehide` whatever waits (a page
1575
+ entering the back/forward cache keeps no thread; a body after a persisted
1576
+ `pageshow` starts one again), or at a session's end outside a leave, as
1577
+ ever. Without one, their bodies are recorded with
1578
+ the first reason until the leave ends. A body's strings go as it is
1579
+ recorded, so nothing the SDK holds grows with the sessions. Nothing is
1580
+ logged. `init()` never
1581
+ waits on a held load: when a leave holds rrweb's import, `init()`
1582
+ resolves once the capture is set up, and rrweb records from when its
1583
+ import lands after the leave ends; until then no DOM events are recorded,
1584
+ and nothing is logged. The same holds for a continuous capture's session
1585
+ the visitor's input starts while the page is leaving: it opens at once.
1586
+ And no GraphQL request waits on a held load: one whose term code has not
1587
+ loaded is recorded with the term `body:*` at once while the page is
1588
+ leaving, and nothing is logged; once the leave ends the code is asked
1589
+ for, and later requests carry their term. A navigate the app intercepts
1590
+ (a single-page app's route) is no leave: a request the route sends as it
1591
+ begins waits the one task it takes to know that, and has its term.
1592
+
1593
+ The browser coming back online (before
1594
+ the upload that ends an outage, when the body code had loaded before
1595
+ it went offline: nothing is fetched offline, so a page that went
1596
+ offline before its first body records it once back online), a hidden tab before its last upload
1597
+ and `stop()` record at once what fits in that budget and leave the rest
1598
+ to the worker; `pause()` cuts a body still arriving and records it when
1599
+ the worker answers.
1600
+
1601
+ The Response your page gets is the network's own: its `url`,
1602
+ `redirected`, `type`, `headers`, `instanceof Response`, `bodyUsed` and
1603
+ BYOB readers are the browser's, and a Cache API round trip stores the
1604
+ network's response exactly as without the SDK. The SDK answers its body
1605
+ readers, `body` and `clone()` with non-enumerable members of its own on
1606
+ that one object. One thing differs:
1607
+
1227
1608
  - A **streamed upload built into a `Request`** (`new Request(url, { body:
1228
- stream, duplex: "half" })`) that the server answers early is pulled
1609
+ stream, duplex: "half" })`) that the server answers early is pulled
1229
1610
  further than without the SDK -- up to the chunk that crosses
1230
1611
  `3 x maxBodySize + 4` bytes (about `maxBodySize` bytes for ASCII). The
1231
1612
  SDK records a Request's body from a copy of it, and that copy reads the
@@ -1241,18 +1622,13 @@ behave as usual. Three things differ:
1241
1622
  without the SDK, 10 with it at the default cap. A stream passed as
1242
1623
  `init.body` is not read at all (recorded `[ReadableStream]`) and is
1243
1624
  pulled exactly as without the SDK; only Chromium streams request bodies.
1244
- - A **`fetch` wrapper installed before the SDK** that reads or clones the
1245
- network's Response later than the moment it hands it on finds its body
1246
- already taken by the SDK. Wrappers that clone at once (most APM and
1247
- error-tracking SDKs) are unaffected; initialise this SDK first if
1248
- yours does not.
1249
-
1250
- `KeployCapture.stop()` waits up to one second for exchanges already
1251
- answered to finish their bodies, and records any still open then (an
1252
- endless stream) cut at that point and marked `...[truncated]` -- as it
1253
- does for exchanges still open when the page leaves. `KeployCapture.pause()`
1254
- cuts them the same way at once, with no wait: a pause records nothing
1255
- more.
1625
+ `KeployCapture.stop()` waits up to one second for exchanges already
1626
+ answered to finish their bodies, and records any still open then (an
1627
+ endless stream) cut at that point and marked `...[truncated]` -- as it
1628
+ does for exchanges still open when the page leaves; one whose body the
1629
+ page has not read is recorded as `[Response body not read by the page]`.
1630
+ `KeployCapture.pause()` records them the same way at once, with no wait:
1631
+ a pause records nothing more.
1256
1632
 
1257
1633
  ## What a large body looks like
1258
1634
 
@@ -1280,7 +1656,7 @@ Over the bound, there are three answers, not one:
1280
1656
  a size it is the figure the SDK had, not always a measurement —
1281
1657
  `[Response body too large: N bytes]` repeats the server's
1282
1658
  `Content-Length` for a body it never downloaded. So a note is not a
1283
- way to size a body against `maxBodySize`. There are seven, one for
1659
+ way to size a body against `maxBodySize`. There are eight, one for
1284
1660
  each way a body can be one the SDK does not read:
1285
1661
  - `[Blob: N bytes, truncated]` — a `fetch` Blob over the bound.
1286
1662
  - `[Blob: N bytes]` — any Blob sent through `XMLHttpRequest`, which
@@ -1291,6 +1667,10 @@ Over the bound, there are three answers, not one:
1291
1667
  text.
1292
1668
  - `[Response body too large: N bytes]` — from a `Content-Length` over
1293
1669
  the bound, so the body is never downloaded.
1670
+ - `[Response body not read by the page]` — a response body your app
1671
+ never read, so the SDK never reads it either (see "Your page's own
1672
+ network"). Replay sends this text as the body, with the recorded
1673
+ status and headers. No size: nothing of it was read.
1294
1674
  - `[ReadableStream]` — a streaming request body, which reading would
1295
1675
  consume out from under your app. No size: measuring a stream means
1296
1676
  consuming it too.
@@ -1307,6 +1687,22 @@ A file inside `FormData` is not one of these: the body is still
1307
1687
  recorded, and that field's value is `[File: name, N bytes]`, URL-encoded
1308
1688
  with the rest of the form. The file's bytes are never read.
1309
1689
 
1690
+ **Where the page has no body worker** (see [Install](#install)), a
1691
+ body is redacted on the page's main thread, and only up to 64 KiB of
1692
+ it: a body over that is recorded cut, its first 64 KiB redacted as
1693
+ above under a first line that says so, `[Body cut: 65536 of N
1694
+ characters kept, unverified]`. The same note marks a body still in the
1695
+ worker when the page leaves, past the 64 KiB the page's last moment
1696
+ redacts (0 kept when nothing was left), and, with nothing kept and a
1697
+ second line saying why, a body the SDK did not capture: the page left
1698
+ before the body chunk had arrived, the chunk could not load, or the
1699
+ page took the body's stream before the chunk had arrived and nothing
1700
+ read it whole (see
1701
+ [Your page's own network](#your-pages-own-network)).
1702
+ It is not the response the server sent, and replay never serves it as
1703
+ one: the request is answered as a failed one and a test that reaches it
1704
+ is reported `unproven`.
1705
+
1310
1706
  Lower `maxBodySize` to save bandwidth and you will get the second
1311
1707
  answer for most large JSON, not a shorter body. If you need the shape
1312
1708
  of a large response more than its contents, that is the trade.
@@ -1345,7 +1741,7 @@ than thrown back into the code that emitted it; so is an event that
1345
1741
  alone is over the ingest server's 10 MiB body cap (an rrweb snapshot
1346
1742
  of a very large page, a captured body under a raised `maxBodySize`),
1347
1743
  which no batch could carry. The first of each kind in a capture logs a
1348
- `console.error`; any after it are dropped silently, because an emitter in a render loop
1744
+ `console.warn`; any after it are dropped silently, because an emitter in a render loop
1349
1745
  would otherwise write a line every few milliseconds into the page the
1350
1746
  SDK is there to record. `onError` is not called — that is reserved
1351
1747
  for a condition that ENDS the capture, and this session goes on
@@ -1407,7 +1803,11 @@ says so once per capture, naming the method:
1407
1803
  `bytes`, `cap`), `KUI_E_EVENT_OVERSIZED_SCRUBBING` (evidence
1408
1804
  `eventType`, `atLeast`, `cap` -- no id: the event never reached the
1409
1805
  queue), `KUI_E_NAVIGATION_UNWRAPPED` (evidence `method`) and
1410
- `KUI_E_REQUEST_TERM_FAILED` (evidence `method`, `reason`; below) are
1806
+ `KUI_E_REQUEST_TERM_FAILED` (evidence `method`, `reason`; below) and
1807
+ `KUI_E_BODY_WORKER_UNAVAILABLE` (below) are written with `console.warn`, never `console.error`: the capture goes on,
1808
+ and a page whose tests or error tracker fail on `console.error` must
1809
+ not fail on one. `console.error` is kept for a capture that ENDS (an
1810
+ `init()` refused, a server rejection, both below). They are
1411
1811
  warning-severity entries of the same error corpus as the codes above, and `SDK_WARNINGS` carries a short summary of each and the
1412
1812
  link to its corpus page, where the remedy is; a program that only has the console
1413
1813
  can match the token and parse the JSON after the first `evidence=`
@@ -1428,7 +1828,9 @@ page that sends none never loads it; your bundler resolves it as it
1428
1828
  resolves rrweb. Where it does not load (a Content-Security-Policy, offline,
1429
1829
  a 404), each such request is recorded `body:*`, as a page with no
1430
1830
  SubtleCrypto records it, and the load is not retried for the life of the
1431
- page. At replay `body:*` matches a live request of the same method and
1831
+ page. While the page is leaving, a request is recorded `body:*` the same
1832
+ way if the code has not loaded, without the warning; a load the leave
1833
+ held, not yet failed, is asked for when the leave ends. At replay `body:*` matches a live request of the same method and
1432
1834
  URL whatever its term; a recorded key equal to the live one is chosen
1433
1835
  first. The first
1434
1836
  such request in a capture logs
@@ -1439,6 +1841,24 @@ entry of the same corpus, on one line of the same shape:
1439
1841
  [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"}
1440
1842
  ```
1441
1843
 
1844
+ A page that cannot run the SDK's body worker or load its body chunk (see
1845
+ [Install](#install): a Content-Security-Policy that refuses the worker,
1846
+ webpack 4, esbuild without the file copied, a build served from another
1847
+ origin or from a CDN, a page without a bundler that serves
1848
+ `dist/index.mjs` alone) still records every
1849
+ exchange: without the worker it redacts bodies on the main thread and
1850
+ records a body over 64 KiB cut; without the body chunk too, a body the
1851
+ main thread must redact is recorded as not captured, with nothing kept,
1852
+ under `[Body not captured: the redaction code could not load]`. Replay
1853
+ reports a test over a cut or not-captured body `unproven`. It
1854
+ logs `KUI_E_BODY_WORKER_UNAVAILABLE` (evidence `part`: `worker` or
1855
+ `code`, and `reason`: what the browser said), a warning entry of the same
1856
+ corpus, once per page for each part, at its first failure:
1857
+
1858
+ ```
1859
+ [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)"}
1860
+ ```
1861
+
1442
1862
  ### The last batch
1443
1863
 
1444
1864
  When the page unloads — a navigation, a tab close — whatever is still
@@ -1446,8 +1866,22 @@ queued is sent in one `keepalive` request from the `pagehide` handler.
1446
1866
  Browsers cap the sum of a document's in-flight keepalive bodies at
1447
1867
  64 KiB (MEASURED in Chromium 145: 65,536 bytes accepted, 65,537
1448
1868
  refused), and a request over that is refused before it leaves, losing
1449
- everything in it. So that last request is cut at the first event that
1450
- does not fit, oldest first, and what does not fit stays behind — an
1869
+ everything in it. That quota is the PAGE's as well: a lead form's
1870
+ keepalive POST or an analytics `sendBeacon` is refused while the SDK
1871
+ holds it (MEASURED with a 63 KB upload on the wire: the page's 2 KB
1872
+ beacon refused in Chromium and WebKit, its keepalive fetch in WebKit).
1873
+ So the SDK keeps its own keepalive bodies in flight to half of it,
1874
+ 32 KiB, counting what is still on the wire, and leaves the page the
1875
+ rest. An upload over 32 KiB gzipped goes without `keepalive`, so a
1876
+ navigation before it completes cancels it (a tab close does not). A
1877
+ queue past what the pagehide request can carry is sent at once, as a
1878
+ plain fetch -- never `keepalive`, so the pagehide request keeps the
1879
+ SDK's whole share -- one upload at a time, ending once the queue is back
1880
+ under. Events queued behind an upload still on the wire when the visitor
1881
+ leaves go in the pagehide request, up to 32 KiB; the upload on the wire
1882
+ is cancelled by the navigation (a tab close lets it finish). The
1883
+ pagehide request is cut at 32 KiB, at the first event that does not fit,
1884
+ oldest first, and what does not fit stays behind — an
1451
1885
  event held back is one whose node ids the events after it depend on,
1452
1886
  so shipping past it would be worse than stopping there.
1453
1887
 
@@ -1460,7 +1894,7 @@ sees the session in order.
1460
1894
  What is **not**: a request already on the wire when the document dies.
1461
1895
  A keepalive request survives the document, so it usually arrives — but
1462
1896
  if it does not, the SDK cannot know and cannot resend it. And an event
1463
- whose JSON, with the envelope that wraps it, exceeds the 64 KiB cap
1897
+ whose JSON, with the envelope that wraps it, exceeds the SDK's 32 KiB
1464
1898
  cannot travel this way at all; the SDK posts such an event the moment
1465
1899
  it is queued rather than leaving it to be cut here — but not while the
1466
1900
  browser reports itself offline (`navigator.onLine`, read each time: the
@@ -1496,19 +1930,20 @@ rather than handing back the one that failed.
1496
1930
  The `CaptureError` is for the program, not just the person reading the
1497
1931
  console. Branch on `code`, never on the message:
1498
1932
 
1499
- | `code` | the server answered | what to do (in short; see `remedy.docs`) |
1500
- | --------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1501
- | `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` |
1502
- | `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 |
1503
- | `KUI_E_SESSION_CONFLICT` | 409 | this session id is already claimed — give each run its own, usually by removing a fixed-value `sessionIdGenerator` |
1504
- | `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 |
1505
- | `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 |
1506
- | `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 |
1507
- | `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 |
1508
- | `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 |
1509
- | `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 |
1510
-
1511
- `onError` receives one of six subclasses of `CaptureError`, and
1933
+ | `code` | the server answered | what to do (in short; see `remedy.docs`) |
1934
+ | ------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1935
+ | `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` |
1936
+ | `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 |
1937
+ | `KUI_E_SESSION_CONFLICT` | 409 | this session id is already claimed — give each run its own, usually by removing a fixed-value `sessionIdGenerator` |
1938
+ | `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 |
1939
+ | `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 |
1940
+ | `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 |
1941
+ | `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 |
1942
+ | `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 |
1943
+ | `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 |
1944
+ | `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 |
1945
+
1946
+ `onError` receives one of seven subclasses of `CaptureError`, and
1512
1947
  branching on `code` narrows to it, so a TypeScript handler can read the
1513
1948
  evidence the remedy names. An `IngestRejection` (the four
1514
1949
  server-answered codes) carries `status`, `serverMessage` (the `error`
@@ -1529,6 +1964,9 @@ is sent, so its `status` is `null` and its evidence is
1529
1964
  and the rule. A `DomRecorderRefusal` (`KUI_E_DOM_RECORDER_UNAVAILABLE`)
1530
1965
  is raised in a browser, before anything is sent, when rrweb cannot be
1531
1966
  imported; its evidence is `{ reason }`, the browser's error. A
1967
+ `StrictAttributesRefusal` (`KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE`) is
1968
+ raised the same way under `strict` when its attribute allow-list cannot
1969
+ be imported, with the same `{ reason }`. A
1532
1970
  `PrivacyRouteRefusal` (`KUI_E_PRIVACY_ROUTE_INVALID`) is raised before
1533
1971
  anything is sent when a declared privacy route is no route; its evidence
1534
1972
  is `{ option, received, rule }`. A `CaptureDeclined`
@@ -1538,7 +1976,7 @@ its evidence is `{ signal }` — `doNotTrack` or `globalPrivacyControl`.
1538
1976
  A `PrivacyConflict` (`KUI_E_PRIVACY_CONFLICT`) is the site's own config
1539
1977
  contradicting itself: its `status` is `null` and its evidence is
1540
1978
  `{ privacyMode, option }` — `"strict"` and the option that asks for
1541
- what strict leaves out. The nine
1979
+ what strict leaves out. The ten
1542
1980
  codes and their evidence are the entries of the same name in
1543
1981
  `@keploy/contract`'s error corpus. The SDK carries each entry's code, a
1544
1982
  short summary of what happened and the link to the entry's page, and
@@ -1546,27 +1984,62 @@ no remedy text, which stays on that page; a test holds the summary, the
1546
1984
  link and the evidence to the corpus. The `docs` pages are published
1547
1985
  with the same docs release as the guide above, and answer 404 until
1548
1986
  then. The status-to-code mapping is
1549
- `spec/sdk-errors.v3.json`; the session-id rule is
1987
+ `spec/sdk-errors.v5.json`; the session-id rule is
1550
1988
  `spec/session-id.v1.json`, the api-server's rule stated once — the
1551
1989
  SDK and the sidecar execute the file today, and the api-server's own
1552
1990
  executor lands with its next vendoring of the corpus. `onError` runs
1553
1991
  after the capture has ended and the singleton is released, so a handler
1554
- may call `init()` again and get a fresh capture:
1992
+ may call `init()` again and get a fresh capture -- once it has changed
1993
+ what was refused. A declined visitor, a conflicting config and an
1994
+ invalid route are refused again by the next `init()` given the same
1995
+ config; a session-id generator runs again on each `init()`, and a chunk
1996
+ that failed to load is asked for again (a browser may keep the failure
1997
+ until the page is reloaded), so each is refused again until what failed
1998
+ has changed. A refusal raised while `init()` runs
1999
+ reaches `onError` in a task of its own (a `setTimeout`), never inside that
2000
+ `init()` call, and `init()` resolves once the handler has run. A
2001
+ refused `init()` is told, in the order the refusals of its code came, but
2002
+ repeated identical refusals are paced and bounded: a code has at most one
2003
+ hand-over waiting, which tells the refusals of that code made while it
2004
+ waited, at most 16 of them -- a refusal that comes while 16 wait resolves
2005
+ its `init()` at once without calling `onError`, and nothing of it is
2006
+ kept; a hand-over that follows the code's last one closely waits twice as
2007
+ long as the one before, from 50 ms up to 30 s, so no refused `init()` is
2008
+ scheduled more than 30 s out, however often the page calls it; and a code
2009
+ quiet for that wait plus a second is handed over in the next task again.
2010
+ So a handler that re-inits the same config for every code, even twice for
2011
+ each refusal, neither recurses, freezes nor loads the page: it goes round
2012
+ 11 times in its first minute, then twice a minute, at most 16 handlers a
2013
+ round. A page that clears timers it does not own, or a test that leaves
2014
+ fake timers, can drop a hand-over's timer, so each refusal reads the
2015
+ clock once (`performance.now()`): the next refusal of that code more
2016
+ than 31 s past its due time hands over what waits in the next task, and
2017
+ until one comes what waits stays unresolved. The
2018
+ console line of a refusal raised while `init()` runs is
2019
+ written once per page per code. Re-init only after changing what was
2020
+ refused:
1555
2021
 
1556
2022
  ```ts
1557
- import { KeployCapture } from "@keploy/capture-sdk";
2023
+ import { KeployCapture, type CaptureConfig } from "@keploy/capture-sdk";
1558
2024
 
1559
- await KeployCapture.init({
2025
+ const config: CaptureConfig = {
1560
2026
  endpoint,
1561
2027
  apiKey,
2028
+ sessionIdGenerator: mySessionId,
1562
2029
  onError: (err) => {
1563
2030
  // The person using the page said no (Do Not Track or Global Privacy
1564
2031
  // Control). Not a failure: keep it out of your error tracker --
1565
2032
  // Brave and DuckDuckGo send GPC by default.
1566
2033
  if (err.code === "KUI_E_CAPTURE_DECLINED") return;
1567
- if (err.code === "KUI_E_SESSION_ID_INVALID")
1568
- fixGenerator(err.evidence.received);
1569
- else if (err.code === "KUI_E_DOM_RECORDER_UNAVAILABLE")
2034
+ if (err.code === "KUI_E_SESSION_ID_INVALID") {
2035
+ report(err.code, err.evidence.received);
2036
+ // Changed what was refused, so a re-init can succeed: the SDK's ids.
2037
+ delete config.sessionIdGenerator;
2038
+ void KeployCapture.init(config);
2039
+ } else if (
2040
+ err.code === "KUI_E_DOM_RECORDER_UNAVAILABLE" ||
2041
+ err.code === "KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE"
2042
+ )
1570
2043
  report(err.code, err.evidence.reason);
1571
2044
  else if (err.code === "KUI_E_PRIVACY_ROUTE_INVALID")
1572
2045
  report(err.code, err.evidence.option, err.evidence.received);
@@ -1576,7 +2049,8 @@ await KeployCapture.init({
1576
2049
  else
1577
2050
  report(err.code, err.serverMessage, err.evidence.issues, err.remedy.docs);
1578
2051
  },
1579
- });
2052
+ };
2053
+ await KeployCapture.init(config);
1580
2054
  ```
1581
2055
 
1582
2056
  A `429`, a `5xx` or a network failure gets three attempts: up to 1 s
@@ -1601,7 +2075,9 @@ is dropped (a batch that failed and goes back to the queue past
1601
2075
  record time and replay time cannot disagree.
1602
2076
  - **No `Math.random` fallback for the session nonce**, so a recording
1603
2077
  is either joinable or says why it is not.
1604
- - **No sampling by user.** `sampleRate` is decided per session start.
2078
+ - **No sampling by user.** `sampleRate` is rolled when `init()` starts a
2079
+ capture, so once per page load (again only after `stop()` or the
2080
+ session's end), never per visitor across loads.
1605
2081
  - **No guessing which generic field holds a secret.** A name/value pair
1606
2082
  is read by its `key`, `name` or `header`; a pair spelled otherwise
1607
2083
  (`{field, val}`), or one whose name is not a secret's own (an