@cloudcare/browser-rum 2.2.15 → 3.0.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 (166) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +161 -0
  4. package/cjs/boot/rum.entry.js +6 -1
  5. package/cjs/boot/rum.js +15 -5
  6. package/cjs/boot/rumPublicApi.js +8 -4
  7. package/cjs/boot/startRecording.js +55 -0
  8. package/cjs/constants.js +52 -0
  9. package/cjs/domain/assembly.js +1 -7
  10. package/cjs/domain/configuration.js +3 -2
  11. package/cjs/domain/contexts/foregroundContexts.js +138 -0
  12. package/cjs/domain/contexts/internalContext.js +1 -1
  13. package/cjs/domain/contexts/urlContexts.js +9 -2
  14. package/cjs/domain/domMutationCollection.js +4 -5
  15. package/cjs/domain/initViewportObservable.js +52 -0
  16. package/cjs/domain/locationChangeObservable.js +12 -26
  17. package/cjs/domain/performanceCollection.js +2 -13
  18. package/cjs/domain/replay/record/elementsScrollPositions.js +27 -0
  19. package/cjs/domain/replay/record/index.js +41 -0
  20. package/cjs/domain/replay/record/mutationBatch.js +58 -0
  21. package/cjs/domain/replay/record/mutationObserver.js +383 -0
  22. package/cjs/domain/replay/record/observers.js +473 -0
  23. package/cjs/domain/replay/record/privacy.js +256 -0
  24. package/cjs/domain/replay/record/record.js +174 -0
  25. package/cjs/domain/replay/record/serializationUtils.js +137 -0
  26. package/cjs/domain/replay/record/serialize.js +488 -0
  27. package/cjs/domain/replay/record/shadowRootsController.js +61 -0
  28. package/cjs/domain/replay/record/utils.js +53 -0
  29. package/cjs/domain/replay/record/viewports.js +104 -0
  30. package/cjs/domain/replay/replayStats.js +83 -0
  31. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +43 -0
  32. package/cjs/domain/replay/segmentCollection/deflateWorker.js +4399 -0
  33. package/cjs/domain/replay/segmentCollection/index.js +33 -0
  34. package/cjs/domain/replay/segmentCollection/segment.js +101 -0
  35. package/cjs/domain/replay/segmentCollection/segmentCollection.js +179 -0
  36. package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +126 -0
  37. package/cjs/domain/requestCollection.js +35 -17
  38. package/cjs/domain/rumEventsCollection/actions/actionCollection.js +12 -4
  39. package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
  40. package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
  41. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +8 -6
  42. package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +111 -75
  43. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
  44. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +94 -54
  45. package/cjs/domain/rumEventsCollection/error/errorCollection.js +13 -5
  46. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +45 -0
  47. package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
  48. package/cjs/domain/rumEventsCollection/view/trackViews.js +21 -18
  49. package/cjs/domain/rumEventsCollection/view/viewCollection.js +12 -9
  50. package/cjs/domain/rumSessionManager.js +6 -3
  51. package/cjs/domain/tracing/getDocumentTraceId.js +2 -10
  52. package/cjs/domain/trackEventCounts.js +10 -2
  53. package/cjs/domain/waitPageActivityEnd.js +5 -1
  54. package/cjs/transport/startRumBatch.js +5 -7
  55. package/cjs/types/index.js +18 -0
  56. package/cjs/types/sessionReplayConstants.js +56 -0
  57. package/esm/boot/buildEnv.js +1 -1
  58. package/esm/boot/recorderApi.js +149 -0
  59. package/esm/boot/rum.entry.js +4 -1
  60. package/esm/boot/rum.js +15 -6
  61. package/esm/boot/rumPublicApi.js +8 -4
  62. package/esm/boot/startRecording.js +44 -0
  63. package/esm/constants.js +31 -0
  64. package/esm/domain/assembly.js +1 -7
  65. package/esm/domain/configuration.js +4 -3
  66. package/esm/domain/contexts/foregroundContexts.js +122 -0
  67. package/esm/domain/contexts/internalContext.js +1 -1
  68. package/esm/domain/contexts/urlContexts.js +10 -3
  69. package/esm/domain/domMutationCollection.js +5 -6
  70. package/esm/domain/initViewportObservable.js +39 -0
  71. package/esm/domain/locationChangeObservable.js +13 -27
  72. package/esm/domain/performanceCollection.js +1 -12
  73. package/esm/domain/replay/record/elementsScrollPositions.js +20 -0
  74. package/esm/domain/replay/record/index.js +3 -0
  75. package/esm/domain/replay/record/mutationBatch.js +35 -0
  76. package/esm/domain/replay/record/mutationObserver.js +331 -0
  77. package/esm/domain/replay/record/observers.js +457 -0
  78. package/esm/domain/replay/record/privacy.js +233 -0
  79. package/esm/domain/replay/record/record.js +158 -0
  80. package/esm/domain/replay/record/serializationUtils.js +107 -0
  81. package/esm/domain/replay/record/serialize.js +461 -0
  82. package/esm/domain/replay/record/shadowRootsController.js +49 -0
  83. package/esm/domain/replay/record/utils.js +38 -0
  84. package/esm/domain/replay/record/viewports.js +87 -0
  85. package/esm/domain/replay/replayStats.js +64 -0
  86. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +31 -0
  87. package/esm/domain/replay/segmentCollection/deflateWorker.js +4390 -0
  88. package/esm/domain/replay/segmentCollection/index.js +3 -0
  89. package/esm/domain/replay/segmentCollection/segment.js +84 -0
  90. package/esm/domain/replay/segmentCollection/segmentCollection.js +158 -0
  91. package/esm/domain/replay/segmentCollection/startDeflateWorker.js +113 -0
  92. package/esm/domain/requestCollection.js +36 -18
  93. package/esm/domain/rumEventsCollection/actions/actionCollection.js +12 -4
  94. package/esm/domain/rumEventsCollection/actions/clickChain.js +3 -3
  95. package/esm/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
  96. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +6 -6
  97. package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +105 -74
  98. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
  99. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +99 -59
  100. package/esm/domain/rumEventsCollection/error/errorCollection.js +13 -5
  101. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +33 -0
  102. package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +1 -18
  103. package/esm/domain/rumEventsCollection/view/trackViews.js +21 -19
  104. package/esm/domain/rumEventsCollection/view/viewCollection.js +12 -9
  105. package/esm/domain/rumSessionManager.js +6 -3
  106. package/esm/domain/tracing/getDocumentTraceId.js +1 -9
  107. package/esm/domain/trackEventCounts.js +10 -2
  108. package/esm/domain/waitPageActivityEnd.js +5 -1
  109. package/esm/transport/startRumBatch.js +5 -7
  110. package/esm/types/index.js +1 -0
  111. package/esm/types/sessionReplayConstants.js +45 -0
  112. package/package.json +3 -3
  113. package/src/boot/recorderApi.js +166 -0
  114. package/src/boot/rum.entry.js +4 -1
  115. package/src/boot/rum.js +38 -10
  116. package/src/boot/rumPublicApi.js +13 -3
  117. package/src/boot/startRecording.js +77 -0
  118. package/src/constants.js +37 -0
  119. package/src/domain/assembly.js +1 -6
  120. package/src/domain/configuration.js +10 -2
  121. package/src/domain/contexts/foregroundContexts.js +140 -0
  122. package/src/domain/contexts/internalContext.js +10 -4
  123. package/src/domain/contexts/urlContexts.js +29 -15
  124. package/src/domain/domMutationCollection.js +14 -6
  125. package/src/domain/initViewportObservable.js +46 -0
  126. package/src/domain/locationChangeObservable.js +17 -25
  127. package/src/domain/performanceCollection.js +42 -42
  128. package/src/domain/replay/record/elementsScrollPositions.js +22 -0
  129. package/src/domain/replay/record/index.js +7 -0
  130. package/src/domain/replay/record/mutationBatch.js +38 -0
  131. package/src/domain/replay/record/mutationObserver.js +393 -0
  132. package/src/domain/replay/record/observers.js +562 -0
  133. package/src/domain/replay/record/privacy.js +304 -0
  134. package/src/domain/replay/record/record.js +158 -0
  135. package/src/domain/replay/record/serializationUtils.js +134 -0
  136. package/src/domain/replay/record/serialize.js +497 -0
  137. package/src/domain/replay/record/shadowRootsController.js +58 -0
  138. package/src/domain/replay/record/utils.js +44 -0
  139. package/src/domain/replay/record/viewports.js +89 -0
  140. package/src/domain/replay/replayStats.js +67 -0
  141. package/src/domain/replay/segmentCollection/buildReplayPayload.js +34 -0
  142. package/src/domain/replay/segmentCollection/deflateWorker.js +4577 -0
  143. package/src/domain/replay/segmentCollection/index.js +6 -0
  144. package/src/domain/replay/segmentCollection/segment.js +87 -0
  145. package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
  146. package/src/domain/replay/segmentCollection/startDeflateWorker.js +101 -0
  147. package/src/domain/requestCollection.js +64 -28
  148. package/src/domain/rumEventsCollection/actions/actionCollection.js +11 -4
  149. package/src/domain/rumEventsCollection/actions/clickChain.js +3 -3
  150. package/src/domain/rumEventsCollection/actions/computeFrustration.js +7 -4
  151. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +9 -6
  152. package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +130 -108
  153. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +26 -27
  154. package/src/domain/rumEventsCollection/actions/trackClickActions.js +162 -92
  155. package/src/domain/rumEventsCollection/error/errorCollection.js +11 -5
  156. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +38 -0
  157. package/src/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
  158. package/src/domain/rumEventsCollection/view/trackViews.js +98 -68
  159. package/src/domain/rumEventsCollection/view/viewCollection.js +15 -7
  160. package/src/domain/rumSessionManager.js +33 -19
  161. package/src/domain/tracing/getDocumentTraceId.js +6 -9
  162. package/src/domain/trackEventCounts.js +10 -4
  163. package/src/domain/waitPageActivityEnd.js +4 -1
  164. package/src/transport/startRumBatch.js +29 -24
  165. package/src/types/index.js +1 -0
  166. package/src/types/sessionReplayConstants.js +49 -0
