@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
@@ -0,0 +1,3 @@
1
+ export { startSegmentCollection, setSegmentBytesLimit } from './segmentCollection';
2
+ export { startDeflateWorker } from './startDeflateWorker';
3
+ export { SEGMENT_BYTES_LIMIT } from './segmentCollection';
@@ -0,0 +1,84 @@
1
+ import { assign } from '@cloudcare/browser-core';
2
+ import { RecordType } from '../../../types';
3
+ import * as replayStats from '../replayStats';
4
+ var nextId = 0;
5
+ export function Segment(worker, context, creationReason, initialRecord, onWrote, onFlushed) {
6
+ this.worker = worker;
7
+ this.id = nextId++;
8
+ var viewId = context.view.id;
9
+ this.metadata = assign({
10
+ start: initialRecord.timestamp,
11
+ end: initialRecord.timestamp,
12
+ creation_reason: creationReason,
13
+ records_count: 1,
14
+ has_full_snapshot: initialRecord.type === RecordType.FullSnapshot,
15
+ index_in_view: replayStats.getSegmentsCount(viewId),
16
+ source: 'browser'
17
+ }, context);
18
+ replayStats.addSegment(viewId);
19
+ replayStats.addRecord(viewId);
20
+
21
+ var _this = this;
22
+
23
+ var listener = function listener(params) {
24
+ var data = params.data;
25
+
26
+ if (data.type === 'errored' || data.type === 'initialized') {
27
+ return;
28
+ }
29
+
30
+ if (data.id === _this.id) {
31
+ replayStats.addWroteData(viewId, data.additionalBytesCount);
32
+
33
+ if (data.type === 'flushed') {
34
+ onFlushed(data.result, data.rawBytesCount);
35
+ worker.removeEventListener('message', listener);
36
+ } else {
37
+ onWrote(data.compressedBytesCount);
38
+ }
39
+ } else if (data.id > _this.id) {
40
+ // Messages should be received in the same order as they are sent, so if we receive a
41
+ // message with an id superior to this Segment instance id, we know that another, more
42
+ // recent Segment instance is being used.
43
+ //
44
+ // In theory, a "flush" response should have been received at this point, so the listener
45
+ // should already have been removed. But if something goes wrong and we didn't receive a
46
+ // "flush" response, remove the listener to avoid any leak, and send a monitor message to
47
+ // help investigate the issue.
48
+ worker.removeEventListener('message', listener);
49
+ }
50
+ };
51
+
52
+ worker.addEventListener('message', listener);
53
+ this.worker.postMessage({
54
+ data: '{"records":[' + JSON.stringify(initialRecord),
55
+ id: this.id,
56
+ action: 'write'
57
+ });
58
+ }
59
+
60
+ Segment.prototype.addRecord = function (record) {
61
+ this.metadata.start = Math.min(this.metadata.start, record.timestamp);
62
+ this.metadata.end = Math.max(this.metadata.end, record.timestamp);
63
+ this.metadata.records_count += 1;
64
+ replayStats.addRecord(this.metadata.view.id);
65
+
66
+ if (!this.metadata.has_full_snapshot) {
67
+ this.metadata.has_full_snapshot = record.type === RecordType.FullSnapshot;
68
+ }
69
+
70
+ this.worker.postMessage({
71
+ data: ',' + JSON.stringify(record),
72
+ id: this.id,
73
+ action: 'write'
74
+ });
75
+ };
76
+
77
+ Segment.prototype.flush = function (reason) {
78
+ this.worker.postMessage({
79
+ data: '],' + JSON.stringify(this.metadata).slice(1) + '\n',
80
+ id: this.id,
81
+ action: 'flush'
82
+ });
83
+ this.flushReason = reason;
84
+ };
@@ -0,0 +1,158 @@
1
+ import { ONE_SECOND, LifeCycleEventType, isPageExitReason } from '@cloudcare/browser-core';
2
+ import { buildReplayPayload } from './buildReplayPayload';
3
+ import { Segment } from './segment';
4
+ export var SEGMENT_DURATION_LIMIT = 30 * ONE_SECOND;
5
+ /**
6
+ * beacon payload max queue size implementation is 64kb
7
+ * ensure that we leave room for logs, rum and potential other users
8
+ */
9
+
10
+ export var SEGMENT_BYTES_LIMIT = 60000; // Segments are the main data structure for session replays. They contain context information used
11
+ // for indexing or UI needs, and a list of records (RRWeb 'events', renamed to avoid confusing
12
+ // namings). They are stored without any processing from the intake, and fetched one after the
13
+ // other while a session is being replayed. Their encoding (deflate) are carefully crafted to allow
14
+ // concatenating multiple segments together. Segments have a size overhead (metadata), so our goal is to
15
+ // build segments containing as many records as possible while complying with the various flush
16
+ // strategies to guarantee a good replay quality.
17
+ //
18
+ // When the recording starts, a segment is initially created. The segment is flushed (finalized and
19
+ // sent) based on various events (non-exhaustive list):
20
+ //
21
+ // * the page visibility change or becomes to unload
22
+ // * the segment duration reaches a limit
23
+ // * the encoded segment bytes count reaches a limit
24
+ // * ...
25
+ //
26
+ // A segment cannot be created without its context. If the RUM session ends and no session id is
27
+ // available when creating a new segment, records will be ignored, until the session is renewed and
28
+ // a new session id is available.
29
+ //
30
+ // Empty segments (segments with no record) aren't useful and should be ignored.
31
+ //
32
+ // To help investigate session replays issues, each segment is created with a "creation reason",
33
+ // indicating why the session has been created.
34
+
35
+ export function startSegmentCollection(lifeCycle, configuration, sessionManager, viewContexts, httpRequest, worker) {
36
+ return doStartSegmentCollection(lifeCycle, function () {
37
+ return computeSegmentContext(configuration, sessionManager, viewContexts);
38
+ }, httpRequest, worker);
39
+ }
40
+ var SegmentCollectionStatus = {
41
+ WaitingForInitialRecord: 0,
42
+ SegmentPending: 1,
43
+ Stopped: 2
44
+ };
45
+ export function doStartSegmentCollection(lifeCycle, getSegmentContext, httpRequest, worker) {
46
+ var state = {
47
+ status: SegmentCollectionStatus.WaitingForInitialRecord,
48
+ nextSegmentCreationReason: 'init'
49
+ };
50
+ var subscribeViewCreated = lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
51
+ flushSegment('view_change');
52
+ });
53
+ var unsubscribeViewCreated = subscribeViewCreated.unsubscribe;
54
+ var subscribePageExited = lifeCycle.subscribe(LifeCycleEventType.PAGE_EXITED, function (pageExitEvent) {
55
+ flushSegment(pageExitEvent.reason);
56
+ });
57
+ var unsubscribePageExited = subscribePageExited.unsubscribe;
58
+
59
+ function flushSegment(flushReason) {
60
+ if (state.status === SegmentCollectionStatus.SegmentPending) {
61
+ state.segment.flush(flushReason);
62
+ clearTimeout(state.expirationTimeoutId);
63
+ }
64
+
65
+ if (flushReason !== 'stop') {
66
+ state = {
67
+ status: SegmentCollectionStatus.WaitingForInitialRecord,
68
+ nextSegmentCreationReason: flushReason
69
+ };
70
+ } else {
71
+ state = {
72
+ status: SegmentCollectionStatus.Stopped
73
+ };
74
+ }
75
+ }
76
+
77
+ function createNewSegment(creationReason, initialRecord) {
78
+ var context = getSegmentContext();
79
+
80
+ if (!context) {
81
+ return;
82
+ }
83
+
84
+ var segment = new Segment(worker, context, creationReason, initialRecord, function (compressedSegmentBytesCount) {
85
+ if (!segment.flushReason && compressedSegmentBytesCount > SEGMENT_BYTES_LIMIT) {
86
+ flushSegment('segment_bytes_limit');
87
+ }
88
+ }, function (data, rawSegmentBytesCount) {
89
+ var payload = buildReplayPayload(data, segment.metadata, rawSegmentBytesCount);
90
+
91
+ if (isPageExitReason(segment.flushReason)) {
92
+ httpRequest.sendOnExit(payload);
93
+ } else {
94
+ httpRequest.send(payload);
95
+ }
96
+ });
97
+ state = {
98
+ status: SegmentCollectionStatus.SegmentPending,
99
+ segment: segment,
100
+ expirationTimeoutId: setTimeout(function () {
101
+ flushSegment('segment_duration_limit');
102
+ }, SEGMENT_DURATION_LIMIT)
103
+ };
104
+ }
105
+
106
+ return {
107
+ addRecord: function addRecord(record) {
108
+ switch (state.status) {
109
+ case SegmentCollectionStatus.WaitingForInitialRecord:
110
+ createNewSegment(state.nextSegmentCreationReason, record);
111
+ break;
112
+
113
+ case SegmentCollectionStatus.SegmentPending:
114
+ state.segment.addRecord(record);
115
+ break;
116
+ }
117
+ },
118
+ stop: function stop() {
119
+ flushSegment('stop');
120
+ unsubscribeViewCreated();
121
+ unsubscribePageExited();
122
+ }
123
+ };
124
+ }
125
+ export function computeSegmentContext(configuration, sessionManager, viewContexts) {
126
+ var session = sessionManager.findTrackedSession();
127
+ var viewContext = viewContexts.findView();
128
+
129
+ if (!session || !viewContext) {
130
+ return undefined;
131
+ }
132
+
133
+ return {
134
+ sdk: {
135
+ name: configuration.sdkName,
136
+ version: configuration.sdkVersion
137
+ },
138
+ env: configuration.env || '',
139
+ service: viewContext.service || configuration.service || 'browser',
140
+ version: viewContext.version || configuration.version || '',
141
+ app: {
142
+ id: configuration.applicationId
143
+ },
144
+ session: {
145
+ id: session.id
146
+ },
147
+ view: {
148
+ id: viewContext.id
149
+ }
150
+ };
151
+ }
152
+ export function setSegmentBytesLimit(newSegmentBytesLimit) {
153
+ if (newSegmentBytesLimit === undefined) {
154
+ newSegmentBytesLimit = 60000;
155
+ }
156
+
157
+ SEGMENT_BYTES_LIMIT = newSegmentBytesLimit;
158
+ }
@@ -0,0 +1,113 @@
1
+ import { display, includes, each } from '@cloudcare/browser-core';
2
+ import { createDeflateWorker } from './deflateWorker';
3
+ /**
4
+ * In order to be sure that the worker is correctly working, we need a round trip of
5
+ * initialization messages, making the creation asynchronous.
6
+ * These worker lifecycle states handle this case.
7
+ */
8
+
9
+ var DeflateWorkerStatus = {
10
+ Nil: 0,
11
+ Loading: 1,
12
+ Error: 2,
13
+ Initialized: 3
14
+ };
15
+ var state = {
16
+ status: DeflateWorkerStatus.Nil
17
+ };
18
+ export function startDeflateWorker(callback, createDeflateWorkerImpl) {
19
+ if (createDeflateWorkerImpl === undefined) {
20
+ createDeflateWorkerImpl = createDeflateWorker;
21
+ }
22
+
23
+ switch (state.status) {
24
+ case DeflateWorkerStatus.Nil:
25
+ state = {
26
+ status: DeflateWorkerStatus.Loading,
27
+ callbacks: [callback]
28
+ };
29
+ doStartDeflateWorker(createDeflateWorkerImpl);
30
+ break;
31
+
32
+ case DeflateWorkerStatus.Loading:
33
+ state.callbacks.push(callback);
34
+ break;
35
+
36
+ case DeflateWorkerStatus.Error:
37
+ callback();
38
+ break;
39
+
40
+ case DeflateWorkerStatus.Initialized:
41
+ callback(state.worker);
42
+ break;
43
+ }
44
+ }
45
+ export function resetDeflateWorkerState() {
46
+ state = {
47
+ status: DeflateWorkerStatus.Nil
48
+ };
49
+ }
50
+ /**
51
+ * Starts the deflate worker and handle messages and errors
52
+ *
53
+ * The spec allow browsers to handle worker errors differently:
54
+ * - Chromium throws an exception
55
+ * - Firefox fires an error event
56
+ *
57
+ * more details: https://bugzilla.mozilla.org/show_bug.cgi?id=1736865#c2
58
+ */
59
+
60
+ export function doStartDeflateWorker(createDeflateWorkerImpl) {
61
+ if (createDeflateWorkerImpl === undefined) {
62
+ createDeflateWorkerImpl = createDeflateWorker;
63
+ }
64
+
65
+ try {
66
+ var worker = createDeflateWorkerImpl();
67
+ worker.addEventListener('error', onError);
68
+ worker.addEventListener('message', function (event) {
69
+ var data = event.data;
70
+
71
+ if (data.type === 'errored') {
72
+ onError(data.error);
73
+ } else if (data.type === 'initialized') {
74
+ onInitialized(worker);
75
+ }
76
+ });
77
+ worker.postMessage({
78
+ action: 'init'
79
+ });
80
+ return worker;
81
+ } catch (error) {
82
+ onError(error);
83
+ }
84
+ }
85
+
86
+ function onInitialized(worker) {
87
+ if (state.status === DeflateWorkerStatus.Loading) {
88
+ each(state.callbacks, function (callback) {
89
+ callback(worker);
90
+ });
91
+ state = {
92
+ status: DeflateWorkerStatus.Initialized,
93
+ worker: worker
94
+ };
95
+ }
96
+ }
97
+
98
+ function onError(error) {
99
+ if (state.status === DeflateWorkerStatus.Loading) {
100
+ display.error('Session Replay recording failed to start: an error occurred while creating the Worker:', error);
101
+
102
+ if (error instanceof Event || error instanceof Error && includes(error.message, 'Content Security Policy')) {
103
+ display.error('Please make sure CSP is correctly configured !!!');
104
+ }
105
+
106
+ each(state.callbacks, function (callback) {
107
+ callback();
108
+ });
109
+ state = {
110
+ status: DeflateWorkerStatus.Error
111
+ };
112
+ }
113
+ }
@@ -1,4 +1,4 @@
1
- import { RequestType, initFetchObservable, initXhrObservable, LifeCycleEventType } from '@cloudcare/browser-core';
1
+ import { RequestType, initFetchObservable, initXhrObservable, LifeCycleEventType, tryToClone, readBytesFromStream, elapsed, timeStampNow } from '@cloudcare/browser-core';
2
2
  import { isAllowedRequestUrl } from './rumEventsCollection/resource/resourceUtils';
