@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,158 @@
1
+ import { timeStampNow } from '@cloudcare/browser-core';
2
+ import { getViewportDimension } from '../../initViewportObservable';
3
+ import { RecordType, IncrementalSource } from '../../../types';
4
+ import { serializeDocument, SerializationContextStatus } from './serialize';
5
+ import { initObservers } from './observers';
6
+ import { getVisualViewport, getScrollX, getScrollY } from './viewports';
7
+ import { assembleIncrementalSnapshot } from './utils';
8
+ import { createElementsScrollPositions } from './elementsScrollPositions';
9
+ import { initShadowRootsController } from './shadowRootsController';
10
+ export function record(options) {
11
+ var emit = options.emit; // runtime checks for user options
12
+
13
+ if (!emit) {
14
+ throw new Error('emit function is required');
15
+ }
16
+
17
+ var elementsScrollPositions = createElementsScrollPositions();
18
+
19
+ var mutationCb = function mutationCb(mutation) {
20
+ emit(assembleIncrementalSnapshot(IncrementalSource.Mutation, mutation));
21
+ };
22
+
23
+ var inputCb = function inputCb(s) {
24
+ emit(assembleIncrementalSnapshot(IncrementalSource.Input, s));
25
+ };
26
+
27
+ var shadowRootsController = initShadowRootsController(options.configuration, {
28
+ mutationCb,
29
+ inputCb
30
+ });
31
+
32
+ var takeFullSnapshot = function takeFullSnapshot(timestamp, serializationContext) {
33
+ if (typeof timestamp === 'undefined') {
34
+ timestamp = timeStampNow();
35
+ }
36
+
37
+ if (typeof serializationContext === 'undefined') {
38
+ serializationContext = {
39
+ status: SerializationContextStatus.INITIAL_FULL_SNAPSHOT,
40
+ elementsScrollPositions: elementsScrollPositions,
41
+ shadowRootsController: shadowRootsController
42
+ };
43
+ }
44
+
45
+ var _viewportDimension = getViewportDimension();
46
+
47
+ var width = _viewportDimension.width;
48
+ var height = _viewportDimension.height;
49
+ emit({
50
+ data: {
51
+ height: height,
52
+ href: window.location.href,
53
+ width: width
54
+ },
55
+ type: RecordType.Meta,
56
+ timestamp: timestamp
57
+ });
58
+ emit({
59
+ data: {
60
+ has_focus: document.hasFocus()
61
+ },
62
+ type: RecordType.Focus,
63
+ timestamp: timestamp
64
+ });
65
+ emit({
66
+ data: {
67
+ node: serializeDocument(document, options.configuration, serializationContext),
68
+ initialOffset: {
69
+ left: getScrollX(),
70
+ top: getScrollY()
71
+ }
72
+ },
73
+ type: RecordType.FullSnapshot,
74
+ timestamp: timestamp
75
+ });
76
+
77
+ if (window.visualViewport) {
78
+ emit({
79
+ data: getVisualViewport(),
80
+ type: RecordType.VisualViewport,
81
+ timestamp: timestamp
82
+ });
83
+ }
84
+ };
85
+
86
+ takeFullSnapshot();
87
+
88
+ var _initObservers = initObservers({
89
+ lifeCycle: options.lifeCycle,
90
+ configuration: options.configuration,
91
+ elementsScrollPositions: elementsScrollPositions,
92
+ inputCb: inputCb,
93
+ mediaInteractionCb: function mediaInteractionCb(p) {
94
+ emit(assembleIncrementalSnapshot(IncrementalSource.MediaInteraction, p));
95
+ },
96
+ mouseInteractionCb: function mouseInteractionCb(mouseInteractionRecord) {
97
+ emit(mouseInteractionRecord);
98
+ },
99
+ mousemoveCb: function mousemoveCb(positions, source) {
100
+ emit(assembleIncrementalSnapshot(source, {
101
+ positions: positions
102
+ }));
103
+ },
104
+ mutationCb: mutationCb,
105
+ scrollCb: function scrollCb(p) {
106
+ emit(assembleIncrementalSnapshot(IncrementalSource.Scroll, p));
107
+ },
108
+ styleSheetCb: function styleSheetCb(r) {
109
+ emit(assembleIncrementalSnapshot(IncrementalSource.StyleSheetRule, r));
110
+ },
111
+ viewportResizeCb: function viewportResizeCb(d) {
112
+ emit(assembleIncrementalSnapshot(IncrementalSource.ViewportResize, d));
113
+ },
114
+ frustrationCb: function frustrationCb(frustrationRecord) {
115
+ emit(frustrationRecord);
116
+ },
117
+ focusCb: function focusCb(data) {
118
+ emit({
119
+ data: data,
120
+ type: RecordType.Focus,
121
+ timestamp: timeStampNow()
122
+ });
123
+ },
124
+ visualViewportResizeCb: function visualViewportResizeCb(data) {
125
+ emit({
126
+ data: data,
127
+ type: RecordType.VisualViewport,
128
+ timestamp: timeStampNow()
129
+ });
130
+ },
131
+ shadowRootsController: shadowRootsController
132
+ });
133
+
134
+ var stopObservers = _initObservers.stop;
135
+ var flushMutationsFromObservers = _initObservers.flush;
136
+
137
+ function flushMutations() {
138
+ shadowRootsController.flush();
139
+ flushMutationsFromObservers();
140
+ }
141
+
142
+ return {
143
+ stop: function stop() {
144
+ shadowRootsController.stop();
145
+ stopObservers();
146
+ },
147
+ takeSubsequentFullSnapshot: function takeSubsequentFullSnapshot(timestamp) {
148
+ flushMutations();
149
+ takeFullSnapshot(timestamp, {
150
+ shadowRootsController: shadowRootsController,
151
+ status: SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT,
152
+ elementsScrollPositions: elementsScrollPositions
153
+ });
154
+ },
155
+ flushMutations: flushMutations,
156
+ shadowRootsController: shadowRootsController
157
+ };
158
+ }
@@ -0,0 +1,107 @@
1
+ import { getParentNode, isNodeShadowRoot, buildUrl } from '@cloudcare/browser-core';
2
+ import { CENSORED_STRING_MARK } from '../../../constants';
3
+ import { shouldMaskNode } from './privacy';
4
+ var serializedNodeIds = new WeakMap();
5
+ export function hasSerializedNode(node) {
6
+ return serializedNodeIds.has(node);
7
+ }
8
+ export function nodeAndAncestorsHaveSerializedNode(node) {
9
+ var current = node;
10
+
11
+ while (current) {
12
+ if (!hasSerializedNode(current) && !isNodeShadowRoot(current)) {
13
+ return false;
14
+ }
15
+
16
+ current = getParentNode(current);
17
+ }
18
+
19
+ return true;
20
+ }
21
+ export function getSerializedNodeId(node) {
22
+ return serializedNodeIds.get(node);
23
+ }
24
+ export function setSerializedNodeId(node, serializeNodeId) {
25
+ serializedNodeIds.set(node, serializeNodeId);
26
+ }
27
+ /**
28
+ * Get the element "value" to be serialized as an attribute or an input update record. It respects
29
+ * the input privacy mode of the element.
30
+ * PERFROMANCE OPTIMIZATION: Assumes that privacy level `HIDDEN` is never encountered because of earlier checks.
31
+ */
32
+
33
+ export function getElementInputValue(element, nodePrivacyLevel) {
34
+ /*
35
+ BROWSER SPEC NOTE: <input>, <select>
36
+ For some <input> elements, the `value` is an exceptional property/attribute that has the
37
+ value synced between el.value and el.getAttribute()
38
+ input[type=button,checkbox,hidden,image,radio,reset,submit]
39
+ */
40
+ var tagName = element.tagName;
41
+ var value = element.value;
42
+
43
+ if (shouldMaskNode(element, nodePrivacyLevel)) {
44
+ var type = element.type;
45
+
46
+ if (tagName === 'INPUT' && (type === 'button' || type === 'submit' || type === 'reset')) {
47
+ // Overrule `MASK` privacy level for button-like element values, as they are used during replay
48
+ // to display their label. They can still be hidden via the "hidden" privacy attribute or class name.
49
+ return value;
50
+ } else if (!value || tagName === 'OPTION') {
51
+ // <Option> value provides no benefit
52
+ return;
53
+ }
54
+
55
+ return CENSORED_STRING_MARK;
56
+ }
57
+
58
+ if (tagName === 'OPTION' || tagName === 'SELECT') {
59
+ return element.value;
60
+ }
61
+
62
+ if (tagName !== 'INPUT' && tagName !== 'TEXTAREA') {
63
+ return;
64
+ }
65
+
66
+ return value;
67
+ }
68
+ export var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
69
+ export var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//;
70
+ export var DATA_URI = /^data:.*,/i;
71
+ export function switchToAbsoluteUrl(cssText, cssHref) {
72
+ return cssText.replace(URL_IN_CSS_REF, function (matchingSubstring, singleQuote, urlWrappedInSingleQuotes, doubleQuote, urlWrappedInDoubleQuotes, urlNotWrappedInQuotes) {
73
+ var url = urlWrappedInSingleQuotes || urlWrappedInDoubleQuotes || urlNotWrappedInQuotes;
74
+
75
+ if (!cssHref || !url || ABSOLUTE_URL.test(url) || DATA_URI.test(url)) {
76
+ return matchingSubstring;
77
+ }
78
+
79
+ var quote = singleQuote || doubleQuote || '';
80
+ return "url(".concat(quote).concat(makeUrlAbsolute(url, cssHref)).concat(quote, ")");
81
+ });
82
+ }
83
+ export function makeUrlAbsolute(url, baseUrl) {
84
+ try {
85
+ return buildUrl(url, baseUrl).href;
86
+ } catch (_) {
87
+ return url;
88
+ }
89
+ }
90
+ export function serializeStyleSheets(cssStyleSheets) {
91
+ if (cssStyleSheets === undefined || cssStyleSheets.length === 0) {
92
+ return undefined;
93
+ }
94
+
95
+ return cssStyleSheets.map(function (cssStyleSheet) {
96
+ var rules = cssStyleSheet.cssRules || cssStyleSheet.rules;
97
+ var cssRules = Array.from(rules, function (cssRule) {
98
+ return cssRule.cssText;
99
+ });
100
+ var styleSheet = {
101
+ cssRules: cssRules,
102
+ disabled: cssStyleSheet.disabled || undefined,
103
+ media: cssStyleSheet.media.length > 0 ? Array.from(cssStyleSheet.media) : undefined
104
+ };
105
+ return styleSheet;
106
+ });
107
+ }