@keploy/capture-sdk 3.0.1 → 3.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1269 -122
- package/dist/errors.d.ts +192 -28
- package/dist/index.d.ts +23 -28
- package/dist/index.js +11 -2354
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +11 -2297
- package/dist/index.mjs.map +1 -0
- package/dist/module-of.d.ts +13 -0
- package/dist/network.d.ts +147 -3
- package/dist/privacy.d.ts +365 -11
- package/dist/recorder.d.ts +279 -63
- package/dist/redact.d.ts +48 -6
- package/dist/request-term.d.ts +21 -0
- package/dist/request-term.js +2 -0
- package/dist/request-term.js.map +1 -0
- package/dist/request-term.mjs +2 -0
- package/dist/request-term.mjs.map +1 -0
- package/dist/term-candidate.d.ts +16 -0
- package/dist/transport.d.ts +237 -130
- package/dist/types.d.ts +132 -5
- package/package.json +9 -3
- package/request-term/package.json +6 -0
package/dist/transport.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SessionEvent, SessionMetadata } from "./types";
|
|
2
|
-
import type { AnyCaptureError } from "./errors";
|
|
2
|
+
import type { AnyCaptureError, ServerAnsweredCode } from "./errors";
|
|
3
3
|
import type { CaptureIdentity } from "./identity";
|
|
4
4
|
/** A request body plus its size on the wire, which the keepalive gate needs. */
|
|
5
5
|
interface WireBody {
|
|
@@ -30,6 +30,26 @@ export declare const MAX_EVENTS_PER_BATCH = 5000;
|
|
|
30
30
|
* enqueue: the server can never take it.
|
|
31
31
|
*/
|
|
32
32
|
export declare const MAX_BATCH_BYTES: number;
|
|
33
|
+
/**
|
|
34
|
+
* THE MOST BYTES THE TRANSPORT HOLDS UNSENT: the event queue and the
|
|
35
|
+
* flights waiting to be re-sent, together, as their JSON. The count cap
|
|
36
|
+
* (maxQueueSize) alone let 5,000 events of up to MAX_BATCH_BYTES each
|
|
37
|
+
* pile up while the ingest was down -- MEASURED (MEASURE.md "Outage"):
|
|
38
|
+
* the 22.5k-node page's heap went 29 -> 211 MB in 90 s once its
|
|
39
|
+
* multi-MB snapshots queued behind a dead endpoint. Past this, the
|
|
40
|
+
* oldest go first, whole: a waiting flight as one (its batchId is bound
|
|
41
|
+
* to its events), then queued events.
|
|
42
|
+
*
|
|
43
|
+
* WHY 16 MiB. It must hold one event of MAX_BATCH_BYTES, the largest the
|
|
44
|
+
* server takes and enqueue() admits -- a big page's FullSnapshot -- or a
|
|
45
|
+
* HEALTHY page would evict its own snapshot on arrival. Above that floor
|
|
46
|
+
* it is memory against how much of an outage is kept: the 6 MiB left
|
|
47
|
+
* behind one such flight is a minute of the busiest stream MEASURE.md
|
|
48
|
+
* recorded (a 64 KB response every second plus mutations and small
|
|
49
|
+
* fetches: about 100 KB/s of JSON) and far longer for a page of ordinary
|
|
50
|
+
* events, which hit the 5,000-event cap first.
|
|
51
|
+
*/
|
|
52
|
+
export declare const MAX_QUEUE_BYTES: number;
|
|
33
53
|
export interface TransportConfig {
|
|
34
54
|
endpoint: string;
|
|
35
55
|
apiKey: string;
|
|
@@ -49,6 +69,24 @@ export interface TransportConfig {
|
|
|
49
69
|
* read before. A program should branch on `code`.
|
|
50
70
|
*/
|
|
51
71
|
onError?: (err: AnyCaptureError) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Called synchronously at pagehide, before the unload flush cuts the
|
|
74
|
+
* last batch, so the owner can hand over what it still holds -- the
|
|
75
|
+
* network exchanges still reading their bodies, which would otherwise
|
|
76
|
+
* be enqueued after the page had gone. Not at beforeunload: a page
|
|
77
|
+
* whose user cancels the leave prompt stays, and its exchanges finish
|
|
78
|
+
* normally.
|
|
79
|
+
*/
|
|
80
|
+
beforeUnloadFlush?: () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Called synchronously when the tab is hidden, before the drain that
|
|
83
|
+
* may be the page's last chance to send (a mobile browser can discard a
|
|
84
|
+
* hidden page with no pagehide), so the owner can queue what it has
|
|
85
|
+
* recorded and not yet handed over: the exchanges whose events wait for
|
|
86
|
+
* a task of their own (NetworkInterceptor.emit). Nothing is cut: the
|
|
87
|
+
* page is still there.
|
|
88
|
+
*/
|
|
89
|
+
beforeHiddenFlush?: () => void;
|
|
52
90
|
/**
|
|
53
91
|
* Called once when a terminal rejection has ended this transport, so
|
|
54
92
|
* the owner can end the CAPTURE.
|
|
@@ -61,6 +99,52 @@ export interface TransportConfig {
|
|
|
61
99
|
* later init() handed back the dead instance.
|
|
62
100
|
*/
|
|
63
101
|
onCaptureEnd?: () => void;
|
|
102
|
+
/**
|
|
103
|
+
* The owner's answer to "does this terminal rejection end only the
|
|
104
|
+
* SESSION?". When it says yes, the transport stops and calls
|
|
105
|
+
* {@link onSessionEnd} instead: no console error, no onError, no
|
|
106
|
+
* onCaptureEnd -- the capture goes on in a new session. Absent, every
|
|
107
|
+
* terminal rejection ends the capture, as it always has.
|
|
108
|
+
*/
|
|
109
|
+
endsSessionOnly?: (code: ServerAnsweredCode, reason: string | null) => boolean;
|
|
110
|
+
/** Called once when {@link endsSessionOnly} said yes, after the transport has stopped. */
|
|
111
|
+
onSessionEnd?: () => void;
|
|
112
|
+
/**
|
|
113
|
+
* Called with the events this transport drops without sending them:
|
|
114
|
+
* refused at enqueue (unserialisable, or over the body cap alone) or
|
|
115
|
+
* dropped to hold the queue at maxQueueSize. A dropped DOM event is a
|
|
116
|
+
* hole in the recording -- every rrweb event after it names nodes by
|
|
117
|
+
* the last FullSnapshot and the mutations since -- so the owner tells
|
|
118
|
+
* the recorder, which holds rrweb's incrementals until a FullSnapshot
|
|
119
|
+
* is sent again. Unsaid, clicks after a snapshot too big to send were
|
|
120
|
+
* posted against no baseline and the flow engine resolved them to
|
|
121
|
+
* `body` (found in review #23). `rebaselined` says a FullSnapshot
|
|
122
|
+
* queued after the dropped DOM events still stands: it is the baseline
|
|
123
|
+
* of everything after it, so there is no hole to hold over -- read as
|
|
124
|
+
* one, a snapshot retaken into a full queue evicted older events, and
|
|
125
|
+
* each eviction asked for another snapshot.
|
|
126
|
+
*/
|
|
127
|
+
onDropped?: (events: SessionEvent[], rebaselined: boolean) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Called with the events of a batch the server accepted. The owner's
|
|
130
|
+
* recorder starts the retake's backoff over when a FullSnapshot is among
|
|
131
|
+
* them: started over as one was emitted, before this transport refused
|
|
132
|
+
* it, the backoff stayed at 5 s and a page too big to send was
|
|
133
|
+
* re-serialised every 5 s for the session (found in review #24).
|
|
134
|
+
*/
|
|
135
|
+
onDelivered?: (events: SessionEvent[]) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Called with true when uploads are failing -- a flight has spent its
|
|
138
|
+
* attempts, or an event was dropped while the browser said it was
|
|
139
|
+
* offline -- and with false when the outage ends: an upload accepted
|
|
140
|
+
* again, or a flush, online, that finds nothing left to probe with
|
|
141
|
+
* (see flush()). The owner's
|
|
142
|
+
* recorder takes no snapshot in between: re-serialising the page into a
|
|
143
|
+
* queue nothing drains is how an outage froze it (MEASURED on a 22.5k-node
|
|
144
|
+
* page: 19 long tasks over 200 ms, up to 373 ms, in the 90 s after the cap), and one snapshot
|
|
145
|
+
* when uploads come back is the baseline for every hole the outage made.
|
|
146
|
+
*/
|
|
147
|
+
onFailing?: (failing: boolean) => void;
|
|
64
148
|
}
|
|
65
149
|
export declare class Transport {
|
|
66
150
|
private config;
|
|
@@ -82,18 +166,39 @@ export declare class Transport {
|
|
|
82
166
|
private sessionId;
|
|
83
167
|
private metadata;
|
|
84
168
|
private captureIdentity;
|
|
85
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Whether the browser says it is online, ASKED EACH TIME. It was a flag
|
|
171
|
+
* the `online` and `offline` events fed, read once more at start() and
|
|
172
|
+
* at release() -- and a page's own listener, registered first, can stop
|
|
173
|
+
* either event before it reaches this transport. After a blip whose
|
|
174
|
+
* `online` was stopped the flag said offline for good: nothing was sent
|
|
175
|
+
* on the transport's own schedule until the tab was hidden or left
|
|
176
|
+
* (found in review #29 on one path, a capture resumed from such a
|
|
177
|
+
* listener, and on two more refuting review #30); and with `offline`
|
|
178
|
+
* stopped it sent into a network the browser called down.
|
|
179
|
+
* navigator.onLine is what the two events report, so it is what is
|
|
180
|
+
* read. The `online` event is when to send at once; the timed flush
|
|
181
|
+
* finds the network back when no event said so.
|
|
182
|
+
*/
|
|
183
|
+
private get online();
|
|
86
184
|
private started;
|
|
87
185
|
/** The stamp the next queued event gets; see enqueue(). */
|
|
88
186
|
private nextSeq;
|
|
89
187
|
/** Set by a drain request that arrived while a flush was running. */
|
|
90
188
|
private drainPending;
|
|
189
|
+
/** Set by hold(): nothing is sent until release(). */
|
|
190
|
+
private holding;
|
|
91
191
|
/**
|
|
92
|
-
*
|
|
93
|
-
* browser said it was offline
|
|
94
|
-
*
|
|
192
|
+
* A DRAIN IS OWED: an event over the keepalive quota was queued while
|
|
193
|
+
* the browser said it was offline. The next thing that sends -- the
|
|
194
|
+
* `online` handler, or a timed flush that finds the browser online --
|
|
195
|
+
* then drains instead of taking one batch. Cleared once the queue has
|
|
196
|
+
* run empty. (A drain that failed is owed by the outage it starts or
|
|
197
|
+
* continues: the upload that ends it drains; see run()'s catch.)
|
|
95
198
|
*/
|
|
96
199
|
private rushDeferred;
|
|
200
|
+
/** Ends the wait of a sender that is between two attempts; see backoff(). */
|
|
201
|
+
private wakeSender;
|
|
97
202
|
private inflightKeepaliveBytes;
|
|
98
203
|
/**
|
|
99
204
|
* Bytes of a request carrying no events: the fixed cost every request
|
|
@@ -103,25 +208,66 @@ export declare class Transport {
|
|
|
103
208
|
/** Set by the first event JSON.stringify refused; see reportUnserialisable(). */
|
|
104
209
|
private reportedUnserialisable;
|
|
105
210
|
private reportedOversized;
|
|
211
|
+
private reportedScrubOversized;
|
|
212
|
+
private reportedNavigationUnwrapped;
|
|
106
213
|
/**
|
|
107
|
-
* Each queued event's JSON bytes, measured once at
|
|
108
|
-
* keepalive rush needs the number there anyway)
|
|
109
|
-
* cut is sized
|
|
214
|
+
* Each queued event's JSON and its bytes, written and measured once at
|
|
215
|
+
* enqueue (the keepalive rush needs the number there anyway): the bytes
|
|
216
|
+
* read wherever a cut is sized (the timed flight, the unload flush, the
|
|
217
|
+
* byte cap), the JSON joined into its flight's body (body()) and never
|
|
218
|
+
* written again. Let go once a flight carries it: the flight keeps its
|
|
219
|
+
* body and its bytes.
|
|
110
220
|
*/
|
|
111
|
-
private readonly
|
|
221
|
+
private readonly jsonOf;
|
|
112
222
|
/** The batch run() is working on, so the unload flush can take it back. */
|
|
113
223
|
private inFlight;
|
|
114
|
-
constructor(config: TransportConfig);
|
|
115
224
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* bare `return` it replaces. An integrator gets the callback; everyone
|
|
121
|
-
* else gets a console error, which is the floor.
|
|
225
|
+
* At least the bytes held unsent (MAX_QUEUE_BYTES): set to the exact
|
|
226
|
+
* sum by fit(), raised by everything that adds to the queue or the retry
|
|
227
|
+
* queue, and never lowered by what leaves them, so it can only be over.
|
|
228
|
+
* fit() counts again only when it is over the cap.
|
|
122
229
|
*/
|
|
230
|
+
private held;
|
|
231
|
+
/** Flights that spent their attempts since one was last accepted; 0 when uploads work. */
|
|
232
|
+
private failures;
|
|
233
|
+
/** performance.now() before which no flight starts on the timer's or an enqueue's say; see OUTAGE_FIRST_MS. */
|
|
234
|
+
private notBefore;
|
|
235
|
+
constructor(config: TransportConfig);
|
|
123
236
|
private fail;
|
|
124
237
|
start(sessionId: string, metadata: SessionMetadata, captureIdentity?: CaptureIdentity | null): void;
|
|
238
|
+
/**
|
|
239
|
+
* HELD: nothing is sent until release(). The capture holds its transport
|
|
240
|
+
* while rrweb's import waits for the network; if that import then
|
|
241
|
+
* fails, the capture is refused, and what was queued meanwhile -- the
|
|
242
|
+
* page's offline calls -- must not reach the server as a session with
|
|
243
|
+
* no DOM. stop() while held sends nothing and drops what was held.
|
|
244
|
+
*/
|
|
245
|
+
hold(): void;
|
|
246
|
+
/**
|
|
247
|
+
* Sends ALL that was held, batch after batch, and from now on as it
|
|
248
|
+
* comes. All of it, whatever asked: one batch left the rest for the
|
|
249
|
+
* timer, and the FullSnapshot of a page started offline sat behind the
|
|
250
|
+
* page's offline calls -- with them, more than a leaving document's one
|
|
251
|
+
* request can carry -- so a visitor who left within seconds of
|
|
252
|
+
* reconnecting was recorded with no DOM (found in review #28, MEASURED
|
|
253
|
+
* in Chromium). A first fix kept only a drain something had asked for
|
|
254
|
+
* while held, which a snapshot under the keepalive quota never does.
|
|
255
|
+
*
|
|
256
|
+
* What comes AFTER is sent as the browser's state allows, read each
|
|
257
|
+
* time (`online`). A release says rrweb's import was answered, which
|
|
258
|
+
* for a transport started offline is most often the network being back
|
|
259
|
+
* -- and the `online` event that would say so need not reach this
|
|
260
|
+
* transport: the page resumed its capture from a listener of its own
|
|
261
|
+
* that stops the event. Believing the browser offline until an event
|
|
262
|
+
* said otherwise, the transport sent what it had held and nothing after
|
|
263
|
+
* it until the page was left (found in review #29, MEASURED in
|
|
264
|
+
* Chromium). Read, not assumed: a service worker that took control
|
|
265
|
+
* after start() answers the import with the network still down, and
|
|
266
|
+
* what comes after waits for the network there as it did.
|
|
267
|
+
*/
|
|
268
|
+
release(): void;
|
|
269
|
+
/** Drops what is queued and what waits to be re-sent, unsent. */
|
|
270
|
+
discard(): void;
|
|
125
271
|
/**
|
|
126
272
|
* Stop accepting events and send what is queued.
|
|
127
273
|
*
|
|
@@ -130,46 +276,59 @@ export declare class Transport {
|
|
|
130
276
|
* can await it; nothing requires it.
|
|
131
277
|
*/
|
|
132
278
|
stop(): Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* Removes the unload and hidden-tab listeners once there is nothing
|
|
135
|
-
* left for them to send: after stop(), the first time the queue is
|
|
136
|
-
* empty. Called wherever the queue can become empty — the drain
|
|
137
|
-
* stop() started, a later drain (a hidden tab, or fail() on a
|
|
138
|
-
* terminal rejection), the unload flush itself — because a listener
|
|
139
|
-
* kept past that point is a leak for the life of the document: a
|
|
140
|
-
* drain that failed on logout kept them, and the hidden-tab drain
|
|
141
|
-
* that later emptied the queue removed nothing, so the Transport was
|
|
142
|
-
* retained by pagehide, beforeunload and visibilitychange for as
|
|
143
|
-
* long as the document lived. Idempotent; a no-op while started or
|
|
144
|
-
* while events remain.
|
|
145
|
-
*/
|
|
146
279
|
private disarmWhenDrained;
|
|
147
280
|
enqueue(event: SessionEvent): void;
|
|
148
281
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* turn. Not `onError` either: that one is reserved for a terminal
|
|
155
|
-
* condition that ENDS the capture, and this one does not — the
|
|
156
|
-
* session goes on without this event.
|
|
157
|
-
*
|
|
158
|
-
* Once, because a custom event emitted from a render or a timer would
|
|
159
|
-
* otherwise write a console line every few milliseconds for the life
|
|
160
|
-
* of the page: the SDK degrading the page it is there to record. The
|
|
161
|
-
* first line carries the event's id and the reason, which is what a
|
|
162
|
-
* developer needs to find the emitter; the rest would only repeat it.
|
|
282
|
+
* A place in the session, taken now for an event queued later: a
|
|
283
|
+
* fetch's, reported when its body ends and recorded in a task after
|
|
284
|
+
* the page's (NetworkInterceptor.emit). Its seq is the one it would
|
|
285
|
+
* have been stamped with, recorded there, so the server orders the
|
|
286
|
+
* session as it did.
|
|
163
287
|
*/
|
|
164
|
-
|
|
288
|
+
place(): number;
|
|
289
|
+
/** Uploads are failing and the wait before the next flight is not over. */
|
|
290
|
+
private get paced();
|
|
291
|
+
/**
|
|
292
|
+
* Holds what is unsent at MAX_QUEUE_BYTES, dropping the oldest first:
|
|
293
|
+
* waiting flights whole, then queued events. fit() never drops the
|
|
294
|
+
* newest -- enqueue() admits none over MAX_BATCH_BYTES, which is under
|
|
295
|
+
* the cap -- though dropped() may, as it takes any incremental read
|
|
296
|
+
* against a DOM event that went. What goes is said (dropped()), so the recorder knows
|
|
297
|
+
* of the hole a DOM event leaves.
|
|
298
|
+
*/
|
|
299
|
+
private fit;
|
|
165
300
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
301
|
+
* Said to the owner (TransportConfig.onDropped): events dropped unsent.
|
|
302
|
+
* A dropped DOM event takes with it the rrweb incrementals still queued
|
|
303
|
+
* behind it up to the next FullSnapshot: each is read against what the
|
|
304
|
+
* dropped event held, and posted, a click on a button the dropped
|
|
305
|
+
* snapshot held was resolved to `body` (found in review #23). A
|
|
306
|
+
* FullSnapshot is never dropped ahead of its incrementals.
|
|
171
307
|
*/
|
|
308
|
+
private dropped;
|
|
309
|
+
private reportUnserialisable;
|
|
172
310
|
private reportOversized;
|
|
311
|
+
/**
|
|
312
|
+
* Say that the recorder dropped an event because scrubbing the page
|
|
313
|
+
* URL's credentials out of it passed the server's decoded cap (privacy.ts
|
|
314
|
+
* ScrubOverCap) -- ONCE per transport, like reportOversized. The event
|
|
315
|
+
* never reached the queue, so it has no id; `atLeast` is a lower bound of
|
|
316
|
+
* the scrubbed event's size: what the scrub had written when it stopped,
|
|
317
|
+
* less what a later replacement could still take off it.
|
|
318
|
+
*/
|
|
319
|
+
reportScrubOversized(eventType: SessionEvent["type"], atLeast: number, cap: number): void;
|
|
320
|
+
/**
|
|
321
|
+
* Say that the page made a History or Navigation API method the SDK wraps
|
|
322
|
+
* impossible to replace and put back, so the recorder wrapped none
|
|
323
|
+
* (recorder.ts wrapHistory) -- ONCE per transport, like
|
|
324
|
+
* reportScrubOversized. Nothing is dropped: route changes are still
|
|
325
|
+
* recorded, with less detail (recorder.ts, ALL OR NOTHING).
|
|
326
|
+
*/
|
|
327
|
+
reportNavigationUnwrapped(method: string): void;
|
|
328
|
+
/** The console line for an event too large to send: once per code, as each caller decides. */
|
|
329
|
+
private warnOversized;
|
|
330
|
+
/** One console line; each caller says its code once per capture. */
|
|
331
|
+
private warn;
|
|
173
332
|
/** The request body for `events`, with everything a batch carries. */
|
|
174
333
|
private payload;
|
|
175
334
|
/**
|
|
@@ -188,6 +347,14 @@ export declare class Transport {
|
|
|
188
347
|
*/
|
|
189
348
|
flush(drain?: boolean): Promise<void>;
|
|
190
349
|
private run;
|
|
350
|
+
/**
|
|
351
|
+
* The wait before the next attempt, ENDED BY `online`: the network
|
|
352
|
+
* being back is what the wait was for, and a sender that slept on
|
|
353
|
+
* sent nothing for up to 2 s more while the page's visitor was
|
|
354
|
+
* leaving (found in review #29). One sender runs at a time, so one
|
|
355
|
+
* wait is pending at most.
|
|
356
|
+
*/
|
|
357
|
+
private backoff;
|
|
191
358
|
private sendWithRetry;
|
|
192
359
|
/**
|
|
193
360
|
* The last flush, issued while the document is being torn down.
|
|
@@ -222,11 +389,11 @@ export declare class Transport {
|
|
|
222
389
|
* a document that survives its pagehide (a back/forward-cache entry)
|
|
223
390
|
* and later ships the held-back event from its timer is stored in
|
|
224
391
|
* order regardless. For the node map: the flow engine's extractor.ts
|
|
225
|
-
*
|
|
226
|
-
* behind a snapshot names its nodes by
|
|
227
|
-
* without it, they are resolved against
|
|
228
|
-
* their nodes, and selectorFromNode answers
|
|
229
|
-
* cannot find — a click on `body` in the generated test, silently,
|
|
392
|
+
* rebuilds the DOM from the FullSnapshot and the mutations after it,
|
|
393
|
+
* and every incremental event behind a snapshot names its nodes by
|
|
394
|
+
* that snapshot's ids. Shipped without it, they are resolved against
|
|
395
|
+
* a DOM that does not hold their nodes, and selectorFromNode answers
|
|
396
|
+
* `body` for a node it cannot find — a click on `body` in the generated test, silently,
|
|
230
397
|
* where the session ending at the snapshot would have been the
|
|
231
398
|
* truth. So what does not fit holds back what depends on it.
|
|
232
399
|
*
|
|
@@ -236,97 +403,37 @@ export declare class Transport {
|
|
|
236
403
|
* leaving. Which is why an event that can never fit is not left to
|
|
237
404
|
* wait here: enqueue() sends it as soon as it is queued.
|
|
238
405
|
*/
|
|
239
|
-
/**
|
|
240
|
-
* Take back the batch run() is holding, if no request for it has been
|
|
241
|
-
* dispatched yet.
|
|
242
|
-
*
|
|
243
|
-
* THE GAP THIS CLOSES. run() splices a batch out of the queue and
|
|
244
|
-
* hands it to sendWithRetry, and a request does not leave the browser
|
|
245
|
-
* straight away: compressPayload is asynchronous, and after a failed
|
|
246
|
-
* attempt sendWithRetry sleeps 0.5–1 s, then 1–2 s, before the next
|
|
247
|
-
* one. Through all of that the events are in neither the queue nor a
|
|
248
|
-
* request, and the unload flush could not see them. pagehide in that
|
|
249
|
-
* window shipped the events queued AFTER them with keepalive and
|
|
250
|
-
* never dispatched these, because an await does not resume in a
|
|
251
|
-
* document that is gone — so the server's seq-sorted file got the
|
|
252
|
-
* tail with a hole in the body. A hole is worse than a short
|
|
253
|
-
* recording: the events after it name node ids the missing batch
|
|
254
|
-
* introduced, and the flow engine resolves them against a map that
|
|
255
|
-
* does not hold them.
|
|
256
|
-
*
|
|
257
|
-
* ONLY WHILE NOTHING IS ON THE WIRE. A dispatched keepalive request
|
|
258
|
-
* outlives the document by design, and one without keepalive may
|
|
259
|
-
* still arrive; re-sending those events would duplicate them in a
|
|
260
|
-
* file the server appends to by seq. That request in flight when the
|
|
261
|
-
* document dies is the residual limit, and it is the same one every
|
|
262
|
-
* in-flight request has.
|
|
263
|
-
*
|
|
264
|
-
* `abandoned` stops every further attempt, so a document that
|
|
265
|
-
* SURVIVES its pagehide (a back/forward-cache entry, a cancelled
|
|
266
|
-
* navigation) does not send the batch a second time when the backoff
|
|
267
|
-
* resumes, and run()'s catch does not unshift what has already gone.
|
|
268
|
-
*/
|
|
269
406
|
private reclaimInFlight;
|
|
270
|
-
/**
|
|
271
|
-
* The next waiting flight as a FRESH ATTEMPT CONTEXT, or null.
|
|
272
|
-
*
|
|
273
|
-
* `abandoned` does one job: it stops the sendWithRetry loop that was
|
|
274
|
-
* running when the unload flush took the flight. That loop still
|
|
275
|
-
* holds the OLD object, so it must keep seeing `abandoned === true`
|
|
276
|
-
* -- but the re-send must not, or it returns from sendWithRetry
|
|
277
|
-
* before its first attempt and run() counts the flight as delivered.
|
|
278
|
-
* MEASURED: a flight over the keepalive quota, reclaimed at pagehide
|
|
279
|
-
* during its backoff on a document that survived (a download click,
|
|
280
|
-
* a cancelled navigation, a bfcache restore), was shifted by the next
|
|
281
|
-
* flush and dropped -- queueSize 2 -> 0, zero requests, where the
|
|
282
|
-
* pre-batchId transport delivered both events. So the flags are
|
|
283
|
-
* per attempt and the id and bytes are per flight.
|
|
284
|
-
*/
|
|
285
407
|
private reviveNext;
|
|
286
|
-
/**
|
|
287
|
-
* A new flight from the head of the queue, or null when it is empty.
|
|
288
|
-
* The id and the bytes are minted together, once.
|
|
289
|
-
*
|
|
290
|
-
* CUT BY BYTES AS WELL AS BY COUNT, the way the unload flush cuts
|
|
291
|
-
* against the keepalive quota: at the first event that would take the
|
|
292
|
-
* decoded body over MAX_BATCH_BYTES, everything behind it holding for
|
|
293
|
-
* the next flight. The first event always fits -- enqueue() refused
|
|
294
|
-
* anything that alone would not -- so a flight is never empty while
|
|
295
|
-
* the queue is not.
|
|
296
|
-
*/
|
|
297
408
|
private formFlight;
|
|
298
|
-
/** The event's JSON bytes: what enqueue() measured, or measured now for an event that reached the queue another way. */
|
|
299
|
-
private eventBytes;
|
|
300
409
|
/**
|
|
301
|
-
* The
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
410
|
+
* The POST body for `events`: JSON.stringify(this.payload(events,
|
|
411
|
+
* batchId)), the same text, with each event's JSON as enqueue() wrote
|
|
412
|
+
* it, joined. The envelope is written with no events; its
|
|
413
|
+
* `"events":[]` is the first, since only the session and batch ids,
|
|
414
|
+
* strings, come before it, and no string's JSON holds a bare `"`. An
|
|
415
|
+
* event with no JSON kept (one a flight carried, taken back at
|
|
416
|
+
* pagehide) is written now.
|
|
307
417
|
*/
|
|
418
|
+
private body;
|
|
419
|
+
/** The event's JSON bytes: what enqueue() measured, or measured now for one a flight carried and pagehide took back. */
|
|
420
|
+
private eventBytes;
|
|
308
421
|
private mintBatchId;
|
|
309
422
|
/** Events waiting to be sent, retry flights included. */
|
|
310
423
|
private pendingCount;
|
|
311
|
-
/**
|
|
312
|
-
* On a re-queue, hold the total at maxQueueSize by dropping the NEWEST
|
|
313
|
-
* queued events, as the old unshift-then-pop did. enqueue() trims the
|
|
314
|
-
* queue alone (oldest first) and does not see waiting flights, so
|
|
315
|
-
* between re-queues the total can stand one batch over maxQueueSize
|
|
316
|
-
* -- the same bound the old code had, where one batch sat off the
|
|
317
|
-
* queue in flight. A retry flight is never trimmed: dropping events
|
|
318
|
-
* from it would change the set its batchId is bound to, and the
|
|
319
|
-
* server answers that with a 409.
|
|
320
|
-
*/
|
|
321
424
|
private trimToCapacity;
|
|
322
425
|
private flushOnUnload;
|
|
323
426
|
/** One fire-and-forget keepalive POST, accounted against the quota. */
|
|
324
427
|
private postKeepalive;
|
|
325
428
|
private handleOnline;
|
|
326
|
-
private handleOffline;
|
|
327
429
|
private handleUnload;
|
|
328
430
|
private handleVisibility;
|
|
329
|
-
/**
|
|
431
|
+
/**
|
|
432
|
+
* Events waiting their turn: the queue, and flights waiting to be
|
|
433
|
+
* re-sent. NOT a batch already taken off the queue and being compressed
|
|
434
|
+
* or on the wire, so 0 does not mean everything was sent -- await
|
|
435
|
+
* stop() for that.
|
|
436
|
+
*/
|
|
330
437
|
get queueSize(): number;
|
|
331
438
|
}
|
|
332
439
|
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -48,7 +48,16 @@ export interface CaptureConfig {
|
|
|
48
48
|
* - "balanced": the value of every input, textarea and select is
|
|
49
49
|
* masked, except the six listed below; visible text is recorded.
|
|
50
50
|
* - "strict" : that, and every visible text node is replaced with
|
|
51
|
-
* asterisks.
|
|
51
|
+
* asterisks. For public sites, where nothing the person typed is
|
|
52
|
+
* recorded: no request or response body is recorded either
|
|
53
|
+
* (`privacy.maskNetworkBodies` is forced on, and an explicit
|
|
54
|
+
* `false` beside strict is refused with KUI_E_PRIVACY_CONFLICT,
|
|
55
|
+
* before anything is recorded), every query value of a request URL
|
|
56
|
+
* is replaced and every name kept, and so is every query value of
|
|
57
|
+
* the page's own URL and of each URL in the DOM; and every header
|
|
58
|
+
* value is replaced, its name kept, but those of the headers that
|
|
59
|
+
* describe the exchange rather than the person (content-type,
|
|
60
|
+
* content-length, accept and the like; the README lists them).
|
|
52
61
|
* - "off" : typed values are recorded — EXCEPT password fields
|
|
53
62
|
* and `<input type="hidden">`, which are masked in every mode.
|
|
54
63
|
* This docstring used to say "no automatic masking", which was
|
|
@@ -94,9 +103,33 @@ export interface CaptureConfig {
|
|
|
94
103
|
*
|
|
95
104
|
* When it elapses the WHOLE capture ends: DOM and network recording
|
|
96
105
|
* stop, the queued tail is flushed, and the singleton is released so
|
|
97
|
-
* a later `KeployCapture.init()` starts a new session
|
|
106
|
+
* a later `KeployCapture.init()` starts a new session -- unless
|
|
107
|
+
* `continuous` is set (without a `sessionIdGenerator`), when the next
|
|
108
|
+
* session starts by itself.
|
|
98
109
|
*/
|
|
99
110
|
maxSessionDuration?: number;
|
|
111
|
+
/**
|
|
112
|
+
* Keep capturing for the life of the page, one session at a time.
|
|
113
|
+
* @default false
|
|
114
|
+
*
|
|
115
|
+
* A single-page app can stay open for hours on one load, and without
|
|
116
|
+
* this a capture records its first `maxSessionDuration` and nothing
|
|
117
|
+
* after. With it, a session that ends -- at `maxSessionDuration`, or
|
|
118
|
+
* because the server refused a batch with a `reason` saying it has
|
|
119
|
+
* completed the session (a 409 `session_completed`, e.g. after the
|
|
120
|
+
* machine slept past the server's idle window) or that the session is
|
|
121
|
+
* full (a 413 `session_full`) -- is followed by a NEW session at the
|
|
122
|
+
* visitor's next click, tap or key press, so an idle tab posts nothing.
|
|
123
|
+
* A server that predates `reason` keeps those refusals terminal. Each
|
|
124
|
+
* session becomes flows on its own. A `pause()` in force carries into
|
|
125
|
+
* the next session; `KeployCapture.stop()` ends it all.
|
|
126
|
+
*
|
|
127
|
+
* With a `sessionIdGenerator` this has no effect: the capture ends at
|
|
128
|
+
* `maxSessionDuration` and at those refusals exactly as without it.
|
|
129
|
+
* That id is yours -- usually one per visit -- and a second session
|
|
130
|
+
* under it would be refused as completed.
|
|
131
|
+
*/
|
|
132
|
+
continuous?: boolean;
|
|
100
133
|
/**
|
|
101
134
|
* Number of events to batch before flushing -- a ceiling, not a
|
|
102
135
|
* promise. Clamped to 5000, the most the ingest server accepts in one
|
|
@@ -131,6 +164,19 @@ export interface CaptureConfig {
|
|
|
131
164
|
* Merged with {@link PrivacyConfig.unmaskSelectors}.
|
|
132
165
|
*/
|
|
133
166
|
unmaskSelectors?: string[];
|
|
167
|
+
/**
|
|
168
|
+
* Honour the browser's privacy signals. @default true
|
|
169
|
+
*
|
|
170
|
+
* When the person using the page has Do Not Track on
|
|
171
|
+
* (`navigator.doNotTrack === "1"`) or sends Global Privacy Control
|
|
172
|
+
* (`navigator.globalPrivacyControl === true`), init() records nothing,
|
|
173
|
+
* patches nothing and sends nothing: the capture never starts, and the
|
|
174
|
+
* SDK says so once -- a console.info line and `onError` with
|
|
175
|
+
* KUI_E_CAPTURE_DECLINED, whose `evidence.signal` names the signal. Set
|
|
176
|
+
* `false` only where the site has its own lawful basis to record
|
|
177
|
+
* regardless and says so in its privacy policy.
|
|
178
|
+
*/
|
|
179
|
+
honorPrivacySignals?: boolean;
|
|
134
180
|
/**
|
|
135
181
|
* Custom session-ID generator. When omitted the SDK produces a UUID v4.
|
|
136
182
|
* Useful if you already have your own session / correlation ID.
|
|
@@ -212,7 +258,7 @@ export interface CaptureConfig {
|
|
|
212
258
|
* on `code` (a KUI_E_* from the contract's error corpus) -- which
|
|
213
259
|
* narrows it to an IngestRejection (`evidence.status`, `.issues`) or
|
|
214
260
|
* a SessionIdRefusal (`evidence.received`, `.rule`) -- and read
|
|
215
|
-
* `serverMessage` (the server's own sentence) and `remedy.
|
|
261
|
+
* `serverMessage` (the server's own sentence) and `remedy.docs`;
|
|
216
262
|
* `message` is the prose a human read before. It is called after the
|
|
217
263
|
* capture has ended and the singleton is released, so a handler may
|
|
218
264
|
* call KeployCapture.init() again and get a fresh capture. It is
|
|
@@ -259,6 +305,14 @@ export interface NetworkEvent {
|
|
|
259
305
|
/** Round-trip duration in ms. */
|
|
260
306
|
duration: number;
|
|
261
307
|
type: NetworkRequestType;
|
|
308
|
+
/**
|
|
309
|
+
* canonical-key.v2's term for the RAW request body ("" when it carries
|
|
310
|
+
* none, "body:*" when it is not text, or is a GraphQL document a page
|
|
311
|
+
* with no SubtleCrypto cannot hash), computed before redaction, masking
|
|
312
|
+
* or truncation. Absent only when computing it threw
|
|
313
|
+
* (KUI_E_REQUEST_TERM_FAILED) (spec/canonical-key.v2.json rules.record).
|
|
314
|
+
*/
|
|
315
|
+
requestTerm?: string;
|
|
262
316
|
}
|
|
263
317
|
export interface SessionMetadata {
|
|
264
318
|
url: string;
|
|
@@ -307,7 +361,14 @@ export interface PrivacyConfig {
|
|
|
307
361
|
unmaskSelectors: string[];
|
|
308
362
|
/** CSS selectors whose matched elements are completely removed from the recording. */
|
|
309
363
|
blockSelectors: string[];
|
|
310
|
-
/**
|
|
364
|
+
/**
|
|
365
|
+
* Replace network request/response bodies with "[MASKED]" (a body
|
|
366
|
+
* that was absent stays null). @default false
|
|
367
|
+
*
|
|
368
|
+
* Forced on under `privacyMode: "strict"`. KeployCapture refuses an
|
|
369
|
+
* explicit `false` beside strict with KUI_E_PRIVACY_CONFLICT rather
|
|
370
|
+
* than let either option silently win.
|
|
371
|
+
*/
|
|
311
372
|
maskNetworkBodies: boolean;
|
|
312
373
|
/**
|
|
313
374
|
* Header names (case-insensitive) whose values are replaced with
|
|
@@ -336,6 +397,62 @@ export interface PrivacyConfig {
|
|
|
336
397
|
* body if they must be scrubbable by pattern.
|
|
337
398
|
*/
|
|
338
399
|
piiPatterns: PiiPattern[];
|
|
400
|
+
/**
|
|
401
|
+
* Routes of the app whose `:name` segments are CREDENTIALS -- a link's
|
|
402
|
+
* token the built-in recognition does not know: `"/invites/:key"`,
|
|
403
|
+
* `"/u/confirm-admin/:token"`. Each value they name in the page's path,
|
|
404
|
+
* in a hash router's route (`#/` or `#!/`), or in a URL nested in a
|
|
405
|
+
* parameter is kept out of the recorded URL and every event, each form
|
|
406
|
+
* of it (as spelt, decoded, encoded) by its own text: a
|
|
407
|
+
* generated-looking one wherever it appears, like a recognised one; any
|
|
408
|
+
* other of at least 6 characters, decoded, whatever its letters, in any
|
|
409
|
+
* case, wherever no ASCII letter or digit touches it (a request body,
|
|
410
|
+
* the page's text, a share link) -- so a page of the app's own that the
|
|
411
|
+
* route also matches (`/invites/notifications` under `/invites/:key`)
|
|
412
|
+
* needs a keep route, or its name is scrubbed as a credential from every
|
|
413
|
+
* event of the page from then on, later routes of a single-page app
|
|
414
|
+
* included; a shorter one (`new`, `Edit`) only as the path segment after
|
|
415
|
+
* the one its route puts before it, in any URL an event carries,
|
|
416
|
+
* written, percent-encoded, or encoded again as a share link encodes it
|
|
417
|
+
* (up to three times),
|
|
418
|
+
* whatever matrix parameters or empty segments follow that segment, so
|
|
419
|
+
* a short word that is also the app's text stays (and is NOT scrubbed
|
|
420
|
+
* from bodies or text). An event's names are dropped (a DOM event's) or
|
|
421
|
+
* renamed only where the page or the integrator wrote them, and never
|
|
422
|
+
* rrweb's own; rrweb's tag names, HTML's vocabulary
|
|
423
|
+
* attributes (`type`, `rel`, ...), the network record's method and CSS's
|
|
424
|
+
* syntax are not scrubbed (CSS only in its url()s, strings and
|
|
425
|
+
* comments, a `<style>`'s text whenever it is written included). A JSON
|
|
426
|
+
* body keeps parsing: a value in a string is replaced
|
|
427
|
+
* inside it, and a number holding one becomes the string "[REDACTED]".
|
|
428
|
+
* The values the routes name in the page's own
|
|
429
|
+
* path and route are always held; a URL's other values, and the other
|
|
430
|
+
* segments a declared value is named after, 32 at most. A route is
|
|
431
|
+
* `/`-separated segments from the path's start (empty ones ignored),
|
|
432
|
+
* each a literal (case-insensitive), `*` (any one segment) or `:name`,
|
|
433
|
+
* with at least one `:name`; it matches a path that begins with it,
|
|
434
|
+
* except where a keep route names its own literal. A route outside that
|
|
435
|
+
* rule refuses to start the capture (KUI_E_PRIVACY_ROUTE_INVALID)
|
|
436
|
+
* rather than protect nothing.
|
|
437
|
+
* @default []
|
|
438
|
+
*/
|
|
439
|
+
secretRoutes?: readonly string[];
|
|
440
|
+
/**
|
|
441
|
+
* Routes whose `:name` segments are the APP'S OWN IDS, which the
|
|
442
|
+
* built-in recognition would otherwise take for a link's token after a
|
|
443
|
+
* link word -- `"/teams/invite/:teamId"`, `"/devices/reset/:id"` -- and
|
|
444
|
+
* scrub, breaking the replay of every request that carries them; a
|
|
445
|
+
* value a secret route names as well is still a credential. A keep
|
|
446
|
+
* route's literal is the app's own name for that position, so no secret
|
|
447
|
+
* route takes it for a value there: `"/invites/settings"` keeps
|
|
448
|
+
* `/invites/settings/billing` from `"/invites/:key"`. A keep route of
|
|
449
|
+
* literals alone names one page, the path it spells exactly and not the
|
|
450
|
+
* pages under it: there, no segment is taken for a token either. The
|
|
451
|
+
* same segment rule as `secretRoutes`, except that a keep route needs
|
|
452
|
+
* at least one literal rather than a `:name`.
|
|
453
|
+
* @default []
|
|
454
|
+
*/
|
|
455
|
+
keepRoutes?: readonly string[];
|
|
339
456
|
}
|
|
340
457
|
export interface PiiPattern {
|
|
341
458
|
name: string;
|
|
@@ -360,4 +477,14 @@ export interface TransportPayload {
|
|
|
360
477
|
captureIdentity: CaptureIdentity | null;
|
|
361
478
|
}
|
|
362
479
|
export type EventCallback = (event: SessionEvent) => void;
|
|
363
|
-
|
|
480
|
+
/**
|
|
481
|
+
* `at`: when the exchange was answered (or failed), as `Date.now()`, for
|
|
482
|
+
* an event whose body is read after that -- every fetch. The event is
|
|
483
|
+
* stamped with it, so the recording's clock places the exchange where it
|
|
484
|
+
* happened (its timestamp less its duration is when it was asked) however
|
|
485
|
+
* long its body took. Absent, it is stamped when it is emitted (an XHR,
|
|
486
|
+
* which is emitted when it ends and whose duration runs to its end).
|
|
487
|
+
*/
|
|
488
|
+
export type NetworkEventCallback = (event: NetworkEvent, at?: number,
|
|
489
|
+
/** The event's place in the recording, when the interceptor was given a way to take one (NetworkInterceptor.start). */
|
|
490
|
+
seq?: number) => void;
|