@coralogix/browser 3.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.1.0 (2026-01-25)
2
+
3
+ ### 🚀 Features
4
+ - Add optimized mutation handling in session recorder
5
+
1
6
  ## 3.0.2 (2026-01-20)
2
7
 
3
8
  ### 🩹 Fixes
package/index.esm2.js CHANGED
@@ -212,7 +212,7 @@ var BATCH_TIME_DELAY = 1000;
212
212
  var SESSION_RECORDING_POSTFIX_URL = '/browser/alpha/sessionrecording';
213
213
  var SESSION_KEY = 'rum_session';
214
214
  var PREV_SESSION_KEY = 'rum_prev_session';
215
- var MAX_MUTATIONS_FOR_SESSION_RECORDING = 5000;
215
+ var MUTATION_LIMIT = 10000;
216
216
  var DEFAULT_SESSION_CONFIG = {
217
217
  sessionSampleRate: 100,
218
218
  onlyWithErrorConfig: {
@@ -4138,7 +4138,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
4138
4138
  return resolvedUrlBlueprinters;
4139
4139
  }
4140
4140
 
4141
- var SDK_VERSION = '3.0.2';
4141
+ var SDK_VERSION = '3.1.0';
4142
4142
 
4143
4143
  function shouldDropEvent(cxRumEvent, options) {
4144
4144
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -5089,4 +5089,4 @@ var SessionRecordingEventType;
5089
5089
  SessionRecordingEventType[SessionRecordingEventType["Plugin"] = 6] = "Plugin";
5090
5090
  })(SessionRecordingEventType || (SessionRecordingEventType = {}));
5091
5091
 
5092
- export { BATCH_TIME_DELAY as B, CxGlobal as C, MAX_BATCH_TIME_MS as M, OtelNetworkAttrs as O, PerformanceTypes as P, Request as R, SESSION_RECORDER_SEGMENTS_MAP as S, UrlBasedLabelProvider as U, getNowTime as a, SESSION_RECORDING_NETWORK_ERR0R_MESSAGE as b, SESSION_RECORDING_DEFAULT_HEADERS as c, SESSION_RECORDING_POSTFIX_URL as d, SESSION_RECORDER_KEY as e, MAX_MUTATIONS_FOR_SESSION_RECORDING as f, getSdkConfig as g, SESSION_RECORDING_DEFAULT_ERROR_MESSAGE as h, CoralogixRum as i, CoralogixLogSeverity as j, SessionRecordingEventType as k, CoralogixEventType as l, UrlType as m, reportInternalEvent as r };
5092
+ export { BATCH_TIME_DELAY as B, CxGlobal as C, MAX_BATCH_TIME_MS as M, OtelNetworkAttrs as O, PerformanceTypes as P, Request as R, SESSION_RECORDER_SEGMENTS_MAP as S, UrlBasedLabelProvider as U, getNowTime as a, SESSION_RECORDING_NETWORK_ERR0R_MESSAGE as b, SESSION_RECORDING_DEFAULT_HEADERS as c, SESSION_RECORDING_POSTFIX_URL as d, SESSION_RECORDER_KEY as e, MUTATION_LIMIT as f, getSdkConfig as g, SESSION_RECORDING_DEFAULT_ERROR_MESSAGE as h, CoralogixRum as i, CoralogixLogSeverity as j, SessionRecordingEventType as k, CoralogixEventType as l, UrlType as m, reportInternalEvent as r };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -1,5 +1,5 @@
1
1
  import { __awaiter, __generator, __assign } from 'tslib';
