@cedarai/session-replay-sdk 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +27 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ function isCompressionSupported() {
24
24
 
25
25
  // src/transport.ts
26
26
  var BEACON_MAX_SIZE = 64 * 1024;
27
+ var MAX_QUEUE_LENGTH = 1e3;
27
28
  var Transport = class {
28
29
  config;
29
30
  queue = [];
@@ -65,6 +66,9 @@ var Transport = class {
65
66
  enqueue(event) {
66
67
  if (!this.started) return;
67
68
  this.queue.push(event);
69
+ if (this.queue.length > MAX_QUEUE_LENGTH) {
70
+ this.queue.splice(0, this.queue.length - MAX_QUEUE_LENGTH);
71
+ }
68
72
  const maxSize = this.config.batchMaxSize ?? 1024 * 512;
69
73
  const estimatedSize = this.estimateQueueSize();
70
74
  if (estimatedSize >= maxSize) {
@@ -294,6 +298,7 @@ var ErrorCapture = class {
294
298
 
295
299
  // src/network.ts
296
300
  var nextId = 0;
301
+ var RESPONSE_BODY_MAX_SIZE = 100 * 1024;
297
302
  var NetworkCapture = class {
298
303
  onEvent;
299
304
  serverUrl;
@@ -330,10 +335,16 @@ var NetworkCapture = class {
330
335
  const response = await this.originalFetch(input, init);
331
336
  const endTime = performance.now();
332
337
  let responseBody;
333
- try {
334
- const cloned = response.clone();
335
- responseBody = await cloned.text();
336
- } catch {
338
+ const contentLength = parseInt(response.headers.get("content-length") ?? "0", 10);
339
+ if (contentLength === 0 || contentLength <= RESPONSE_BODY_MAX_SIZE) {
340
+ try {
341
+ const cloned = response.clone();
342
+ const text = await cloned.text();
343
+ if (text.length <= RESPONSE_BODY_MAX_SIZE) {
344
+ responseBody = text;
345
+ }
346
+ } catch {
347
+ }
337
348
  }
338
349
  this.onEvent({
339
350
  type: "network",
@@ -385,6 +396,16 @@ var NetworkCapture = class {
385
396
 
386
397
  // src/recorder.ts
387
398
  import { record } from "rrweb";
399
+ var DEFAULT_SAMPLING = {
400
+ mousemove: 50,
401
+ // throttle mousemove to one event per 50ms (default is every frame)
402
+ mouseInteraction: true,
403
+ // keep mouse clicks/interactions
404
+ scroll: 150,
405
+ // throttle scroll to one event per 150ms
406
+ input: "last"
407
+ // only capture the final input value, not every keystroke
408
+ };
388
409
  var RecorderCapture = class {
389
410
  onEvent;
390
411
  config;
@@ -398,6 +419,7 @@ var RecorderCapture = class {
398
419
  if (this.started) return;
399
420
  this.started = true;
400
421
  const { checkoutEveryNms, blockSelector, maskAllInputs, inlineStylesheet, sampling } = this.config;
422
+ const mergedSampling = { ...DEFAULT_SAMPLING, ...sampling };
401
423
  const result = record({
402
424
  emit: (event) => {
403
425
  if (!this.started) return;
@@ -410,7 +432,7 @@ var RecorderCapture = class {
410
432
  ...blockSelector !== void 0 && { blockSelector },
411
433
  ...maskAllInputs !== void 0 && { maskAllInputs },
412
434
  ...inlineStylesheet !== void 0 && { inlineStylesheet },
413
- ...sampling !== void 0 && { sampling }
435
+ sampling: mergedSampling
414
436
  });
415
437
  this.stopFn = result ?? null;
416
438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarai/session-replay-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",