3
3
  import { startTracer } from './tracing/tracer';
4
4
  var nextRequestIndex = 1;
@@ -67,23 +67,25 @@ export function trackFetch(lifeCycle, configuration, tracer) {
67
67
  });
68
68
  break;
69
69
 
70
- case 'complete':
71
- tracer.clearTracingIfNeeded(context);
72
- lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
73
- duration: context.duration,
74
- method: context.method,
75
- requestIndex: context.requestIndex,
76
- responseType: context.responseType,
77
- spanId: context.spanId,
78
- startClocks: context.startClocks,
79
- status: context.status,
80
- traceId: context.traceId,
81
- traceSampled: context.traceSampled,
82
- type: RequestType.FETCH,
83
- url: context.url,
84
- response: context.response,
85
- init: context.init,
86
- input: context.input
70
+ case 'resolve':
71
+ waitForResponseToComplete(context, function (duration) {
72
+ tracer.clearTracingIfNeeded(context);
73
+ lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, {
74
+ duration: duration,
75
+ method: context.method,
76
+ requestIndex: context.requestIndex,
77
+ responseType: context.responseType,
78
+ spanId: context.spanId,
79
+ startClocks: context.startClocks,
80
+ status: context.status,
81
+ traceId: context.traceId,
82
+ traceSampled: context.traceSampled,
83
+ type: RequestType.FETCH,
84
+ url: context.url,
85
+ response: context.response,
86
+ init: context.init,
87
+ input: context.input
88
+ });
87
89
  });