2
- import { C as CxGlobal, r as reportInternalEvent, g as getSdkConfig, S as SESSION_RECORDER_SEGMENTS_MAP, a as getNowTime, b as SESSION_RECORDING_NETWORK_ERR0R_MESSAGE, M as MAX_BATCH_TIME_MS, R as Request, c as SESSION_RECORDING_DEFAULT_HEADERS, d as SESSION_RECORDING_POSTFIX_URL, B as BATCH_TIME_DELAY, e as SESSION_RECORDER_KEY, f as MAX_MUTATIONS_FOR_SESSION_RECORDING, h as SESSION_RECORDING_DEFAULT_ERROR_MESSAGE } from './index.esm2.js';
2
+ import { C as CxGlobal, g as getSdkConfig, S as SESSION_RECORDER_SEGMENTS_MAP, a as getNowTime, b as SESSION_RECORDING_NETWORK_ERR0R_MESSAGE, M as MAX_BATCH_TIME_MS, R as Request, c as SESSION_RECORDING_DEFAULT_HEADERS, d as SESSION_RECORDING_POSTFIX_URL, B as BATCH_TIME_DELAY, r as reportInternalEvent, e as SESSION_RECORDER_KEY, f as MUTATION_LIMIT, h as SESSION_RECORDING_DEFAULT_ERROR_MESSAGE } from './index.esm2.js';
3
3
  import { record } from 'rrweb';
4
4
  import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record';
5
5
  import '@opentelemetry/sdk-trace-base';
