@keploy/capture-sdk 3.1.0-rc.2 → 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.
- package/README.md +235 -99
- package/dist/body-jobs.d.ts +106 -10
- package/dist/body-redact.d.ts +6 -0
- package/dist/body-redact.js +1 -1
- package/dist/body-redact.js.map +1 -1
- package/dist/body-redact.mjs +1 -1
- package/dist/body-redact.mjs.map +1 -1
- package/dist/body-worker-none.js +1 -1
- package/dist/body-worker-none.js.map +1 -1
- package/dist/body-worker-none.mjs +1 -1
- package/dist/body-worker-none.mjs.map +1 -1
- package/dist/body-worker-start.js +1 -1
- package/dist/body-worker-start.js.map +1 -1
- package/dist/body-worker-start.mjs +1 -1
- package/dist/body-worker-start.mjs.map +1 -1
- package/dist/body-worker-unbundled.mjs +1 -1
- package/dist/body-worker-unbundled.mjs.map +1 -1
- package/dist/body-worker.js +1 -1
- package/dist/body-worker.js.map +1 -1
- package/dist/index.bundler.mjs +1 -1
- package/dist/index.bundler.mjs.map +1 -1
- package/dist/index.d.ts +73 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/module-of.d.ts +17 -0
- package/dist/network.d.ts +39 -27
- package/dist/page-stream.d.ts +24 -0
- package/dist/privacy.d.ts +4 -1
- package/dist/redact.d.ts +25 -2
- package/dist/request-term.js +1 -1
- package/dist/request-term.js.map +1 -1
- package/dist/request-term.mjs +1 -1
- package/dist/request-term.mjs.map +1 -1
- package/dist/strict-attributes.js +1 -1
- package/dist/strict-attributes.js.map +1 -1
- package/dist/strict-attributes.mjs +1 -1
- package/dist/strict-attributes.mjs.map +1 -1
- package/dist/types.d.ts +27 -6
- package/package.json +1 -1
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
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
|
|
@@ -63,9 +66,9 @@ are no peer dependencies. The package ships ESM and CommonJS
|
|
|
63
66
|
rather than the `exports` map (webpack 4, Parcel by default): the same
|
|
64
67
|
SDK without the worker start a page with no bundler loads from beside
|
|
65
68
|
it (see below), so webpack 4 never reads `import.meta`, for the web or
|
|
66
|
-
for node. The bundle is 40.
|
|
69
|
+
for node. The bundle is 40.9 kB
|
|
67
70
|
(decimal) gzipped with rrweb excluded -- the ESM build; the CommonJS
|
|
68
|
-
build is
|
|
71
|
+
build is 41.1 kB and the `module` field's build is 40.9 kB, and
|
|
69
72
|
`privacyMode: "strict"` alone loads its 1.3 kB attribute allow-list
|
|
70
73
|
beside it -- MEASURED on the repository's build at its
|
|
71
74
|
placeholder version (`pnpm build`, which runs `node scripts/build-main.mjs`);
|
|
@@ -73,14 +76,14 @@ the published build carries its version in place of the placeholder,
|
|
|
73
76
|
which moves both figures by a few bytes either way (MEASURED for
|
|
74
77
|
3.1.0-rc.1: 2 B more on each build). It is fully minified, so its
|
|
75
78
|
local names are shortened: that is what keeps an SDK that redacts what
|
|
76
|
-
it records, in the browser,
|
|
79
|
+
it records, in the browser, within its budget: 40 KiB, and 41,316 B for
|
|
77
80
|
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
|
|
81
|
+
format cost then (as built now, the format costs 194 B). Body
|
|
79
82
|
redaction is not in it: it runs in
|
|
80
83
|
a Web Worker, `dist/body-worker.js` (9.3 kB gzipped), which your bundler
|
|
81
84
|
emits beside your app and the SDK starts when a capture that redacts
|
|
82
85
|
bodies starts, in the page's next idle period; its main-thread copy,
|
|
83
|
-
`dist/body-redact.mjs` (9.
|
|
86
|
+
`dist/body-redact.mjs` (9.7 kB gzipped), is a chunk `init()` asks for at once
|
|
84
87
|
for such a capture, beside rrweb, while your page's network is recorded
|
|
85
88
|
from the start (see [Your page's own network](#your-pages-own-network)).
|
|
86
89
|
A capture that masks bodies whole (`privacy.maskNetworkBodies`, which
|
|
@@ -185,7 +188,7 @@ SDK uses when you leave them out:
|
|
|
185
188
|
| option | default | what it does |
|
|
186
189
|
| --------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
187
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) |
|
|
188
|
-
| `sampleRate` | `1` | fraction of
|
|
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 |
|
|
189
192
|
| `networkCapture` | `true` | record `fetch` and `XMLHttpRequest` exchanges. `false` records the DOM only |
|
|
190
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 |
|
|
191
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) |
|
|
@@ -197,7 +200,7 @@ SDK uses when you leave them out:
|
|
|
197
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 |
|
|
198
201
|
| `privacy` | — | a `Partial<PrivacyConfig>`: `maskSelectors`, `unmaskSelectors`, `blockSelectors`, `maskNetworkBodies`, `sensitiveHeaders`, `piiPatterns`, `secretRoutes`, `keepRoutes` — see [Privacy](#privacy) |
|
|
199
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`) |
|
|
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`
|
|
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 |
|
|
201
204
|
| `onError` | — | called once when a terminal condition ends the capture — see [When the server rejects a batch](#when-the-server-rejects-a-batch) |
|
|
202
205
|
|
|
203
206
|
After `init`, the static surface is:
|
|
@@ -207,6 +210,7 @@ KeployCapture.pause(); // keep the session, record nothing more
|
|
|
207
210
|
KeployCapture.resume();
|
|
208
211
|
KeployCapture.getSessionId(); // "" when no session is live
|
|
209
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
|
|
210
214
|
KeployCapture.stop(); // stop recording and send what is queued
|
|
211
215
|
```
|
|
212
216
|
|
|
@@ -511,11 +515,15 @@ value only when its name is the page's structure -- `id`, `class`,
|
|
|
511
515
|
URL (query values replaced), CSS, a `srcset`, a `srcdoc` (its text and
|
|
512
516
|
attributes masked the same way, its scripts included). Every other
|
|
513
517
|
value is recorded as `""`: `title`, `alt`, `placeholder`, `aria-label`
|
|
514
|
-
and the other `aria-*` text, every `data-*` but `data-testid`,
|
|
515
|
-
`
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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`,
|
|
519
527
|
`max` and `pattern` (a date range copies the start the visitor picked
|
|
520
528
|
into the end's `min`; a confirm field copies a typed email into
|
|
521
529
|
`pattern`) and `aria-valuenow` (a slider's chosen value). SVG geometry
|
|
@@ -560,8 +568,9 @@ custom element as on any other; text in one is blanked.
|
|
|
560
568
|
What strict still records, so do not put a visitor's text there: URL
|
|
561
569
|
PATHS (`/search/<term>`, a `#/search/<q>` route, a `<link
|
|
562
570
|
rel="canonical">`; only query and fragment-pair values are replaced),
|
|
563
|
-
`id`s and `class`es, `data-testid` (
|
|
564
|
-
|
|
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
|
|
565
574
|
signature pad's strokes are its `d`) and text under `unmaskSelectors`. A comment
|
|
566
575
|
outside `<html>` that changes after the snapshot is recorded as rrweb
|
|
567
576
|
records it. And the replay's look pays for it: CSS keyed on a `data-*`
|
|
@@ -601,7 +610,8 @@ count are `navigator.doNotTrack === "1"` -- or as older browsers spell
|
|
|
601
610
|
it: `"yes"` (Firefox before 32), `window.doNotTrack === "1"` (Safari,
|
|
602
611
|
IE 11), `navigator.msDoNotTrack === "1"` (IE 10) -- and
|
|
603
612
|
`navigator.globalPrivacyControl === true`; `onError` hears every
|
|
604
|
-
declined `init()
|
|
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.
|
|
605
615
|
|
|
606
616
|
**On the network.** For every recorded exchange:
|
|
607
617
|
|
|
@@ -841,18 +851,16 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
|
|
|
841
851
|
passed in `fetch()`'s `init` or to `send()` is decided from its kind
|
|
842
852
|
and size, never serialised or decoded (only a string one is scanned,
|
|
843
853
|
for its `requestTerm`, below), and the body chunk is never loaded.
|
|
844
|
-
|
|
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
|
|
854
|
+
One body is still read: a `Request` object's own
|
|
850
855
|
(`fetch(new Request(url, { body }))`, as ky and axios's fetch adapter
|
|
851
|
-
send one) is copied
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
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
|
|
856
864
|
request sent with none or an empty one (but an XHR's Blob, which is
|
|
857
865
|
named however small), and a response to a HEAD, a 204, 205 or 304,
|
|
858
866
|
or one whose `Content-Length` is 0. A response that does not declare
|
|
@@ -868,7 +876,27 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
|
|
|
868
876
|
a body that is no GraphQL, or `body:*` for one the SDK could not read
|
|
869
877
|
or hash. It is computed over the body before redaction and never holds
|
|
870
878
|
a variable or a literal: it is what replay tells GraphQL calls apart by
|
|
871
|
-
(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.
|
|
872
900
|
- One rule reads every URL the SDK records: a request's URL and every
|
|
873
901
|
URL its request and response headers carry (`Location`,
|
|
874
902
|
`Content-Location`, `Link` and `Refresh` -- its delay first or not --
|
|
@@ -913,8 +941,8 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
|
|
|
913
941
|
is recorded as `/search?q=[REDACTED]&page=[REDACTED]`; an empty value
|
|
914
942
|
and a bare name (`?flag`, recorded as written, whatever it holds) are
|
|
915
943
|
kept. Replaying such a request needs a replay key that matches a value
|
|
916
|
-
redacted at record against any live value (canonical-key.v2,
|
|
917
|
-
|
|
944
|
+
redacted at record against any live value (canonical-key.v2,
|
|
945
|
+
spec/canonical-key.v2.json); with
|
|
918
946
|
it, two requests that differ only in a redacted value
|
|
919
947
|
(`?session=morning` and `?session=evening`, two `?pin=`s) are one
|
|
920
948
|
request to the replay, answered in the order they were recorded.
|
|
@@ -1280,8 +1308,9 @@ expected, actual}`, a header list `[{name: "Set-Cookie", value}]` —
|
|
|
1280
1308
|
URL is kept; a URL with
|
|
1281
1309
|
nothing to scrub is recorded exactly as it was, and an event the scrub
|
|
1282
1310
|
cannot read is dropped rather than sent, as one the credential scrub
|
|
1283
|
-
cannot read is. A test
|
|
1284
|
-
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.
|
|
1285
1314
|
- The page's TEXT -- each text node of the full snapshot and of a node
|
|
1286
1315
|
added after it, each text change, a value typed under `off`, a
|
|
1287
1316
|
`srcdoc`'s markup -- has every JWT and provider-prefixed key in it
|
|
@@ -1356,22 +1385,65 @@ records each body `[MASKED]`, never in the clear. Changed in this version: it us
|
|
|
1356
1385
|
With network capture on, `fetch()` resolves when the response's headers
|
|
1357
1386
|
arrive, exactly as without the SDK, and the body reaches the page as the
|
|
1358
1387
|
network delivers it: a streamed response -- SSE over `fetch`, NDJSON, an
|
|
1359
|
-
LLM's tokens, a live log view read with `getReader()` -- streams. The
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
`
|
|
1366
|
-
the
|
|
1367
|
-
|
|
1368
|
-
`maxBodySize`
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
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.
|
|
1375
1447
|
|
|
1376
1448
|
The page has its body first. The SDK hands each body to a Web Worker,
|
|
1377
1449
|
which redacts it off your page's main thread. It does so in a task of
|
|
@@ -1388,7 +1460,32 @@ run of large POSTs costs it no redaction, and nothing the SDK does can
|
|
|
1388
1460
|
interleave with a page's `text()`. MEASURED before the page-first
|
|
1389
1461
|
change: 50 parallel 64 KB JSON fetches took 32 ms without the SDK and
|
|
1390
1462
|
382 ms with it in Chromium. The exchange keeps its time and its place
|
|
1391
|
-
in the recording.
|
|
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
|
|
1392
1489
|
record at once every body still in the worker, on the main thread up to
|
|
1393
1490
|
64 KiB in all and cut past it -- with the main thread's chunk, which
|
|
1394
1491
|
`init()` asks for at once, beside rrweb, for a capture that redacts
|
|
@@ -1409,17 +1506,31 @@ each body the main thread must redact the same way, with its own reason
|
|
|
1409
1506
|
[Body not captured: the redaction code could not load]
|
|
1410
1507
|
```
|
|
1411
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
|
+
|
|
1412
1517
|
(`notCapturedBodyNote(N, why)` in `@keploy/contract/privacy`, `why`
|
|
1413
|
-
being `"left"
|
|
1414
|
-
which tells
|
|
1415
|
-
|
|
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.
|
|
1416
1522
|
|
|
1417
1523
|
A page that is leaving starts none of the SDK's own loads (its chunks,
|
|
1418
1524
|
rrweb's import and the body worker), and a load its leave refused or
|
|
1419
1525
|
cancelled is held, not judged failed: a body the page leaves on is
|
|
1420
1526
|
recorded with the first reason, and nothing is logged. A single-page
|
|
1421
|
-
app's route the Navigation API intercepted is no leave
|
|
1422
|
-
`
|
|
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
|
|
1423
1534
|
on something a navigation still on its way cannot produce: Chromium's
|
|
1424
1535
|
abort of the leaving navigation when no navigate came after it (an
|
|
1425
1536
|
"unsaved changes" prompt the visitor cancelled; a link clicked twice,
|
|
@@ -1487,24 +1598,13 @@ and `stop()` record at once what fits in that budget and leave the rest
|
|
|
1487
1598
|
to the worker; `pause()` cuts a body still arriving and records it when
|
|
1488
1599
|
the worker answers.
|
|
1489
1600
|
|
|
1490
|
-
The Response your page gets is
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
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).
|
|
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
|
+
|
|
1508
1608
|
- A **streamed upload built into a `Request`** (`new Request(url, { body:
|
|
1509
1609
|
stream, duplex: "half" })`) that the server answers early is pulled
|
|
1510
1610
|
further than without the SDK -- up to the chunk that crosses
|
|
@@ -1522,18 +1622,13 @@ stream, duplex: "half" })`) that the server answers early is pulled
|
|
|
1522
1622
|
without the SDK, 10 with it at the default cap. A stream passed as
|
|
1523
1623
|
`init.body` is not read at all (recorded `[ReadableStream]`) and is
|
|
1524
1624
|
pulled exactly as without the SDK; only Chromium streams request bodies.
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
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.
|
|
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.
|
|
1537
1632
|
|
|
1538
1633
|
## What a large body looks like
|
|
1539
1634
|
|
|
@@ -1561,7 +1656,7 @@ Over the bound, there are three answers, not one:
|
|
|
1561
1656
|
a size it is the figure the SDK had, not always a measurement —
|
|
1562
1657
|
`[Response body too large: N bytes]` repeats the server's
|
|
1563
1658
|
`Content-Length` for a body it never downloaded. So a note is not a
|
|
1564
|
-
way to size a body against `maxBodySize`. There are
|
|
1659
|
+
way to size a body against `maxBodySize`. There are eight, one for
|
|
1565
1660
|
each way a body can be one the SDK does not read:
|
|
1566
1661
|
- `[Blob: N bytes, truncated]` — a `fetch` Blob over the bound.
|
|
1567
1662
|
- `[Blob: N bytes]` — any Blob sent through `XMLHttpRequest`, which
|
|
@@ -1572,6 +1667,10 @@ Over the bound, there are three answers, not one:
|
|
|
1572
1667
|
text.
|
|
1573
1668
|
- `[Response body too large: N bytes]` — from a `Content-Length` over
|
|
1574
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.
|
|
1575
1674
|
- `[ReadableStream]` — a streaming request body, which reading would
|
|
1576
1675
|
consume out from under your app. No size: measuring a stream means
|
|
1577
1676
|
consuming it too.
|
|
@@ -1596,7 +1695,9 @@ characters kept, unverified]`. The same note marks a body still in the
|
|
|
1596
1695
|
worker when the page leaves, past the 64 KiB the page's last moment
|
|
1597
1696
|
redacts (0 kept when nothing was left), and, with nothing kept and a
|
|
1598
1697
|
second line saying why, a body the SDK did not capture: the page left
|
|
1599
|
-
before the body chunk had arrived,
|
|
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
|
|
1600
1701
|
[Your page's own network](#your-pages-own-network)).
|
|
1601
1702
|
It is not the response the server sent, and replay never serves it as
|
|
1602
1703
|
one: the request is answered as a failed one and a test that reaches it
|
|
@@ -1883,27 +1984,59 @@ no remedy text, which stays on that page; a test holds the summary, the
|
|
|
1883
1984
|
link and the evidence to the corpus. The `docs` pages are published
|
|
1884
1985
|
with the same docs release as the guide above, and answer 404 until
|
|
1885
1986
|
then. The status-to-code mapping is
|
|
1886
|
-
`spec/sdk-errors.
|
|
1987
|
+
`spec/sdk-errors.v5.json`; the session-id rule is
|
|
1887
1988
|
`spec/session-id.v1.json`, the api-server's rule stated once — the
|
|
1888
1989
|
SDK and the sidecar execute the file today, and the api-server's own
|
|
1889
1990
|
executor lands with its next vendoring of the corpus. `onError` runs
|
|
1890
1991
|
after the capture has ended and the singleton is released, so a handler
|
|
1891
|
-
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:
|
|
1892
2021
|
|
|
1893
2022
|
```ts
|
|
1894
|
-
import { KeployCapture } from "@keploy/capture-sdk";
|
|
2023
|
+
import { KeployCapture, type CaptureConfig } from "@keploy/capture-sdk";
|
|
1895
2024
|
|
|
1896
|
-
|
|
2025
|
+
const config: CaptureConfig = {
|
|
1897
2026
|
endpoint,
|
|
1898
2027
|
apiKey,
|
|
2028
|
+
sessionIdGenerator: mySessionId,
|
|
1899
2029
|
onError: (err) => {
|
|
1900
2030
|
// The person using the page said no (Do Not Track or Global Privacy
|
|
1901
2031
|
// Control). Not a failure: keep it out of your error tracker --
|
|
1902
2032
|
// Brave and DuckDuckGo send GPC by default.
|
|
1903
2033
|
if (err.code === "KUI_E_CAPTURE_DECLINED") return;
|
|
1904
|
-
if (err.code === "KUI_E_SESSION_ID_INVALID")
|
|
1905
|
-
|
|
1906
|
-
|
|
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 (
|
|
1907
2040
|
err.code === "KUI_E_DOM_RECORDER_UNAVAILABLE" ||
|
|
1908
2041
|
err.code === "KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE"
|
|
1909
2042
|
)
|
|
@@ -1916,7 +2049,8 @@ await KeployCapture.init({
|
|
|
1916
2049
|
else
|
|
1917
2050
|
report(err.code, err.serverMessage, err.evidence.issues, err.remedy.docs);
|
|
1918
2051
|
},
|
|
1919
|
-
}
|
|
2052
|
+
};
|
|
2053
|
+
await KeployCapture.init(config);
|
|
1920
2054
|
```
|
|
1921
2055
|
|
|
1922
2056
|
A `429`, a `5xx` or a network failure gets three attempts: up to 1 s
|
|
@@ -1941,7 +2075,9 @@ is dropped (a batch that failed and goes back to the queue past
|
|
|
1941
2075
|
record time and replay time cannot disagree.
|
|
1942
2076
|
- **No `Math.random` fallback for the session nonce**, so a recording
|
|
1943
2077
|
is either joinable or says why it is not.
|
|
1944
|
-
- **No sampling by user.** `sampleRate` is
|
|
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.
|
|
1945
2081
|
- **No guessing which generic field holds a secret.** A name/value pair
|
|
1946
2082
|
is read by its `key`, `name` or `header`; a pair spelled otherwise
|
|
1947
2083
|
(`{field, val}`), or one whose name is not a secret's own (an
|