@keploy/capture-sdk 3.0.1 → 3.1.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1617 -130
- package/body-redact/package.json +6 -0
- package/body-worker-start/package.json +6 -0
- package/dist/body-jobs.d.ts +134 -0
- package/dist/body-redact.d.ts +23 -0
- package/dist/body-redact.js +1 -0
- package/dist/body-redact.js.map +1 -0
- package/dist/body-redact.mjs +1 -0
- package/dist/body-redact.mjs.map +1 -0
- package/dist/body-worker-none.d.ts +3 -0
- package/dist/body-worker-none.js +1 -0
- package/dist/body-worker-none.js.map +1 -0
- package/dist/body-worker-none.mjs +1 -0
- package/dist/body-worker-none.mjs.map +1 -0
- package/dist/body-worker-start.d.ts +3 -0
- package/dist/body-worker-start.js +1 -0
- package/dist/body-worker-start.js.map +1 -0
- package/dist/body-worker-start.mjs +1 -0
- package/dist/body-worker-start.mjs.map +1 -0
- package/dist/body-worker-unbundled.d.ts +1 -0
- package/dist/body-worker-unbundled.mjs +1 -0
- package/dist/body-worker-unbundled.mjs.map +1 -0
- package/dist/body-worker.d.ts +1 -0
- package/dist/body-worker.js +1 -0
- package/dist/body-worker.js.map +1 -0
- package/dist/errors.d.ts +224 -28
- package/dist/index.bundler.mjs +1 -0
- package/dist/index.bundler.mjs.map +1 -0
- package/dist/index.d.ts +23 -28
- package/dist/index.js +1 -2354
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -2297
- package/dist/index.mjs.map +1 -0
- package/dist/leave.d.ts +67 -0
- package/dist/module-of.d.ts +58 -0
- package/dist/network.d.ts +163 -4
- package/dist/privacy.d.ts +387 -12
- package/dist/recorder.d.ts +304 -64
- package/dist/redact.d.ts +48 -6
- package/dist/request-term.d.ts +23 -0
- package/dist/request-term.js +1 -0
- package/dist/request-term.js.map +1 -0
- package/dist/request-term.mjs +1 -0
- package/dist/request-term.mjs.map +1 -0
- package/dist/strict-attributes.d.ts +9 -0
- package/dist/strict-attributes.js +1 -0
- package/dist/strict-attributes.js.map +1 -0
- package/dist/strict-attributes.mjs +1 -0
- package/dist/strict-attributes.mjs.map +1 -0
- package/dist/term-candidate.d.ts +16 -0
- package/dist/transport.d.ts +269 -130
- package/dist/types.d.ts +152 -9
- package/package.json +37 -4
- package/request-term/package.json +6 -0
- package/strict-attributes/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,36 @@ 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 bodies are still
|
|
86
|
+
* being redacted, as far as they fit the main thread's budget
|
|
87
|
+
* (NetworkInterceptor.reportDue()). Nothing is cut: the page is still
|
|
88
|
+
* there, and the rest is recorded when the worker answers.
|
|
89
|
+
*/
|
|
90
|
+
beforeHiddenFlush?: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Called synchronously when the browser is back online, before the
|
|
93
|
+
* flush that ends an outage, so the owner can queue what it recorded
|
|
94
|
+
* offline and has not yet handed over: the exchanges whose bodies are
|
|
95
|
+
* still being redacted, as far as they fit the main thread's budget
|
|
96
|
+
* and its body code had loaded before the outage
|
|
97
|
+
* (NetworkInterceptor.reportDue()): such an exchange made offline is in
|
|
98
|
+
* the upload that ends the outage; the rest follow it, recorded the
|
|
99
|
+
* same, when the code and the worker load and answer.
|
|
100
|
+
*/
|
|
101
|
+
beforeOnlineFlush?: () => void;
|
|
52
102
|
/**
|
|
53
103
|
* Called once when a terminal rejection has ended this transport, so
|
|
54
104
|
* the owner can end the CAPTURE.
|
|
@@ -61,6 +111,52 @@ export interface TransportConfig {
|
|
|
61
111
|
* later init() handed back the dead instance.
|
|
62
112
|
*/
|
|
63
113
|
onCaptureEnd?: () => void;
|
|
114
|
+
/**
|
|
115
|
+
* The owner's answer to "does this terminal rejection end only the
|
|
116
|
+
* SESSION?". When it says yes, the transport stops and calls
|
|
117
|
+
* {@link onSessionEnd} instead: no console error, no onError, no
|
|
118
|
+
* onCaptureEnd -- the capture goes on in a new session. Absent, every
|
|
119
|
+
* terminal rejection ends the capture, as it always has.
|
|
120
|
+
*/
|
|
121
|
+
endsSessionOnly?: (code: ServerAnsweredCode, reason: string | null) => boolean;
|
|
122
|
+
/** Called once when {@link endsSessionOnly} said yes, after the transport has stopped. */
|
|
123
|
+
onSessionEnd?: () => void;
|
|
124
|
+
/**
|
|
125
|
+
* Called with the events this transport drops without sending them:
|
|
126
|
+
* refused at enqueue (unserialisable, or over the body cap alone) or
|
|
127
|
+
* dropped to hold the queue at maxQueueSize. A dropped DOM event is a
|
|
128
|
+
* hole in the recording -- every rrweb event after it names nodes by
|
|
129
|
+
* the last FullSnapshot and the mutations since -- so the owner tells
|
|
130
|
+
* the recorder, which holds rrweb's incrementals until a FullSnapshot
|
|
131
|
+
* is sent again. Unsaid, clicks after a snapshot too big to send were
|
|
132
|
+
* posted against no baseline and the flow engine resolved them to
|
|
133
|
+
* `body` (found in review #23). `rebaselined` says a FullSnapshot
|
|
134
|
+
* queued after the dropped DOM events still stands: it is the baseline
|
|
135
|
+
* of everything after it, so there is no hole to hold over -- read as
|
|
136
|
+
* one, a snapshot retaken into a full queue evicted older events, and
|
|
137
|
+
* each eviction asked for another snapshot.
|
|
138
|
+
*/
|
|
139
|
+
onDropped?: (events: SessionEvent[], rebaselined: boolean) => void;
|
|
140
|
+
/**
|
|
141
|
+
* Called with the events of a batch the server accepted. The owner's
|
|
142
|
+
* recorder starts the retake's backoff over when a FullSnapshot is among
|
|
143
|
+
* them: started over as one was emitted, before this transport refused
|
|
144
|
+
* it, the backoff stayed at 5 s and a page too big to send was
|
|
145
|
+
* re-serialised every 5 s for the session (found in review #24).
|
|
146
|
+
*/
|
|
147
|
+
onDelivered?: (events: SessionEvent[]) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Called with true when uploads are failing -- a flight has spent its
|
|
150
|
+
* attempts, or an event was dropped while the browser said it was
|
|
151
|
+
* offline -- and with false when the outage ends: an upload accepted
|
|
152
|
+
* again, or a flush, online, that finds nothing left to probe with
|
|
153
|
+
* (see flush()). The owner's
|
|
154
|
+
* recorder takes no snapshot in between: re-serialising the page into a
|
|
155
|
+
* queue nothing drains is how an outage froze it (MEASURED on a 22.5k-node
|
|
156
|
+
* page: 19 long tasks over 200 ms, up to 373 ms, in the 90 s after the cap), and one snapshot
|
|
157
|
+
* when uploads come back is the baseline for every hole the outage made.
|
|
158
|
+
*/
|
|
159
|
+
onFailing?: (failing: boolean) => void;
|
|
64
160
|
}
|
|
65
161
|
export declare class Transport {
|
|
66
162
|
private config;
|
|
@@ -82,18 +178,44 @@ export declare class Transport {
|
|
|
82
178
|
private sessionId;
|
|
83
179
|
private metadata;
|
|
84
180
|
private captureIdentity;
|
|
85
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Whether the browser says it is online, ASKED EACH TIME. It was a flag
|
|
183
|
+
* the `online` and `offline` events fed, read once more at start() and
|
|
184
|
+
* at release() -- and a page's own listener, registered first, can stop
|
|
185
|
+
* either event before it reaches this transport. After a blip whose
|
|
186
|
+
* `online` was stopped the flag said offline for good: nothing was sent
|
|
187
|
+
* on the transport's own schedule until the tab was hidden or left
|
|
188
|
+
* (found in review #29 on one path, a capture resumed from such a
|
|
189
|
+
* listener, and on two more refuting review #30); and with `offline`
|
|
190
|
+
* stopped it sent into a network the browser called down.
|
|
191
|
+
* navigator.onLine is what the two events report, so it is what is
|
|
192
|
+
* read. The `online` event is when to send at once; the timed flush
|
|
193
|
+
* finds the network back when no event said so.
|
|
194
|
+
*/
|
|
195
|
+
private get online();
|
|
86
196
|
private started;
|
|
87
197
|
/** The stamp the next queued event gets; see enqueue(). */
|
|
88
198
|
private nextSeq;
|
|
89
199
|
/** Set by a drain request that arrived while a flush was running. */
|
|
90
200
|
private drainPending;
|
|
201
|
+
/** Set by hold(): nothing is sent until release(). */
|
|
202
|
+
private holding;
|
|
203
|
+
/**
|
|
204
|
+
* Full batches enqueue() asked for while a flight was out, which the run
|
|
205
|
+
* under way owes: one batch each, sent as its flight settles (run()).
|
|
206
|
+
*/
|
|
207
|
+
private asked;
|
|
91
208
|
/**
|
|
92
|
-
*
|
|
93
|
-
* browser said it was offline
|
|
94
|
-
*
|
|
209
|
+
* A DRAIN IS OWED: an event over the keepalive quota was queued while
|
|
210
|
+
* the browser said it was offline. The next thing that sends -- the
|
|
211
|
+
* `online` handler, or a timed flush that finds the browser online --
|
|
212
|
+
* then drains instead of taking one batch. Cleared once the queue has
|
|
213
|
+
* run empty. (A drain that failed is owed by the outage it starts or
|
|
214
|
+
* continues: the upload that ends it drains; see run()'s catch.)
|
|
95
215
|
*/
|
|
96
216
|
private rushDeferred;
|
|
217
|
+
/** Ends the wait of a sender that is between two attempts; see backoff(). */
|
|
218
|
+
private wakeSender;
|
|
97
219
|
private inflightKeepaliveBytes;
|
|
98
220
|
/**
|
|
99
221
|
* Bytes of a request carrying no events: the fixed cost every request
|
|
@@ -103,25 +225,77 @@ export declare class Transport {
|
|
|
103
225
|
/** Set by the first event JSON.stringify refused; see reportUnserialisable(). */
|
|
104
226
|
private reportedUnserialisable;
|
|
105
227
|
private reportedOversized;
|
|
228
|
+
private reportedScrubOversized;
|
|
229
|
+
private reportedNavigationUnwrapped;
|
|
106
230
|
/**
|
|
107
|
-
* Each queued event's JSON bytes, measured once at
|
|
108
|
-
* keepalive rush needs the number there anyway)
|
|
109
|
-
* cut is sized
|
|
231
|
+
* Each queued event's JSON and its bytes, written and measured once at
|
|
232
|
+
* enqueue (the keepalive rush needs the number there anyway): the bytes
|
|
233
|
+
* read wherever a cut is sized (the timed flight, the unload flush, the
|
|
234
|
+
* byte cap), the JSON joined into its flight's body (body()) and never
|
|
235
|
+
* written again. Let go once a flight carries it: the flight keeps its
|
|
236
|
+
* body and its bytes.
|
|
110
237
|
*/
|
|
111
|
-
private readonly
|
|
238
|
+
private readonly jsonOf;
|
|
112
239
|
/** The batch run() is working on, so the unload flush can take it back. */
|
|
113
240
|
private inFlight;
|
|
114
|
-
constructor(config: TransportConfig);
|
|
115
241
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
|
|
121
|
-
|
|
242
|
+
* At least the bytes held unsent (MAX_QUEUE_BYTES): set to the exact
|
|
243
|
+
* sum by fit(), raised by everything that adds to the queue or the retry
|
|
244
|
+
* queue, and never lowered by what leaves them, so it can only be over.
|
|
245
|
+
* fit() counts again only when it is over the cap.
|
|
246
|
+
*/
|
|
247
|
+
private held;
|
|
248
|
+
/**
|
|
249
|
+
* The JSON bytes of what `queue` holds, kept exactly at every change of
|
|
250
|
+
* it (each event's size is measured once, at enqueue): what the unload
|
|
251
|
+
* flush would have to carry. O(1) an event; never a walk of the queue.
|
|
122
252
|
*/
|
|
253
|
+
private queued;
|
|
254
|
+
/**
|
|
255
|
+
* The next flight is the counter's: the queue went past the share, and
|
|
256
|
+
* no drain was asked. It is capped at the share (formFlight).
|
|
257
|
+
*/
|
|
258
|
+
private counted;
|
|
259
|
+
/** Flights that spent their attempts since one was last accepted; 0 when uploads work. */
|
|
260
|
+
private failures;
|
|
261
|
+
/** performance.now() before which no flight starts on the timer's or an enqueue's say; see OUTAGE_FIRST_MS. */
|
|
262
|
+
private notBefore;
|
|
263
|
+
constructor(config: TransportConfig);
|
|
123
264
|
private fail;
|
|
124
265
|
start(sessionId: string, metadata: SessionMetadata, captureIdentity?: CaptureIdentity | null): void;
|
|
266
|
+
/**
|
|
267
|
+
* HELD: nothing is sent until release(). The capture holds its transport
|
|
268
|
+
* while rrweb's import waits for the network; if that import then
|
|
269
|
+
* fails, the capture is refused, and what was queued meanwhile -- the
|
|
270
|
+
* page's offline calls -- must not reach the server as a session with
|
|
271
|
+
* no DOM. stop() while held sends nothing and drops what was held.
|
|
272
|
+
*/
|
|
273
|
+
hold(): void;
|
|
274
|
+
/**
|
|
275
|
+
* Sends ALL that was held, batch after batch, and from now on as it
|
|
276
|
+
* comes. All of it, whatever asked: one batch left the rest for the
|
|
277
|
+
* timer, and the FullSnapshot of a page started offline sat behind the
|
|
278
|
+
* page's offline calls -- with them, more than a leaving document's one
|
|
279
|
+
* request can carry -- so a visitor who left within seconds of
|
|
280
|
+
* reconnecting was recorded with no DOM (found in review #28, MEASURED
|
|
281
|
+
* in Chromium). A first fix kept only a drain something had asked for
|
|
282
|
+
* while held, which a snapshot under the keepalive quota never does.
|
|
283
|
+
*
|
|
284
|
+
* What comes AFTER is sent as the browser's state allows, read each
|
|
285
|
+
* time (`online`). A release says rrweb's import was answered, which
|
|
286
|
+
* for a transport started offline is most often the network being back
|
|
287
|
+
* -- and the `online` event that would say so need not reach this
|
|
288
|
+
* transport: the page resumed its capture from a listener of its own
|
|
289
|
+
* that stops the event. Believing the browser offline until an event
|
|
290
|
+
* said otherwise, the transport sent what it had held and nothing after
|
|
291
|
+
* it until the page was left (found in review #29, MEASURED in
|
|
292
|
+
* Chromium). Read, not assumed: a service worker that took control
|
|
293
|
+
* after start() answers the import with the network still down, and
|
|
294
|
+
* what comes after waits for the network there as it did.
|
|
295
|
+
*/
|
|
296
|
+
release(): void;
|
|
297
|
+
/** Drops what is queued and what waits to be re-sent, unsent. */
|
|
298
|
+
discard(): void;
|
|
125
299
|
/**
|
|
126
300
|
* Stop accepting events and send what is queued.
|
|
127
301
|
*
|
|
@@ -130,46 +304,59 @@ export declare class Transport {
|
|
|
130
304
|
* can await it; nothing requires it.
|
|
131
305
|
*/
|
|
132
306
|
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
307
|
private disarmWhenDrained;
|
|
147
308
|
enqueue(event: SessionEvent): void;
|
|
148
309
|
/**
|
|
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.
|
|
310
|
+
* A place in the session, taken now for an event queued later: a
|
|
311
|
+
* fetch's, reported when its body ends and recorded in a task after
|
|
312
|
+
* the page's (NetworkInterceptor.emit). Its seq is the one it would
|
|
313
|
+
* have been stamped with, recorded there, so the server orders the
|
|
314
|
+
* session as it did.
|
|
163
315
|
*/
|
|
164
|
-
|
|
316
|
+
place(): number;
|
|
317
|
+
/** Uploads are failing and the wait before the next flight is not over. */
|
|
318
|
+
private get paced();
|
|
319
|
+
/**
|
|
320
|
+
* Holds what is unsent at MAX_QUEUE_BYTES, dropping the oldest first:
|
|
321
|
+
* waiting flights whole, then queued events. fit() never drops the
|
|
322
|
+
* newest -- enqueue() admits none over MAX_BATCH_BYTES, which is under
|
|
323
|
+
* the cap -- though dropped() may, as it takes any incremental read
|
|
324
|
+
* against a DOM event that went. What goes is said (dropped()), so the recorder knows
|
|
325
|
+
* of the hole a DOM event leaves.
|
|
326
|
+
*/
|
|
327
|
+
private fit;
|
|
165
328
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
329
|
+
* Said to the owner (TransportConfig.onDropped): events dropped unsent.
|
|
330
|
+
* A dropped DOM event takes with it the rrweb incrementals still queued
|
|
331
|
+
* behind it up to the next FullSnapshot: each is read against what the
|
|
332
|
+
* dropped event held, and posted, a click on a button the dropped
|
|
333
|
+
* snapshot held was resolved to `body` (found in review #23). A
|
|
334
|
+
* FullSnapshot is never dropped ahead of its incrementals.
|
|
171
335
|
*/
|
|
336
|
+
private dropped;
|
|
337
|
+
private reportUnserialisable;
|
|
172
338
|
private reportOversized;
|
|
339
|
+
/**
|
|
340
|
+
* Say that the recorder dropped an event because scrubbing the page
|
|
341
|
+
* URL's credentials out of it passed the server's decoded cap (privacy.ts
|
|
342
|
+
* ScrubOverCap) -- ONCE per transport, like reportOversized. The event
|
|
343
|
+
* never reached the queue, so it has no id; `atLeast` is a lower bound of
|
|
344
|
+
* the scrubbed event's size: what the scrub had written when it stopped,
|
|
345
|
+
* less what a later replacement could still take off it.
|
|
346
|
+
*/
|
|
347
|
+
reportScrubOversized(eventType: SessionEvent["type"], atLeast: number, cap: number): void;
|
|
348
|
+
/**
|
|
349
|
+
* Say that the page made a History or Navigation API method the SDK wraps
|
|
350
|
+
* impossible to replace and put back, so the recorder wrapped none
|
|
351
|
+
* (recorder.ts wrapHistory) -- ONCE per transport, like
|
|
352
|
+
* reportScrubOversized. Nothing is dropped: route changes are still
|
|
353
|
+
* recorded, with less detail (recorder.ts, ALL OR NOTHING).
|
|
354
|
+
*/
|
|
355
|
+
reportNavigationUnwrapped(method: string): void;
|
|
356
|
+
/** The console line for an event too large to send: once per code, as each caller decides. */
|
|
357
|
+
private warnOversized;
|
|
358
|
+
/** One console line; each caller says its code once per capture. */
|
|
359
|
+
private warn;
|
|
173
360
|
/** The request body for `events`, with everything a batch carries. */
|
|
174
361
|
private payload;
|
|
175
362
|
/**
|
|
@@ -188,6 +375,14 @@ export declare class Transport {
|
|
|
188
375
|
*/
|
|
189
376
|
flush(drain?: boolean): Promise<void>;
|
|
190
377
|
private run;
|
|
378
|
+
/**
|
|
379
|
+
* The wait before the next attempt, ENDED BY `online`: the network
|
|
380
|
+
* being back is what the wait was for, and a sender that slept on
|
|
381
|
+
* sent nothing for up to 2 s more while the page's visitor was
|
|
382
|
+
* leaving (found in review #29). One sender runs at a time, so one
|
|
383
|
+
* wait is pending at most.
|
|
384
|
+
*/
|
|
385
|
+
private backoff;
|
|
191
386
|
private sendWithRetry;
|
|
192
387
|
/**
|
|
193
388
|
* The last flush, issued while the document is being torn down.
|
|
@@ -222,11 +417,11 @@ export declare class Transport {
|
|
|
222
417
|
* a document that survives its pagehide (a back/forward-cache entry)
|
|
223
418
|
* and later ships the held-back event from its timer is stored in
|
|
224
419
|
* 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,
|
|
420
|
+
* rebuilds the DOM from the FullSnapshot and the mutations after it,
|
|
421
|
+
* and every incremental event behind a snapshot names its nodes by
|
|
422
|
+
* that snapshot's ids. Shipped without it, they are resolved against
|
|
423
|
+
* a DOM that does not hold their nodes, and selectorFromNode answers
|
|
424
|
+
* `body` for a node it cannot find — a click on `body` in the generated test, silently,
|
|
230
425
|
* where the session ending at the snapshot would have been the
|
|
231
426
|
* truth. So what does not fit holds back what depends on it.
|
|
232
427
|
*
|
|
@@ -236,97 +431,41 @@ export declare class Transport {
|
|
|
236
431
|
* leaving. Which is why an event that can never fit is not left to
|
|
237
432
|
* wait here: enqueue() sends it as soon as it is queued.
|
|
238
433
|
*/
|
|
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
434
|
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
435
|
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
436
|
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
437
|
/**
|
|
301
|
-
* The
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
438
|
+
* The POST body for `events`: JSON.stringify(this.payload(events,
|
|
439
|
+
* batchId)), the same text, with each event's JSON as enqueue() wrote
|
|
440
|
+
* it, joined. The envelope is written with no events; its
|
|
441
|
+
* `"events":[]` is the first, since only the session and batch ids,
|
|
442
|
+
* strings, come before it, and no string's JSON holds a bare `"`. An
|
|
443
|
+
* event with no JSON kept (one a flight carried, taken back at
|
|
444
|
+
* pagehide) is written now.
|
|
307
445
|
*/
|
|
446
|
+
private body;
|
|
447
|
+
/** The event's JSON bytes: what enqueue() measured, or measured now for one a flight carried and pagehide took back. */
|
|
448
|
+
private eventBytes;
|
|
308
449
|
private mintBatchId;
|
|
450
|
+
/** Takes `events` off the queued bytes (`sign` -1: puts them back). */
|
|
451
|
+
private uncount;
|
|
452
|
+
/** The queue is past what the unload request can carry: O(1), from the counters. */
|
|
453
|
+
private pastShare;
|
|
309
454
|
/** Events waiting to be sent, retry flights included. */
|
|
310
455
|
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
456
|
private trimToCapacity;
|
|
322
457
|
private flushOnUnload;
|
|
323
458
|
/** One fire-and-forget keepalive POST, accounted against the quota. */
|
|
324
459
|
private postKeepalive;
|
|
325
460
|
private handleOnline;
|
|
326
|
-
private handleOffline;
|
|
327
461
|
private handleUnload;
|
|
328
462
|
private handleVisibility;
|
|
329
|
-
/**
|
|
463
|
+
/**
|
|
464
|
+
* Events waiting their turn: the queue, and flights waiting to be
|
|
465
|
+
* re-sent. NOT a batch already taken off the queue and being compressed
|
|
466
|
+
* or on the wire, so 0 does not mean everything was sent -- await
|
|
467
|
+
* stop() for that.
|
|
468
|
+
*/
|
|
330
469
|
get queueSize(): number;
|
|
331
470
|
}
|
|
332
471
|
export {};
|