@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,461 @@
1
+ import { assign, startsWith, isNodeShadowHost, isNodeShadowRoot } from '@cloudcare/browser-core';
2
+ import { STABLE_ATTRIBUTES } from '../../rumEventsCollection/actions/getSelectorsFromElement';
3
+ import { NodePrivacyLevel, PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_HIDDEN, CENSORED_STRING_MARK, CENSORED_IMG_MARK } from '../../../constants';
4
+ import { NodeType } from '../../../types';
5
+ import { getTextContent, shouldMaskNode, reducePrivacyLevel, getNodeSelfPrivacyLevel, MAX_ATTRIBUTE_VALUE_CHAR_LENGTH } from './privacy';
6
+ import { getSerializedNodeId, setSerializedNodeId, getElementInputValue, switchToAbsoluteUrl, serializeStyleSheets } from './serializationUtils'; // Those values are the only one that can be used when inheriting privacy levels from parent to
7
+ // children during serialization, since HIDDEN and IGNORE shouldn't serialize their children. This
8
+ // ensures that no children are serialized when they shouldn't.
9
+
10
+ export var SerializationContextStatus = {
11
+ INITIAL_FULL_SNAPSHOT: 0,
12
+ SUBSEQUENT_FULL_SNAPSHOT: 1,
13
+ MUTATION: 2
14
+ };
15
+ export function serializeDocument(document, configuration, serializationContext) {
16
+ // We are sure that Documents are never ignored, so this function never returns null
17
+ return serializeNodeWithId(document, {
18
+ serializationContext: serializationContext,
19
+ parentNodePrivacyLevel: configuration.defaultPrivacyLevel,
20
+ configuration: configuration
21
+ });
22
+ }
23
+ export function serializeNodeWithId(node, options) {
24
+ var serializedNode = serializeNode(node, options);
25
+
26
+ if (!serializedNode) {
27
+ return null;
28
+ } // Try to reuse the previous id
29
+
30
+
31
+ var id = getSerializedNodeId(node) || generateNextId();
32
+ var serializedNodeWithId = serializedNode;
33
+ serializedNodeWithId.id = id;
34
+ setSerializedNodeId(node, id);
35
+
36
+ if (options.serializedNodeIds) {
37
+ options.serializedNodeIds.add(id);
38
+ }
39
+
40
+ return serializedNodeWithId;
41
+ }
42
+
43
+ function serializeNode(node, options) {
44
+ switch (node.nodeType) {
45
+ case node.DOCUMENT_NODE:
46
+ return serializeDocumentNode(node, options);
47
+
48
+ case node.DOCUMENT_FRAGMENT_NODE:
49
+ return serializeDocumentFragmentNode(node, options);
50
+
51
+ case node.DOCUMENT_TYPE_NODE:
52
+ return serializeDocumentTypeNode(node);
53
+
54
+ case node.ELEMENT_NODE:
55
+ return serializeElementNode(node, options);
56
+
57
+ case node.TEXT_NODE:
58
+ return serializeTextNode(node, options);
59
+
60
+ case node.CDATA_SECTION_NODE:
61
+ return serializeCDataNode();
62
+ }
63
+ }
64
+
65
+ export function serializeDocumentNode(document, options) {
66
+ return {
67
+ type: NodeType.Document,
68
+ childNodes: serializeChildNodes(document, options),
69
+ adoptedStyleSheets: serializeStyleSheets(document.adoptedStyleSheets)
70
+ };
71
+ }
72
+
73
+ function serializeDocumentTypeNode(documentType) {
74
+ return {
75
+ type: NodeType.DocumentType,
76
+ name: documentType.name,
77
+ publicId: documentType.publicId,
78
+ systemId: documentType.systemId
79
+ };
80
+ }
81
+
82
+ function serializeDocumentFragmentNode(element, options) {
83
+ var childNodes = [];
84
+
85
+ if (element.childNodes.length) {
86
+ childNodes = serializeChildNodes(element, options);
87
+ }
88
+
89
+ var isShadowRoot = isNodeShadowRoot(element);
90
+
91
+ if (isShadowRoot) {
92
+ options.serializationContext.shadowRootsController.addShadowRoot(element);
93
+ }
94
+
95
+ return {
96
+ type: NodeType.DocumentFragment,
97
+ childNodes: childNodes,
98
+ isShadowRoot: isShadowRoot,
99
+ adoptedStyleSheets: isShadowRoot ? serializeStyleSheets(element.adoptedStyleSheets) : undefined
100
+ };
101
+ }
102
+ /**
103
+ * Serializing Element nodes involves capturing:
104
+ * 1. HTML ATTRIBUTES:
105
+ * 2. JS STATE:
106
+ * - scroll offsets
107
+ * - Form fields (input value, checkbox checked, option selection, range)
108
+ * - Canvas state,
109
+ * - Media (video/audio) play mode + currentTime
110
+ * - iframe contents
111
+ * - webcomponents
112
+ * 3. CUSTOM PROPERTIES:
113
+ * - height+width for when `hidden` to cover the element
114
+ * 4. EXCLUDED INTERACTION STATE:
115
+ * - focus (possible, but not worth perf impact)
116
+ * - hover (tracked only via mouse activity)
117
+ * - fullscreen mode
118
+ */
119
+
120
+
121
+ export function serializeElementNode(element, options) {
122
+ var tagName = getValidTagName(element.tagName);
123
+ var isSVG = isSVGElement(element) || undefined; // For performance reason, we don't use getNodePrivacyLevel directly: we leverage the
124
+ // parentNodePrivacyLevel option to avoid iterating over all parents
125
+
126
+ var nodePrivacyLevel = reducePrivacyLevel(getNodeSelfPrivacyLevel(element), options.parentNodePrivacyLevel);
127
+
128
+ if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
129
+ var _boundingClientRect = element.getBoundingClientRect();
130
+
131
+ var width = _boundingClientRect.width;
132
+ var height = _boundingClientRect.height;
133
+ return {
134
+ type: NodeType.Element,
135
+ tagName: tagName,
136
+ attributes: {
137
+ rr_width: width + 'px',
138
+ rr_height: height + 'px',
139
+ [PRIVACY_ATTR_NAME]: PRIVACY_ATTR_VALUE_HIDDEN
140
+ },
141
+ childNodes: [],
142
+ isSVG: isSVG
143
+ };
144
+ } // Ignore Elements like Script and some Link, Metas
145
+
146
+
147
+ if (nodePrivacyLevel === NodePrivacyLevel.IGNORE) {
148
+ return;
149
+ }
150
+
151
+ var attributes = getAttributesForPrivacyLevel(element, nodePrivacyLevel, options);
152
+ var childNodes = [];
153
+
154
+ if (element.childNodes.length) {
155
+ // OBJECT POOLING OPTIMIZATION:
156
+ // We should not create a new object systematically as it could impact performances. Try to reuse
157
+ // the same object as much as possible, and clone it only if we need to.
158
+ var childNodesSerializationOptions;
159
+
160
+ if (options.parentNodePrivacyLevel === nodePrivacyLevel && options.ignoreWhiteSpace === (tagName === 'head')) {
161
+ childNodesSerializationOptions = options;
162
+ } else {
163
+ childNodesSerializationOptions = assign({}, options, {
164
+ parentNodePrivacyLevel: nodePrivacyLevel,
165
+ ignoreWhiteSpace: tagName === 'head'
166
+ });
167
+ }
168
+
169
+ childNodes = serializeChildNodes(element, childNodesSerializationOptions);
170
+ }
171
+
172
+ if (isNodeShadowHost(element)) {
173
+ var shadowRoot = serializeNodeWithId(element.shadowRoot, options);
174
+
175
+ if (shadowRoot !== null) {
176
+ childNodes.push(shadowRoot);
177
+ }
178
+ }
179
+
180
+ return {
181
+ type: NodeType.Element,
182
+ tagName: tagName,
183
+ attributes: attributes,
184
+ childNodes: childNodes,
185
+ isSVG: isSVG
186
+ };
187
+ }
188
+ /**
189
+ * Text Nodes are dependant on Element nodes
190
+ * Privacy levels are set on elements so we check the parentElement of a text node
191
+ * for privacy level.
192
+ */
193
+
194
+ function serializeTextNode(textNode, options) {
195
+ var _textNode$parentEleme;
196
+
197
+ // The parent node may not be a html element which has a tagName attribute.
198
+ // So just let it be undefined which is ok in this use case.
199
+ var parentTagName = (_textNode$parentEleme = textNode.parentElement) === null || _textNode$parentEleme === void 0 ? void 0 : _textNode$parentEleme.tagName;
200
+ var textContent = getTextContent(textNode, options.ignoreWhiteSpace || false, options.parentNodePrivacyLevel);
201
+
202
+ if (!textContent) {
203
+ return;
204
+ }
205
+
206
+ return {
207
+ type: NodeType.Text,
208
+ textContent: textContent,
209
+ isStyle: parentTagName === 'STYLE' ? true : undefined
210
+ };
211
+ }
212
+
213
+ function serializeCDataNode() {
214
+ return {
215
+ type: NodeType.CDATA,
216
+ textContent: ''
217
+ };
218
+ }
219
+
220
+ export function serializeChildNodes(node, options) {
221
+ var result = [];
222
+ node.childNodes.forEach(function (childNode) {
223
+ var serializedChildNode = serializeNodeWithId(childNode, options);
224
+
225
+ if (serializedChildNode) {
226
+ result.push(serializedChildNode);
227
+ }
228
+ });
229
+ return result;
230
+ }
231
+ export function serializeAttribute(element, nodePrivacyLevel, attributeName, configuration) {
232
+ if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
233
+ // dup condition for direct access case
234
+ return null;
235
+ }
236
+
237
+ var attributeValue = element.getAttribute(attributeName);
238
+
239
+ if (nodePrivacyLevel === NodePrivacyLevel.MASK && attributeName !== PRIVACY_ATTR_NAME && !STABLE_ATTRIBUTES.includes(attributeName) && attributeName !== configuration.actionNameAttribute) {
240
+ var tagName = element.tagName;
241
+
242
+ switch (attributeName) {
243
+ // Mask Attribute text content
244
+ case 'title':
245
+ case 'alt':
246
+ case 'placeholder':
247
+ return CENSORED_STRING_MARK;
248
+ } // mask image URLs
249
+
250
+
251
+ if (tagName === 'IMG' || tagName === 'SOURCE') {
252
+ if (attributeName === 'src' || attributeName === 'srcset') {
253
+ return CENSORED_IMG_MARK;
254
+ }
255
+ } // mask <a> URLs
256
+
257
+
258
+ if (tagName === 'A' && attributeName === 'href') {
259
+ return CENSORED_STRING_MARK;
260
+ } // mask data-* attributes
261
+
262
+
263
+ if (attributeValue && startsWith(attributeName, 'data-')) {
264
+ // Exception: it's safe to reveal the `${PRIVACY_ATTR_NAME}` attr
265
+ return CENSORED_STRING_MARK;
266
+ }
267
+ }
268
+
269
+ if (!attributeValue || typeof attributeValue !== 'string') {
270
+ return attributeValue;
271
+ } // Minimum Fix for customer.
272
+
273
+
274
+ if (attributeValue.length > MAX_ATTRIBUTE_VALUE_CHAR_LENGTH && attributeValue.slice(0, 5) === 'data:') {
275
+ return 'data:truncated';
276
+ }
277
+
278
+ return attributeValue;
279
+ }
280
+ var _nextId = 1;
281
+
282
+ function generateNextId() {
283
+ return _nextId++;
284
+ }
285
+
286
+ var TAG_NAME_REGEX = /[^a-z1-6-_]/;
287
+
288
+ function getValidTagName(tagName) {
289
+ var processedTagName = tagName.toLowerCase().trim();
290
+
291
+ if (TAG_NAME_REGEX.test(processedTagName)) {
292
+ // if the tag name is odd and we cannot extract
293
+ // anything from the string, then we return a
294
+ // generic div
295
+ return 'div';
296
+ }
297
+
298
+ return processedTagName;
299
+ }
300
+
301
+ function getCssRulesString(s) {
302
+ try {
303
+ var rules = s.rules || s.cssRules;
304
+
305
+ if (rules) {
306
+ var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
307
+ return switchToAbsoluteUrl(styleSheetCssText, s.href);
308
+ }
309
+
310
+ return null;
311
+ } catch (error) {
312
+ return null;
313
+ }
314
+ }
315
+
316
+ function getCssRuleString(rule) {
317
+ return isCSSImportRule(rule) ? getCssRulesString(rule.styleSheet) || '' : rule.cssText;
318
+ }
319
+
320
+ function isCSSImportRule(rule) {
321
+ return 'styleSheet' in rule;
322
+ }
323
+
324
+ function isSVGElement(el) {
325
+ return el.tagName === 'svg' || el instanceof SVGElement;
326
+ }
327
+
328
+ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
329
+ if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
330
+ return {};
331
+ }
332
+
333
+ var safeAttrs = {};
334
+ var tagName = getValidTagName(element.tagName);
335
+ var doc = element.ownerDocument;
336
+
337
+ for (var i = 0; i < element.attributes.length; i += 1) {
338
+ var attribute = element.attributes.item(i);
339
+ var attributeName = attribute.name;
340
+ var attributeValue = serializeAttribute(element, nodePrivacyLevel, attributeName, options.configuration);
341
+
342
+ if (attributeValue !== null) {
343
+ safeAttrs[attributeName] = attributeValue;
344
+ }
345
+ }
346
+
347
+ if (element.value && (tagName === 'textarea' || tagName === 'select' || tagName === 'option' || tagName === 'input')) {
348
+ var formValue = getElementInputValue(element, nodePrivacyLevel);
349
+
350
+ if (formValue !== undefined) {
351
+ safeAttrs.value = formValue;
352
+ }
353
+ }
354
+ /**
355
+ * <Option> can be selected, which occurs if its `value` matches ancestor `<Select>.value`
356
+ */
357
+
358
+
359
+ if (tagName === 'option' && nodePrivacyLevel === NodePrivacyLevel.ALLOW) {
360
+ // For privacy=`MASK`, all the values would be the same, so skip.
361
+ var optionElement = element;
362
+
363
+ if (optionElement.selected) {
364
+ safeAttrs.selected = optionElement.selected;
365
+ }
366
+ } // remote css
367
+
368
+
369
+ if (tagName === 'link') {
370
+ var stylesheet = Array.from(doc.styleSheets).find(function (s) {
371
+ return s.href === element.href;
372
+ });
373
+ var cssText = getCssRulesString(stylesheet);
374
+
375
+ if (cssText && stylesheet) {
376
+ safeAttrs._cssText = cssText;
377
+ }
378
+ } // dynamic stylesheet
379
+
380
+
381
+ if (tagName === 'style' && element.sheet && // TODO: Currently we only try to get dynamic stylesheet when it is an empty style element
382
+ !(element.innerText || element.textContent || '').trim().length) {
383
+ var cssText = getCssRulesString(element.sheet);
384
+
385
+ if (cssText) {
386
+ safeAttrs._cssText = cssText;
387
+ }
388
+ }
389
+ /**
390
+ * Forms: input[type=checkbox,radio]
391
+ * The `checked` property for <input> is a little bit special:
392
+ * 1. el.checked is a setter that returns if truthy.
393
+ * 2. getAttribute returns the string value
394
+ * getAttribute('checked') does not sync with `Element.checked`, so use JS property
395
+ * NOTE: `checked` property exists on `HTMLInputElement`. For serializer assumptions, we check for type=radio|check.
396
+ */
397
+
398
+
399
+ var inputElement = element;
400
+
401
+ if (tagName === 'input' && (inputElement.type === 'radio' || inputElement.type === 'checkbox')) {
402
+ if (nodePrivacyLevel === NodePrivacyLevel.ALLOW) {
403
+ safeAttrs.checked = !!inputElement.checked;
404
+ } else if (shouldMaskNode(inputElement, nodePrivacyLevel)) {
405
+ delete safeAttrs.checked;
406
+ }
407
+ }
408
+ /**
409
+ * Serialize the media playback state
410
+ */
411
+
412
+
413
+ if (tagName === 'audio' || tagName === 'video') {
414
+ var mediaElement = element;
415
+ safeAttrs.rr_mediaState = mediaElement.paused ? 'paused' : 'played';
416
+ }
417
+ /**
418
+ * Serialize the scroll state for each element only for full snapshot
419
+ */
420
+
421
+
422
+ var scrollTop;
423
+ var scrollLeft;
424
+ var serializationContext = options.serializationContext;
425
+
426
+ switch (serializationContext.status) {
427
+ case SerializationContextStatus.INITIAL_FULL_SNAPSHOT:
428
+ scrollTop = Math.round(element.scrollTop);
429
+ scrollLeft = Math.round(element.scrollLeft);
430
+
431
+ if (scrollTop || scrollLeft) {
432
+ serializationContext.elementsScrollPositions.set(element, {
433
+ scrollTop: scrollTop,
434
+ scrollLeft: scrollLeft
435
+ });
436
+ }
437
+
438
+ break;
439
+
440
+ case SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT:
441
+ if (serializationContext.elementsScrollPositions.has(element)) {
442
+ ;
443
+ ({
444
+ scrollTop,
445
+ scrollLeft
446
+ } = serializationContext.elementsScrollPositions.get(element));
447
+ }
448
+
449
+ break;
450
+ }
451
+
452
+ if (scrollLeft) {
453
+ safeAttrs.rr_scrollLeft = scrollLeft;
454
+ }
455
+
456
+ if (scrollTop) {
457
+ safeAttrs.rr_scrollTop = scrollTop;
458
+ }
459
+
460
+ return safeAttrs;
461
+ }
@@ -0,0 +1,49 @@
1
+ import { DOM_EVENT } from '@cloudcare/browser-core';
2
+ import { startMutationObserver } from './mutationObserver';
3
+ import { initInputObserver } from './observers';
4
+ export var initShadowRootsController = function initShadowRootsController(configuration, data) {
5
+ var mutationCb = data.mutationCb;
6
+ var inputCb = data.inputCb;
7
+ var controllerByShadowRoot = new Map();
8
+ var shadowRootsController = {
9
+ addShadowRoot: function addShadowRoot(shadowRoot) {
10
+ var _startMutaionObserve = startMutationObserver(mutationCb, configuration, shadowRootsController, shadowRoot);
11
+
12
+ var flush = _startMutaionObserve.flush;
13
+ var stopMutationObserver = _startMutaionObserve.stop; // the change event no do bubble up across the shadow root, we have to listen on the shadow root
14
+
15
+ var stopInputObserver = initInputObserver(inputCb, configuration.defaultPrivacyLevel, {
16
+ target: shadowRoot,
17
+ domEvents: [DOM_EVENT.CHANGE]
18
+ });
19
+ controllerByShadowRoot.set(shadowRoot, {
20
+ flush: flush,
21
+ stop: function stop() {
22
+ stopMutationObserver();
23
+ stopInputObserver();
24
+ }
25
+ });
26
+ },
27
+ removeShadowRoot: function removeShadowRoot(shadowRoot) {
28
+ var entry = controllerByShadowRoot.get(shadowRoot);
29
+
30
+ if (!entry) {
31
+ return;
32
+ }
33
+
34
+ entry.stop();
35
+ controllerByShadowRoot.delete(shadowRoot);
36
+ },
37
+ stop: function stop() {
38
+ controllerByShadowRoot.forEach(function (event) {
39
+ event.stop();
40
+ });
41
+ },
42
+ flush: function flush() {
43
+ controllerByShadowRoot.forEach(function (event) {
44
+ event.flush();
45
+ });
46
+ }
47
+ };
48
+ return shadowRootsController;
49
+ };
@@ -0,0 +1,38 @@
1
+ import { assign, timeStampNow } from '@cloudcare/browser-core';
2
+ import { RecordType } from '../../../types';
3
+ export function isTouchEvent(event) {
4
+ return Boolean(event.changedTouches);
5
+ }
6
+ export function forEach(list, callback) {
7
+ Array.prototype.forEach.call(list, callback);
8
+ }
9
+ export function assembleIncrementalSnapshot(source, data) {
10
+ return {
11
+ data: assign({
12
+ source: source
13
+ }, data),
14
+ type: RecordType.IncrementalSnapshot,
15
+ timestamp: timeStampNow()
16
+ };
17
+ }
18
+ export function getPathToNestedCSSRule(rule) {
19
+ var path = [];
20
+ var currentRule = rule;
21
+
22
+ while (currentRule.parentRule) {
23
+ var rules = Array.from(currentRule.parentRule.cssRules);
24
+ var index = rules.indexOf(currentRule);
25
+ path.unshift(index);
26
+ currentRule = currentRule.parentRule;
27
+ } // A rule may not be attached to a stylesheet
28
+
29
+
30
+ if (!currentRule.parentStyleSheet) {
31
+ return;
32
+ }
33
+
34
+ var rules = Array.from(currentRule.parentStyleSheet.cssRules);
35
+ var index = rules.indexOf(currentRule);
36
+ path.unshift(index);
37
+ return path;
38
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Browsers have not standardized various dimension properties. Mobile devices typically report
3
+ * dimensions in reference to the visual viewport, while desktop uses the layout viewport. For example,
4
+ * Mobile Chrome will change innerWidth when a pinch zoom takes place, while Chrome Desktop (mac) will not.
5
+ *
6
+ * With the new Viewport API, we now calculate and normalize dimension properties to the layout viewport.
7
+ * If the VisualViewport API is not supported by a browser, it isn't reasonably possible to detect or normalize
8
+ * which viewport is being measured. Therefore these exported functions will fallback to assuming that the layout
9
+ * viewport is being measured by the browser
10
+ */
11
+ // Scrollbar widths vary across properties on different devices and browsers
12
+ var TOLERANCE = 25;
13
+ /**
14
+ * Use the Visual Viewport API's properties to measure scrollX/Y in reference to the layout viewport
15
+ * in order to determine if window.scrollX/Y is measuring the layout or visual viewport.
16
+ * This finding corresponds to which viewport mouseEvent.clientX/Y and window.innerWidth/Height measures.
17
+ */
18
+
19
+ function isVisualViewportFactoredIn() {
20
+ var visual = window.visualViewport;
21
+ return Math.abs(visual.pageTop - visual.offsetTop - window.scrollY) > TOLERANCE || Math.abs(visual.pageLeft - visual.offsetLeft - window.scrollX) > TOLERANCE;
22
+ }
23
+
24
+ export var convertMouseEventToLayoutCoordinates = function convertMouseEventToLayoutCoordinates(clientX, clientY) {
25
+ var visual = window.visualViewport;
26
+ var normalised = {
27
+ layoutViewportX: clientX,
28
+ layoutViewportY: clientY,
29
+ visualViewportX: clientX,
30
+ visualViewportY: clientY
31
+ };
32
+
33
+ if (!visual) {
34
+ // On old browsers, we cannot normalise, so fallback to clientX/Y
35
+ return normalised;
36
+ } else if (isVisualViewportFactoredIn()) {
37
+ // Typically Mobile Devices
38
+ normalised.layoutViewportX = Math.round(clientX + visual.offsetLeft);
39
+ normalised.layoutViewportY = Math.round(clientY + visual.offsetTop);
40
+ } else {
41
+ // Typically Desktop Devices
42
+ normalised.visualViewportX = Math.round(clientX - visual.offsetLeft);
43
+ normalised.visualViewportY = Math.round(clientY - visual.offsetTop);
44
+ }
45
+
46
+ return normalised;
47
+ };
48
+ export var getVisualViewport = function getVisualViewport() {
49
+ var visual = window.visualViewport;
50
+ return {
51
+ scale: visual.scale,
52
+ offsetLeft: visual.offsetLeft,
53
+ offsetTop: visual.offsetTop,
54
+ pageLeft: visual.pageLeft,
55
+ pageTop: visual.pageTop,
56
+ height: visual.height,
57
+ width: visual.width
58
+ };
59
+ };
60
+ export function getScrollX() {
61
+ var scrollX;
62
+ var visual = window.visualViewport;
63
+
64
+ if (visual) {
65
+ scrollX = visual.pageLeft - visual.offsetLeft;
66
+ } else if (window.scrollX !== undefined) {
67
+ scrollX = window.scrollX;
68
+ } else {
69
+ scrollX = window.pageXOffset || 0;
70
+ }
71
+
72
+ return Math.round(scrollX);
73
+ }
74
+ export function getScrollY() {
75
+ var scrollY;
76
+ var visual = window.visualViewport;
77
+
78
+ if (visual) {
79
+ scrollY = visual.pageTop - visual.offsetTop;
80
+ } else if (window.scrollY !== undefined) {
81
+ scrollY = window.scrollY;
82
+ } else {
83
+ scrollY = window.pageYOffset || 0;
84
+ }
85
+
86
+ return Math.round(scrollY);
87
+ }
@@ -0,0 +1,64 @@
1
+ export var MAX_STATS_HISTORY = 10;
2
+ var statsPerView;
3
+ export function getSegmentsCount(viewId) {
4
+ return getOrCreateReplayStats(viewId).segments_count;
5
+ }
6
+ export function addSegment(viewId) {
7
+ getOrCreateReplayStats(viewId).segments_count += 1;
8
+ }
9
+ export function addRecord(viewId) {
10
+ getOrCreateReplayStats(viewId).records_count += 1;
11
+ }
12
+ export function addWroteData(viewId, additionalBytesCount) {
13
+ getOrCreateReplayStats(viewId).segments_total_raw_size += additionalBytesCount;
14
+ }
15
+ export function getReplayStats(viewId) {
16
+ return statsPerView && statsPerView.get(viewId);
17
+ }
18
+ export function resetReplayStats() {
19
+ statsPerView = undefined;
20
+ }
21
+
22
+ function getOrCreateReplayStats(viewId) {
23
+ if (!statsPerView) {
24
+ statsPerView = new Map();
25
+ }
26
+
27
+ var replayStats;
28
+
29
+ if (statsPerView.has(viewId)) {
30
+ replayStats = statsPerView.get(viewId);
31
+ } else {
32
+ replayStats = {
33
+ records_count: 0,
34
+ segments_count: 0,
35
+ segments_total_raw_size: 0
36
+ };
37
+ statsPerView.set(viewId, replayStats);
38
+
39
+ if (statsPerView.size > MAX_STATS_HISTORY) {
40
+ deleteOldestStats();
41
+ }
42
+ }
43
+
44
+ return replayStats;
45
+ }
46
+
47
+ function deleteOldestStats() {
48
+ if (!statsPerView) {
49
+ return;
50
+ }
51
+
52
+ if (statsPerView.keys) {
53
+ statsPerView.delete(statsPerView.keys().next().value);
54
+ } else {
55
+ // IE11 doesn't support map.keys
56
+ var isFirst = true;
57
+ statsPerView.forEach(function (_value, key) {
58
+ if (isFirst) {
59
+ statsPerView.delete(key);
60
+ isFirst = false;
61
+ }
62
+ });
63
+ }
64
+ }