@@ -1484,6 +1484,15 @@ var SessionRecorder = (function () {
1484
1484
  this.isErrorOccurred = false;
1485
1485
  this.debugMode = !!((_a = getSdkConfig()) === null || _a === void 0 ? void 0 : _a.debug);
1486
1486
  this._recordingStopDueToTimeout = false;
1487
+ this.onMutation = function (mutations) {
1488
+ var mutationsCount = _this.getMutationCount(mutations);
1489
+ if (mutationsCount > _this.maxMutations) {
1490
+ var message = "Recording stopped: mutation-limit exceeded - mutations: ".concat(mutationsCount, ", limit: ").concat(_this.maxMutations);
1491
+ console.warn("Coralogix Browser SDK - ".concat(message));
1492
+ reportInternalEvent('recording-stop', message);
1493
+ _this.stopRecording();
1494
+ }
1495
+ };
1487
1496
  this.handleRecordEvent = function (event, isCheckout) {
1488
1497
  if (!_this.recordingStopped) {
1489
1498
  if (_this.onlySessionWithErrorMode) {
@@ -1554,7 +1563,7 @@ var SessionRecorder = (function () {
1554
1563
  this.onlySessionWithErrorMode = onlySessionWithErrorMode;
1555
1564
  this.maxRecordTimeForSessionWithError = maxRecordTimeForSessionWithError;
1556
1565
  this.isAutoStartRecording = autoStartSessionRecording;
1557
- this.maxMutations = maxMutations !== null && maxMutations !== void 0 ? maxMutations : MAX_MUTATIONS_FOR_SESSION_RECORDING;
1566
+ this.maxMutations = maxMutations !== null && maxMutations !== void 0 ? maxMutations : MUTATION_LIMIT;
1558
1567
  this.recordConfig = this.prepareRecordConfig(recordConfig);
1559
1568
  if (CxGlobal.Worker) {
1560
1569
  this.workerManager = new WorkerManager();
@@ -1606,7 +1615,6 @@ var SessionRecorder = (function () {
1606
1615
  if (this.debugMode) {
1607
1616
  console.debug('Coralogix Browser SDK - Session recording started');
1608
1617
  }
1609
- this.startMutationObserver();
1610
1618
  this.resetBatching();
1611
1619
  this.recordingStopped = false;
1612
1620
  this.isErrorOccurred = false;
@@ -1645,31 +1653,12 @@ var SessionRecorder = (function () {
1645
1653
  this.hasRecording = false;
1646
1654
  this.prepareRecordEventsBeforeSend();
1647
1655
  this.clearIntervals();
1648
- this.stopMutationObserver();
1649
- };
1650
- SessionRecorder.prototype.stopMutationObserver = function () {
1651
- var _a;
1652
- (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
1653
1656
  };
1654
- SessionRecorder.prototype.startMutationObserver = function () {
1655
- var _this = this;
1656
- this.stopMutationObserver();
1657
- this.mutationObserver = new MutationObserver(function (mutations) {
1658
- if (mutations.length > _this.maxMutations) {
1659
- var message = "Coralogix Browser SDK - Recording stopped due to too many mutations ".concat(mutations.length);
1660
- console.warn(message);
1661
- reportInternalEvent('recording-stop', message);
1662
- _this.stopRecording();
1663
- }
1664
- });
1665
- this.mutationObserver.observe(document, {
1666
- attributes: false,
1667
- attributeOldValue: false,
1668
- characterData: false,
1669
- characterDataOldValue: false,
1670
- childList: true,
1671
- subtree: true,
1672
- });
1657
+ SessionRecorder.prototype.getMutationCount = function (mutations) {
1658
+ return (mutations.adds.length +
1659
+ mutations.removes.length +
1660
+ mutations.attributes.length +
1661
+ mutations.texts.length);
1673
1662
  };
1674
1663
  SessionRecorder.prototype.clearIntervals = function () {
1675
1664
  if (this.batchingTimeInterval) {
@@ -1679,7 +1668,9 @@ var SessionRecorder = (function () {
1679
1668
  SessionRecorder.prototype.prepareRecordConfig = function (recordConfig) {
1680
1669
  var _a;
1681
1670
  var _b = recordConfig || {}, excludeDOMOptions = _b.excludeDOMOptions, recordConsoleEvents = _b.recordConsoleEvents;
1682
- this.recordConfig = __assign(__assign({}, recordConfig), { emit: this.handleRecordEvent, checkoutEveryNms: this.onlySessionWithErrorMode
1671
+ this.recordConfig = __assign(__assign({}, recordConfig), { emit: this.handleRecordEvent, hooks: {
1672
+ mutation: this.onMutation,
1673
+ }, checkoutEveryNms: this.onlySessionWithErrorMode
1683
1674
  ? this.maxRecordTimeForSessionWithError
1684
1675
  : undefined, slimDOMOptions: __assign(__assign({}, excludeDOMOptions), { script: (_a = excludeDOMOptions === null || excludeDOMOptions === void 0 ? void 0 : excludeDOMOptions.script) !== null && _a !== void 0 ? _a : true }), plugins: recordConsoleEvents ? [getRecordConsolePlugin()] : [] });
1685
1676
  return this.recordConfig;
@@ -7,7 +7,7 @@ export declare const BATCH_TIME_DELAY: number;
7
7
  export declare const SESSION_RECORDING_POSTFIX_URL = "/browser/alpha/sessionrecording";
8
8
  export declare const SESSION_KEY: string;
9
9
  export declare const PREV_SESSION_KEY: string;
10
- export declare const MAX_MUTATIONS_FOR_SESSION_RECORDING: number;
10
+ export declare const MUTATION_LIMIT: number;
11
11
  export declare const DEFAULT_SESSION_CONFIG: SessionConfig;
12
12
  export declare const SESSION_IDLE_TIME: number;
13
13
  export declare const SESSION_EXPIRATION_TIME: number;
@@ -21,7 +21,6 @@ export declare class SessionRecorder {
21
21
  private isErrorOccurred;
22
22
  private debugMode;
23
23
  private _recordingStopDueToTimeout;
24
- private mutationObserver;
25
24
  private request;
26
25
  private workerManager;
27
26
  private isWorkerReady;
@@ -35,8 +34,8 @@ export declare class SessionRecorder {
35
34
  startRecording(): Promise<void>;
36
35
  screenshot(id: string): void;
37
36
  stopRecording(): void;
38
- private stopMutationObserver;
39
- private startMutationObserver;
37
+ private onMutation;
38
+ private getMutationCount;
40
39
  private clearIntervals;
41
40
  private prepareRecordConfig;
42
41
  private handleRecordEvent;
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "3.0.2";
1
+ export declare const SDK_VERSION = "3.1.0";