@cloudcare/browser-rum 2.2.15 → 3.0.1

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