88
90
  break;
89
91
  }
@@ -99,4 +101,20 @@ function getNextRequestIndex() {
99
101
  var result = nextRequestIndex;
100
102
  nextRequestIndex += 1;
101
103
  return result;
104
+ }
105
+
106
+ function waitForResponseToComplete(context, callback) {
107
+ var clonedResponse = context.response && tryToClone(context.response);
108
+
109
+ if (!clonedResponse || !clonedResponse.body) {
110
+ // do not try to wait for the response if the clone failed, fetch error or null body
111
+ callback(elapsed(context.startClocks.timeStamp, timeStampNow()));
112
+ } else {
113
+ readBytesFromStream(clonedResponse.body, function () {
114
+ callback(elapsed(context.startClocks.timeStamp, timeStampNow()));
115
+ }, {
116
+ bytesLimit: Number.POSITIVE_INFINITY,
117
+ collectStreamBody: false
118
+ });
119
+ }
102
120
  }
@@ -1,8 +1,8 @@
1
1
  import { toServerDuration, extend, extend2Lev, ActionType, RumEventType, LifeCycleEventType, UUID, noop } from '@cloudcare/browser-core';
2
2
  import { trackClickActions } from './trackClickActions';
3
- export function startActionCollection(lifeCycle, domMutationObservable, configuration) {
3
+ export function startActionCollection(lifeCycle, domMutationObservable, configuration, foregroundContexts) {
4
4
  lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_COMPLETED, function (action) {
5
- lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processAction(action));
5
+ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processAction(action, foregroundContexts));
6
6
  });