@@ -1,24 +1,8 @@
1
1
  import { noop, elapsed, round, ONE_SECOND, LifeCycleEventType, ViewLoadingType } from '@cloudcare/browser-core';
2
2
  import { supportPerformanceTimingEvent } from '../../performanceCollection';
3
- import { trackEventCounts } from '../../trackEventCounts';
4
3
  import { waitPageActivityEnd } from '../../waitPageActivityEnd';
5
4
  export function trackViewMetrics(lifeCycle, domMutationObservable, configuration, scheduleViewUpdate, loadingType, viewStart) {
6
- var viewMetrics = {
7
- eventCounts: {
8
- errorCount: 0,
9
- longTaskCount: 0,
10
- resourceCount: 0,
11
- actionCount: 0,
12
- frustrationCount: 0
13
- }
14
- };
15
-
16
- var _trackEventCounts = trackEventCounts(lifeCycle, function (newEventCounts) {
17
- viewMetrics.eventCounts = newEventCounts;
18
- scheduleViewUpdate();
19
- });
20
-
21
- var stopEventCountsTracking = _trackEventCounts.stop;
5
+ var viewMetrics = {};
22
6
 
23
7
  var _trackLoadingTime = trackLoadingTime(lifeCycle, domMutationObservable, configuration, loadingType, viewStart, function (newLoadingTime) {
24
8
  viewMetrics.loadingTime = newLoadingTime;
@@ -44,7 +28,6 @@ export function trackViewMetrics(lifeCycle, domMutationObservable, configuration
44
28
 
45
29
  return {
46
30
  stop: function stop() {
47
- stopEventCountsTracking();
48
31
  stopLoadingTimeTracking();
49
32
  stopCLSTracking();
50
33
  },
@@ -1,6 +1,7 @@
1
- import { shallowClone, assign, elapsed, UUID, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, looksLikeRelativeTime, ViewLoadingType, LifeCycleEventType } from '@cloudcare/browser-core';
1
+ import { shallowClone, assign, elapsed, UUID, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, looksLikeRelativeTime, ViewLoadingType, LifeCycleEventType, PageExitReason, isHashAnAnchor, getPathFromHash } from '@cloudcare/browser-core';
2
2
  import { trackInitialViewTimings } from './trackInitialViewTimings';
3
3
  import { trackViewMetrics } from './trackViewMetrics';
4
+ import { trackViewEventCounts } from './trackViewEventCounts';
4
5
  export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
5
6
  export var SESSION_KEEP_ALIVE_INTERVAL = 5 * ONE_MINUTE;
6
7
  export function trackViews(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, areViewsTrackedAutomatically, initialViewOptions) {
@@ -49,9 +50,11 @@ export function trackViews(location, lifeCycle, domMutationObservable, configura
49
50
  });
50
51
  }); // End the current view on page unload
51
52
 
52
- lifeCycle.subscribe(LifeCycleEventType.BEFORE_UNLOAD, function () {
53
- currentView.end();
54
- currentView.triggerUpdate();
53
+ lifeCycle.subscribe(LifeCycleEventType.PAGE_EXITED, function (pageExitEvent) {
54
+ if (pageExitEvent.reason === PageExitReason.UNLOADING || pageExitEvent.reason === PageExitReason.PAGEHIDE) {
55
+ currentView.end();
56
+ currentView.triggerUpdate();
57
+ }
55
58
  }); // Session keep alive
56
59
 
57
60
  var keepAliveInterval = window.setInterval(function () {
@@ -134,16 +137,23 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
134
137
  version: version
135
138
  }); // Update the view every time the measures are changing
136
139
 
137
- var scheduleViewUpdate = throttle(triggerViewUpdate, THROTTLE_VIEW_UPDATE_PERIOD, {
140
+ var _scheduleViewUpdate = throttle(triggerViewUpdate, THROTTLE_VIEW_UPDATE_PERIOD, {
138
141
  leading: false
139
142
  });
140
- var cancelScheduleViewUpdate = scheduleViewUpdate.cancel;
143
+
144
+ var scheduleViewUpdate = _scheduleViewUpdate.throttled;
145
+ var cancelScheduleViewUpdate = _scheduleViewUpdate.cancel;
141
146
 
142
147
  var _trackViewMetrics = trackViewMetrics(lifeCycle, domMutationObservable, configuration, scheduleViewUpdate, loadingType, startClocks);
143
148
 
144
149
  var setLoadEvent = _trackViewMetrics.setLoadEvent;
145
150
  var stopViewMetricsTracking = _trackViewMetrics.stop;
146
- var viewMetrics = _trackViewMetrics.viewMetrics; // Initial view update
151
+ var viewMetrics = _trackViewMetrics.viewMetrics;
152
+
153
+ var _trackViewEventCounts = trackViewEventCounts(lifeCycle, id, scheduleViewUpdate);
154
+
155
+ var scheduleStopEventCountsTracking = _trackViewEventCounts.scheduleStop;
156
+ var eventCounts = _trackViewEventCounts.eventCounts; // Initial view update
147
157
 
148
158
  triggerViewUpdate();
149
159
 
@@ -162,7 +172,8 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
162
172
  startClocks: startClocks,
163
173
  timings: timings,
164
174
  duration: elapsed(startClocks.timeStamp, currentEnd),
165
- isActive: endClocks === undefined
175
+ isActive: endClocks === undefined,
176
+ eventCounts: eventCounts
166
177
  }, viewMetrics));
167
178
  }
168
179
 
@@ -178,9 +189,10 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
178
189
 
179
190
  endClocks = clocks;
180
191
  lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, {
181
- endClocks
192
+ endClocks: endClocks
182
193
  });
183
194
  stopViewMetricsTracking();
195
+ scheduleStopEventCountsTracking;
184
196
  },
185
197
  triggerUpdate: function triggerUpdate() {
186
198
  // cancel any pending view updates execution
@@ -217,14 +229,4 @@ function sanitizeTiming(name) {
217
229
 
218
230
  function areDifferentLocation(currentLocation, otherLocation) {
219
231
  return currentLocation.pathname !== otherLocation.pathname || !isHashAnAnchor(otherLocation.hash) && getPathFromHash(otherLocation.hash) !== getPathFromHash(currentLocation.hash);
220
- }
221
-
222
- function isHashAnAnchor(hash) {
223
- var correspondingId = hash.substr(1);
224
- return !!document.getElementById(correspondingId);
225
- }
226
-
227
- function getPathFromHash(hash) {
228
- var index = hash.indexOf('?');
229
- return index < 0 ? hash : hash.slice(0, index);
230
232
  }
@@ -1,9 +1,9 @@
1
1
  import { isEmptyObject, mapValues, toServerDuration, isNumber, RumEventType, LifeCycleEventType, extend2Lev } from '@cloudcare/browser-core';
2
2
  import { trackViews } from './trackViews';
3
3
  import { toValidEntry } from '../resource/resourceUtils';
4
- export function startViewCollection(lifeCycle, configuration, location, domMutationObservable, locationChangeObservable, initialViewOptions) {
4
+ export function startViewCollection(lifeCycle, configuration, location, domMutationObservable, locationChangeObservable, foregroundContexts, recorderApi, initialViewOptions) {
5
5
  lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, function (view) {
6
- lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processViewUpdate(view));
6
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processViewUpdate(view, foregroundContexts, recorderApi));
7
7
  });
8
8
  return trackViews(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, !configuration.trackViewsManually, initialViewOptions);
9
9
  }
@@ -58,10 +58,12 @@ function computePerformanceViewDetails(entry) {
58
58
  return details;
59
59
  }
60
60
 
61
- function processViewUpdate(view) {
61
+ function processViewUpdate(view, foregroundContexts, recorderApi) {
62
+ var replayStats = recorderApi.getReplayStats(view.id);
62
63
  var viewEvent = {
63
64
  _dd: {
64
- document_version: view.documentVersion
65
+ document_version: view.documentVersion,
66
+ replay_stats: replayStats
65
67
  },
66
68
  date: view.startClocks.timeStamp,
67
69
  type: RumEventType.VIEW,
@@ -95,11 +97,12 @@ function processViewUpdate(view) {
95
97
  resource: {
96
98
  count: view.eventCounts.resourceCount
97
99
  },
98
- time_spent: toServerDuration(view.duration)
99
- } // session: {
100
- // has_replay: replayStats ? true : undefined,
101
- // },
102
-
100
+ time_spent: toServerDuration(view.duration),
101
+ in_foreground_periods: foregroundContexts.selectInForegroundPeriodsFor(view.startClocks.relative, view.duration)
102
+ },
103
+ session: {
104
+ has_replay: replayStats ? true : undefined
105
+ }
103
106
  };
104
107
 
105
108
  if (!isEmptyObject(view.customTimings)) {
@@ -1,8 +1,8 @@
1
1
  import { performDraw, startSessionManager, LifeCycleEventType } from '@cloudcare/browser-core';
2
2
  export var RUM_SESSION_KEY = 'rum';
3
3
  export var RumSessionPlan = {
4
- LITE: 1,
5
- PREMIUM: 2
4
+ WITHOUT_SESSION_REPLAY: 1,
5
+ WITH_SESSION_REPLAY: 2
6
6
  };
7
7
  export var RumTrackingType = {
8
8
  NOT_TRACKED: '0',
@@ -30,8 +30,11 @@ export function startRumSessionManager(configuration, lifeCycle) {
30
30
  return;
31
31
  }
32
32
 
33
+ var plan = session.trackingType === RumTrackingType.TRACKED_WITH_SESSION_REPLAY ? RumSessionPlan.WITH_SESSION_REPLAY : RumSessionPlan.WITHOUT_SESSION_REPLAY;
33
34
  return {
34
- id: session.id
35
+ id: session.id,
36
+ plan: plan,
37
+ sessionReplayAllowed: plan === RumSessionPlan.WITH_SESSION_REPLAY
35
38
  };
36
39
  }
37
40
  };
@@ -1,4 +1,4 @@
1
- import { findCommaSeparatedValue, ONE_MINUTE } from '@cloudcare/browser-core';
1
+ import { findCommaSeparatedValue, ONE_MINUTE, isCommentNode, isTextNode } from '@cloudcare/browser-core';
2
2
  export var INITIAL_DOCUMENT_OUTDATED_TRACE_ID_THRESHOLD = 2 * ONE_MINUTE;
3
3
  export function getDocumentTraceId(document) {
4
4
  var data = getDocumentTraceDataFromMeta(document) || getDocumentTraceDataFromComment(document);
@@ -76,12 +76,4 @@ function getTraceCommentFromNode(node) {
76
76
  return match[1];
77
77
  }
78
78
  }
79
- }
80
-
81
- function isCommentNode() {
82
- return node.nodeName === '#comment';
83
- }
84
-
85
- function isTextNode(node) {
86
- return node.nodeName === '#text';
87
79
  }
@@ -1,6 +1,10 @@
1
1
  import { noop, RumEventType, LifeCycleEventType } from '@cloudcare/browser-core';
2
- export function trackEventCounts(lifeCycle, callback) {
3
- if (typeof callback === 'undefined') {
2
+ export function trackEventCounts(data) {
3
+ var lifeCycle = data.lifeCycle;
4
+ var isChildEvent = data.isChildEvent;
5
+ var callback = data.onChange;
6
+
7
+ if (callback === undefined) {
4
8
  callback = noop;
5
9
  }
6
10
 
@@ -12,6 +16,10 @@ export function trackEventCounts(lifeCycle, callback) {
12
16
  frustrationCount: 0
13
17
  };
14
18
  var subscription = lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, function (event) {
19
+ if (event.type === RumEventType.VIEW || !isChildEvent(event)) {
20
+ return;
21
+ }
22
+
15
23
  switch (event.type) {
16
24
  case RumEventType.ERROR:
17
25
  eventCounts.errorCount += 1;
@@ -120,8 +120,12 @@ export function createPageActivityObservable(lifeCycle, domMutationObservable, c
120
120
  pendingRequestsCount -= 1;
121
121
  notifyPageActivity();
122
122
  }));
123
- trackWindowOpen(notifyPageActivity);
123
+
124
+ var _trackWindowOpen = trackWindowOpen(notifyPageActivity);
125
+
126
+ var stopTrackingWindowOpen = _trackWindowOpen.stop;
124
127
  return function () {
128
+ stopTrackingWindowOpen();
125
129
  each(subscriptions, function (s) {
126
130
  s.unsubscribe();
127
131
  });
@@ -1,6 +1,6 @@
1
1
  import { Batch, createHttpRequest, LifeCycleEventType, RumEventType } from '@cloudcare/browser-core';
2
- export function startRumBatch(configuration, lifeCycle, reportError) {
3
- var batch = makeRumBatch(configuration, lifeCycle, reportError);
2
+ export function startRumBatch(configuration, lifeCycle, reportError, pageExitObservable) {
3
+ var batch = makeRumBatch(configuration, reportError, pageExitObservable);
4
4
  lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, function (serverRumEvent) {
5
5
  if (serverRumEvent.type === RumEventType.VIEW) {
6
6
  batch.upsert(serverRumEvent, serverRumEvent.view.id);
@@ -10,13 +10,11 @@ export function startRumBatch(configuration, lifeCycle, reportError) {
10
10
  });
11
11
  }
12
12
 
13
- function makeRumBatch(configuration, lifeCycle, reportError) {
14
- var primaryBatch = createRumBatch(configuration.datakitUrl, function () {
15
- lifeCycle.notify(LifeCycleEventType.BEFORE_UNLOAD);
16
- });
13
+ function makeRumBatch(configuration, reportError, pageExitObservable) {
14
+ var primaryBatch = createRumBatch(configuration.datakitUrl);
17
15
 
18
16
  function createRumBatch(endpointUrl, unloadCallback) {
19
- return new Batch(createHttpRequest(endpointUrl, configuration.batchBytesLimit, reportError), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout, unloadCallback);
17
+ return new Batch(createHttpRequest(endpointUrl, configuration.batchBytesLimit, reportError), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout, pageExitObservable);
20
18
  }
21
19
 
22
20
  return {
@@ -0,0 +1 @@
1
+ export * from './sessionReplayConstants';
@@ -0,0 +1,45 @@
1
+ export var RecordType = {
2
+ FullSnapshot: 2,
3
+ IncrementalSnapshot: 3,
4
+ Meta: 4,
5
+ Focus: 6,
6
+ ViewEnd: 7,
7
+ VisualViewport: 8,
8
+ FrustrationRecord: 9
9
+ };
10
+ export var NodeType = {
11
+ Document: 0,
12
+ DocumentType: 1,
13
+ Element: 2,
14
+ Text: 3,
15
+ CDATA: 4,
16
+ DocumentFragment: 11
17
+ };
18
+ export var IncrementalSource = {
19
+ Mutation: 0,
20
+ MouseMove: 1,
21
+ MouseInteraction: 2,
22
+ Scroll: 3,
23
+ ViewportResize: 4,
24
+ Input: 5,
25
+ TouchMove: 6,
26
+ MediaInteraction: 7,
27
+ StyleSheetRule: 8 // CanvasMutation : 9,
28
+ // Font : 10,
29
+
30
+ };
31
+ export var MouseInteractionType = {
32
+ MouseUp: 0,
33
+ MouseDown: 1,
34
+ Click: 2,
35
+ ContextMenu: 3,
36
+ DblClick: 4,
37
+ Focus: 5,
38
+ Blur: 6,
39
+ TouchStart: 7,
40
+ TouchEnd: 9
41
+ };
42
+ export var MediaInteractionType = {
43
+ Play: 0,
44
+ Pause: 1
45
+ };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@cloudcare/browser-rum",
3
- "version": "2.2.15",
3
+ "version": "3.0.0",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "dependencies": {
7
- "@cloudcare/browser-core": "1.2.11"
7
+ "@cloudcare/browser-core": "2.0.0"
8
8
  },
9
9
  "scripts": {
10
10
  "dev": "webpack serve --open --mode=development",
@@ -29,5 +29,5 @@
29
29
  "license": "MIT",
30
30
  "homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
31
31
  "description": "DataFlux RUM Web 端数据指标监控",
32
- "gitHead": "7a7a643e72002ffafff9ce0f6c1b1c2f904eeebe"
32
+ "gitHead": "bc7a044056367a5f9a0bc941462cb4e1d4d1d925"
33
33
  }
@@ -0,0 +1,166 @@
1
+ import {
2
+ noop,
3
+ runOnReadyState,
4
+ LifeCycleEventType
5
+ } from '@cloudcare/browser-core'
6
+
7
+ import { getReplayStats } from '../domain/replay/replayStats'
8
+ import { startDeflateWorker } from '../domain/replay/segmentCollection'
9
+
10
+ var RecorderStatus = {
11
+ // The recorder is stopped.
12
+ Stopped: 0,
13
+ // The user started the recording while it wasn't possible yet. The recorder should start as soon
14
+ // as possible.
15
+ IntentToStart: 1,
16
+ // The recorder is starting. It does not record anything yet.
17
+ Starting: 2,
18
+ // The recorder is started, it records the session.
19
+ Started: 3
20
+ }
21
+
22
+ export function makeRecorderApi(startRecordingImpl, startDeflateWorkerImpl) {
23
+ if (typeof startDeflateWorkerImpl === 'undefined') {
24
+ startDeflateWorkerImpl = startDeflateWorker
25
+ }
26
+ if (!isBrowserSupported()) {
27
+ return {
28
+ start: noop,
29
+ stop: noop,
30
+ getReplayStats: function () {
31
+ return undefined
32
+ },
33
+ onRumStart: noop,
34
+ isRecording: function () {
35
+ return false
36
+ }
37
+ }
38
+ }
39
+
40
+ var state = {
41
+ status: RecorderStatus.Stopped
42
+ }
43
+
44
+ var startStrategy = function () {
45
+ state = { status: RecorderStatus.IntentToStart }
46
+ }
47
+ var stopStrategy = function () {
48
+ state = { status: RecorderStatus.Stopped }
49
+ }
50
+ return {
51
+ start: function () {
52
+ startStrategy()
53
+ },
54
+ stop: function () {
55
+ stopStrategy()
56
+ },
57
+ getReplayStats: getReplayStats,
58
+
59
+ onRumStart: function (
60
+ lifeCycle,
61
+ configuration,
62
+ sessionManager,
63
+ viewContexts
64
+ ) {
65
+ lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
66
+ if (
67
+ state.status === RecorderStatus.Starting ||
68
+ state.status === RecorderStatus.Started
69
+ ) {
70
+ stopStrategy()
71
+ state = { status: RecorderStatus.IntentToStart }
72
+ }
73
+ })
74
+
75
+ lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, function () {
76
+ if (state.status === RecorderStatus.IntentToStart) {
77
+ startStrategy()
78
+ }
79
+ })
80
+
81
+ startStrategy = function () {
82
+ var session = sessionManager.findTrackedSession()
83
+ if (!session || !session.sessionReplayAllowed) {
84
+ state = { status: RecorderStatus.IntentToStart }
85
+ return
86
+ }
87
+
88
+ if (
89
+ state.status === RecorderStatus.Starting ||
90
+ state.status === RecorderStatus.Started
91
+ ) {
92
+ return
93
+ }
94
+
95
+ state = { status: RecorderStatus.Starting }
96
+
97
+ runOnReadyState('interactive', function () {
98
+ if (state.status !== RecorderStatus.Starting) {
99
+ return
100
+ }
101
+
102
+ startDeflateWorkerImpl(function (worker) {
103
+ if (state.status !== RecorderStatus.Starting) {
104
+ return
105
+ }
106
+
107
+ if (!worker) {
108
+ state = {
109
+ status: RecorderStatus.Stopped
110
+ }
111
+ return
112
+ }
113
+
114
+ var recordingImpl = startRecordingImpl(
115
+ lifeCycle,
116
+ configuration,
117
+ sessionManager,
118
+ viewContexts,
119
+ worker
120
+ )
121
+ state = {
122
+ status: RecorderStatus.Started,
123
+ stopRecording: recordingImpl.stop
124
+ }
125
+ })
126
+ })
127
+ }
128
+
129
+ stopStrategy = function () {
130
+ if (state.status === RecorderStatus.Stopped) {
131
+ return
132
+ }
133
+
134
+ if (state.status === RecorderStatus.Started) {
135
+ state.stopRecording()
136
+ }
137
+
138
+ state = {
139
+ status: RecorderStatus.Stopped
140
+ }
141
+ }
142
+
143
+ if (state.status === RecorderStatus.IntentToStart) {
144
+ startStrategy()
145
+ }
146
+ },
147
+
148
+ isRecording: function () {
149
+ return state.status === RecorderStatus.Started
150
+ }
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Test for Browser features used while recording
156
+ */
157
+ function isBrowserSupported() {
158
+ return (
159
+ // Array.from is a bit less supported by browsers than CSSSupportsRule, but has higher chances
160
+ // to be polyfilled. Test for both to be more confident. We could add more things if we find out
161
+ // this test is not sufficient.
162
+ typeof Array.from === 'function' &&
163
+ typeof CSSSupportsRule === 'function' &&
164
+ 'forEach' in NodeList.prototype
165
+ )
166
+ }
@@ -1,6 +1,9 @@
1
1
  import { defineGlobal, getGlobalObject } from '@cloudcare/browser-core'
2
2
  import { startRum } from './rum'
3
3
  import { makeRumPublicApi } from './rumPublicApi'
4
- export var datafluxRum = makeRumPublicApi(startRum)
4
+ import { startRecording } from './startRecording'
5
+ import { makeRecorderApi } from './recorderApi'
6
+ var recorderApi = makeRecorderApi(startRecording)
7
+ export var datafluxRum = makeRumPublicApi(startRum, recorderApi)
5
8
 
6
9
  defineGlobal(getGlobalObject(), 'DATAFLUX_RUM', datafluxRum)
package/src/boot/rum.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { startRumSessionManager } from '../domain/rumSessionManager'
2
2
  import { startCacheUsrCache } from '../domain/usr'
3
- import { LifeCycle, LifeCycleEventType } from '@cloudcare/browser-core'
3
+ import {
4
+ LifeCycle,
5
+ LifeCycleEventType,
6
+ createPageExitObservable
7
+ } from '@cloudcare/browser-core'
4
8
  import { startPerformanceCollection } from '../domain/performanceCollection'
5
9
  import { createDOMMutationObservable } from '../domain/domMutationCollection'
6
10
  import { createLocationChangeObservable } from '../domain/locationChangeObservable'
@@ -9,19 +13,29 @@ import { startActionCollection } from '../domain/rumEventsCollection/actions/act
9
13
  import { startRumBatch } from '../transport/startRumBatch'
10
14
  import { startRumAssembly } from '../domain/assembly'
11
15
  import { startInternalContext } from '../domain/contexts/internalContext'
16
+ import { startForegroundContexts } from '../domain/contexts/foregroundContexts'
12
17
  import { startUrlContexts } from '../domain/contexts/urlContexts'
13
18
  import { startViewContexts } from '../domain/contexts/viewContexts'
14
19
  import { startErrorCollection } from '../domain/rumEventsCollection/error/errorCollection'
15
20
  import { startViewCollection } from '../domain/rumEventsCollection/view/viewCollection'
16
21
  import { startRequestCollection } from '../domain/requestCollection'
17
22
  import { startResourceCollection } from '../domain/rumEventsCollection/resource/resourceCollection'
18
- export function startRum(configuration, getCommonContext, initialViewOptions) {
23
+ export function startRum(
24
+ configuration,
25
+ getCommonContext,
26
+ recorderApi,
27
+ initialViewOptions
28
+ ) {
19
29
  var lifeCycle = new LifeCycle()
20
-
21
- var reportError = function(error) {
30
+
31
+ var reportError = function (error) {
22
32
  lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error })
23
33
  }
24
- startRumBatch(configuration, lifeCycle, reportError)
34
+ var pageExitObservable = createPageExitObservable()
35
+ pageExitObservable.subscribe(function (event) {
36
+ lifeCycle.notify(LifeCycleEventType.PAGE_EXITED, event)
37
+ })
38
+ startRumBatch(configuration, lifeCycle, reportError, pageExitObservable)
25
39
  var session = startRumSessionManager(configuration, lifeCycle)
26
40
  var userSession = startCacheUsrCache(configuration)
27
41
  var domMutationObservable = createDOMMutationObservable()
@@ -40,8 +54,9 @@ export function startRum(configuration, getCommonContext, initialViewOptions) {
40
54
  var viewContexts = _startRumEventCollection.viewContexts
41
55
  var urlContexts = _startRumEventCollection.urlContexts
42
56
  var actionContexts = _startRumEventCollection.actionContexts
57
+ var foregroundContexts = _startRumEventCollection.foregroundContexts
43
58
  startLongTaskCollection(lifeCycle, session)
44
- startResourceCollection(lifeCycle,configuration)
59
+ startResourceCollection(lifeCycle, configuration)
45
60
 
46
61
  var _startViewCollection = startViewCollection(
47
62
  lifeCycle,
@@ -49,11 +64,16 @@ export function startRum(configuration, getCommonContext, initialViewOptions) {
49
64
  location,
50
65
  domMutationObservable,
51
66
  locationChangeObservable,
67
+ foregroundContexts,
68
+ recorderApi,
52
69
  initialViewOptions
53
70
  )
54
71
  var addTiming = _startViewCollection.addTiming
55
72
  var startView = _startViewCollection.startView
56
- var _startErrorCollection = startErrorCollection(lifeCycle, configuration)
73
+ var _startErrorCollection = startErrorCollection(
74
+ lifeCycle,
75
+ foregroundContexts
76
+ )
57
77
  var addError = _startErrorCollection.addError
58
78
  startRequestCollection(lifeCycle, configuration, session)
59
79
  startPerformanceCollection(lifeCycle, configuration)
@@ -89,11 +109,17 @@ export function startRumEventCollection(
89
109
  reportError
90
110
  ) {
91
111
  var viewContexts = startViewContexts(lifeCycle)
92
- var urlContexts = startUrlContexts(lifeCycle, locationChangeObservable, location)
112
+ var urlContexts = startUrlContexts(
113
+ lifeCycle,
114
+ locationChangeObservable,
115
+ location
116
+ )
117
+ var foregroundContexts = startForegroundContexts()
93
118
  var _startActionCollection = startActionCollection(
94
119
  lifeCycle,
95
120
  domMutationObservable,
96
121
  configuration,
122
+ foregroundContexts
97
123
  )
98
124
  var actionContexts = _startActionCollection.actionContexts
99
125
  startRumAssembly(
@@ -110,10 +136,12 @@ export function startRumEventCollection(
110
136
  return {
111
137
  viewContexts: viewContexts,
112
138
  urlContexts: urlContexts,
139
+ foregroundContexts: foregroundContexts,
113
140
  addAction: _startActionCollection.addAction,
114
141
  actionContexts: actionContexts,
115
- stop: function() {
142
+ stop: function () {
116
143
  viewContexts.stop()
117
- },
144
+ foregroundContexts.stop()
145
+ }
118
146
  }
119
147
  }
@@ -13,7 +13,7 @@ import {
13
13
  createHandlingStack
14
14
  } from '@cloudcare/browser-core'
15
15
  import { validateAndBuildRumConfiguration } from '../domain/configuration'
16
- export function makeRumPublicApi(startRumImpl) {
16
+ export function makeRumPublicApi(startRumImpl, recorderApi) {
17
17
  var isAlreadyInitialized = false
18
18
 
19
19
  var globalContextManager = createContextManager()
@@ -105,9 +105,11 @@ export function makeRumPublicApi(startRumImpl) {
105
105
  function () {
106
106
  return {
107
107
  user: userContextManager.getContext(),
108
- context: globalContextManager.getContext()
108
+ context: globalContextManager.getContext(),
109
+ hasReplay: recorderApi.isRecording() ? true : undefined
109
110
  }
110
111
  },
112
+ recorderApi,
111
113
  initialViewOptions
112
114
  )
113
115
  startViewStrategy = startRumResults.startView
@@ -116,6 +118,12 @@ export function makeRumPublicApi(startRumImpl) {
116
118
  addTimingStrategy = startRumResults.addTiming
117
119
  getInternalContextStrategy = startRumResults.getInternalContext
118
120
  bufferApiCalls.drain()
121
+ recorderApi.onRumStart(
122
+ startRumResults.lifeCycle,
123
+ configuration,
124
+ startRumResults.session,
125
+ startRumResults.viewContexts
126
+ )
119
127
  }
120
128
  var startView = function (options) {
121
129
  var sanitizedOptions =
@@ -198,7 +206,9 @@ export function makeRumPublicApi(startRumImpl) {
198
206
  /** @deprecated: renamed to clearUser */
199
207
  removeUser: userContextManager.clearContext,
200
208
  clearUser: userContextManager.clearContext,
201
- startView: startView
209
+ startView: startView,
210
+ startSessionReplayRecording: recorderApi.start,
211
+ stopSessionReplayRecording: recorderApi.stop
202
212
  })
203
213
  return rumPublicApi
204
214