7
7
  var actionContexts = {
8
8
  findActionId: noop
@@ -17,12 +17,12 @@ export function startActionCollection(lifeCycle, domMutationObservable, configur
17
17
  addAction: function addAction(action, savedCommonContext) {
18
18
  lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, extend({
19
19
  savedCommonContext: savedCommonContext
20
- }, processAction(action)));
20
+ }, processAction(action, foregroundContexts)));
21
21
  }
22
22
  };
23
23
  }
24
24
 
25
- function processAction(action) {
25
+ function processAction(action, foregroundContexts) {
26
26
  var autoActionProperties = isAutoAction(action) ? {
27
27
  action: {
28
28
  error: {
@@ -63,6 +63,14 @@ function processAction(action) {
63
63
  date: action.startClocks.timeStamp,
64
64
  type: RumEventType.ACTION
65
65
  }, autoActionProperties);
66
+ var inForeground = foregroundContexts.isInForegroundAt(action.startClocks.relative);
67
+
68
+ if (inForeground !== undefined) {
69
+ actionEvent.view = {
70
+ in_foreground: inForeground
71
+ };
72
+ }
73
+
66
74
  return {
67
75
  customerContext: customerContext,
68
76
  rawRumEvent: actionEvent,
@@ -2,9 +2,9 @@ import { ONE_SECOND, every } from '@cloudcare/browser-core';
2
2
  export var MAX_DURATION_BETWEEN_CLICKS = ONE_SECOND;
3
3
  export var MAX_DISTANCE_BETWEEN_CLICKS = 100;
4
4
  var ClickChainStatus = {
5
- WaitingForMoreClicks: 'WaitingForMoreClicks',
6
- WaitingForClicksToStop: 'WaitingForClicksToStop',
7
- Finalized: 'Finalized'
5
+ WaitingForMoreClicks: 0,
6
+ WaitingForClicksToStop: 1,
7
+ Finalized: 2
8
8
  };
9
9
  export function createClickChain(firstClick, onFinalize) {
10
10
  var bufferedClicks = [];
@@ -4,11 +4,11 @@ export function computeFrustration(clicks, rageClick) {
4
4
  if (isRage(clicks)) {
5
5
  rageClick.addFrustration(FrustrationType.RAGE_CLICK);
6
6
 
7
- if (clicks.some(isDead)) {
7
+ if (some(clicks, isDead)) {
8
8
  rageClick.addFrustration(FrustrationType.DEAD_CLICK);
9
9
  }
10
10
 
11
- if (rageClick.hasError) {
11
+ if (rageClick.hasError()) {
12
12
  rageClick.addFrustration(FrustrationType.ERROR_CLICK);
13
13
  }
14
14
 
@@ -21,7 +21,7 @@ export function computeFrustration(clicks, rageClick) {
21
21
  return click.getUserActivity().selection;
22
22
  });
23
23
  each(clicks, function (click) {
24
- if (click.hasError) {
24
+ if (click.hasError()) {
25
25
  click.addFrustration(FrustrationType.ERROR_CLICK);
26
26
  }
27
27
 
@@ -51,12 +51,13 @@ export function isRage(clicks) {
51
51
  }
52
52
  var DEAD_CLICK_EXCLUDE_SELECTOR = // inputs that don't trigger a meaningful event like "input" when clicked, including textual
53
53
  // inputs (using a negative selector is shorter here)
54
- 'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="range"]),' + 'textarea,' + 'select,' + // canvas, as there is no good way to detect activity occurring on them
54
+ 'input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="range"]),' + 'textarea,' + 'select,' + // contenteditable and their descendants don't always trigger meaningful changes when manipulated
55
+ '[contenteditable],' + '[contenteditable] *,' + // canvas, as there is no good way to detect activity occurring on them
55
56
  'canvas,' + // links that are interactive (have an href attribute) or any of their descendants, as they can
56
57
  // open a new tab or navigate to a hash without triggering a meaningful event
57
58
  'a[href],' + 'a[href] *';
58
59
  export function isDead(click) {
59
- if (click.hasPageActivity || click.getUserActivity().input) {
60
+ if (click.hasPageActivity() || click.getUserActivity().input) {
60
61
  return false;
61
62
  }
62
63
 
@@ -1,5 +1,5 @@
1
1
  import { safeTruncate, isIE, find, map, filter } from '@cloudcare/browser-core';
2
- var DEFAULT_PROGRAMMATIC_ATTRIBUTE = 'data-guance-action-name';
2
+ export var DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE = 'data-guance-action-name';
3
3
  export function getActionNameFromElement(element, userProgrammaticAttribute) {
4
4
  // Proceed to get the action name in two steps:
5
5
  // * first, get the name programmatically, explicitly defined by the user.
@@ -7,7 +7,7 @@ export function getActionNameFromElement(element, userProgrammaticAttribute) {
7
7
  // the element and a few parents, but it's likely that they won't succeed at all.
8
8
  // * if no name is found this way, use strategies returning less accurate names as a fallback.
9
9
  // Those are much likely to succeed.
10
- return getActionNameFromElementProgrammatically(element, DEFAULT_PROGRAMMATIC_ATTRIBUTE) || userProgrammaticAttribute && getActionNameFromElementProgrammatically(element, userProgrammaticAttribute) || getActionNameFromElementForStrategies(element, userProgrammaticAttribute, priorityStrategies) || getActionNameFromElementForStrategies(element, userProgrammaticAttribute, fallbackStrategies) || '';
10
+ return getActionNameFromElementProgrammatically(element, DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE) || userProgrammaticAttribute && getActionNameFromElementProgrammatically(element, userProgrammaticAttribute) || getActionNameFromElementForStrategies(element, userProgrammaticAttribute, priorityStrategies) || getActionNameFromElementForStrategies(element, userProgrammaticAttribute, fallbackStrategies) || '';
11
11
  }
12
12
 
13
13
  function getActionNameFromElementProgrammatically(targetElement, programmaticAttribute) {
@@ -83,7 +83,7 @@ function (element, userProgrammaticAttribute) {
83
83
  return Boolean(label);
84
84
  });
85
85
  labelledByAttribute = map(labelledByAttribute, function (ele) {
86
- return getTextualContent(ele);
86
+ return getTextualContent(ele, userProgrammaticAttribute);
87
87
  });
88
88
  return labelledByAttribute.join(' ');
89
89
  }
@@ -96,9 +96,9 @@ function (element, userProgrammaticAttribute) {
96
96
  }, function (element) {
97
97
  return element.getAttribute('placeholder');
98
98
  }, // SELECT first OPTION text
99
- function (element) {
99
+ function (element, userProgrammaticAttribute) {
100
100
  if ('options' in element && element.options.length > 0) {
101
- return getTextualContent(element.options[0]);
101
+ return getTextualContent(element.options[0], userProgrammaticAttribute);
102
102
  }
103
103
  }];
104
104
  var fallbackStrategies = [function (element, userProgrammaticAttribute) {
@@ -185,7 +185,7 @@ function getTextualContent(element, userProgrammaticAttribute) {
185
185
  } // remove the text of elements with programmatic attribute value
186
186
 
187
187
 
188
- removeTextFromElements('[' + DEFAULT_PROGRAMMATIC_ATTRIBUTE + ']');
188
+ removeTextFromElements('[' + DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE + ']');
189
189
 
190
190
  if (userProgrammaticAttribute) {
191
191
  removeTextFromElements('[' + userProgrammaticAttribute + ']');