@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.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/recorderApi.js +161 -0
- package/cjs/boot/rum.entry.js +6 -1
- package/cjs/boot/rum.js +15 -5
- package/cjs/boot/rumPublicApi.js +8 -4
- package/cjs/boot/startRecording.js +55 -0
- package/cjs/constants.js +52 -0
- package/cjs/domain/assembly.js +1 -7
- package/cjs/domain/configuration.js +3 -2
- package/cjs/domain/contexts/foregroundContexts.js +138 -0
- package/cjs/domain/contexts/internalContext.js +1 -1
- package/cjs/domain/contexts/urlContexts.js +9 -2
- package/cjs/domain/domMutationCollection.js +4 -5
- package/cjs/domain/initViewportObservable.js +52 -0
- package/cjs/domain/locationChangeObservable.js +12 -26
- package/cjs/domain/performanceCollection.js +2 -13
- package/cjs/domain/replay/record/elementsScrollPositions.js +27 -0
- package/cjs/domain/replay/record/index.js +41 -0
- package/cjs/domain/replay/record/mutationBatch.js +58 -0
- package/cjs/domain/replay/record/mutationObserver.js +383 -0
- package/cjs/domain/replay/record/observers.js +473 -0
- package/cjs/domain/replay/record/privacy.js +256 -0
- package/cjs/domain/replay/record/record.js +174 -0
- package/cjs/domain/replay/record/serializationUtils.js +137 -0
- package/cjs/domain/replay/record/serialize.js +488 -0
- package/cjs/domain/replay/record/shadowRootsController.js +61 -0
- package/cjs/domain/replay/record/utils.js +53 -0
- package/cjs/domain/replay/record/viewports.js +104 -0
- package/cjs/domain/replay/replayStats.js +83 -0
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +43 -0
- package/cjs/domain/replay/segmentCollection/deflateWorker.js +4399 -0
- package/cjs/domain/replay/segmentCollection/index.js +33 -0
- package/cjs/domain/replay/segmentCollection/segment.js +101 -0
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +179 -0
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +126 -0
- package/cjs/domain/requestCollection.js +35 -17
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +8 -6
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +111 -75
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +94 -54
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +45 -0
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/cjs/domain/rumEventsCollection/view/trackViews.js +21 -18
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/cjs/domain/rumSessionManager.js +6 -3
- package/cjs/domain/tracing/getDocumentTraceId.js +2 -10
- package/cjs/domain/trackEventCounts.js +10 -2
- package/cjs/domain/waitPageActivityEnd.js +5 -1
- package/cjs/transport/startRumBatch.js +5 -7
- package/cjs/types/index.js +18 -0
- package/cjs/types/sessionReplayConstants.js +56 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/recorderApi.js +149 -0
- package/esm/boot/rum.entry.js +4 -1
- package/esm/boot/rum.js +15 -6
- package/esm/boot/rumPublicApi.js +8 -4
- package/esm/boot/startRecording.js +44 -0
- package/esm/constants.js +31 -0
- package/esm/domain/assembly.js +1 -7
- package/esm/domain/configuration.js +4 -3
- package/esm/domain/contexts/foregroundContexts.js +122 -0
- package/esm/domain/contexts/internalContext.js +1 -1
- package/esm/domain/contexts/urlContexts.js +10 -3
- package/esm/domain/domMutationCollection.js +5 -6
- package/esm/domain/initViewportObservable.js +39 -0
- package/esm/domain/locationChangeObservable.js +13 -27
- package/esm/domain/performanceCollection.js +1 -12
- package/esm/domain/replay/record/elementsScrollPositions.js +20 -0
- package/esm/domain/replay/record/index.js +3 -0
- package/esm/domain/replay/record/mutationBatch.js +35 -0
- package/esm/domain/replay/record/mutationObserver.js +331 -0
- package/esm/domain/replay/record/observers.js +457 -0
- package/esm/domain/replay/record/privacy.js +233 -0
- package/esm/domain/replay/record/record.js +158 -0
- package/esm/domain/replay/record/serializationUtils.js +107 -0
- package/esm/domain/replay/record/serialize.js +461 -0
- package/esm/domain/replay/record/shadowRootsController.js +49 -0
- package/esm/domain/replay/record/utils.js +38 -0
- package/esm/domain/replay/record/viewports.js +87 -0
- package/esm/domain/replay/replayStats.js +64 -0
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +31 -0
- package/esm/domain/replay/segmentCollection/deflateWorker.js +4390 -0
- package/esm/domain/replay/segmentCollection/index.js +3 -0
- package/esm/domain/replay/segmentCollection/segment.js +84 -0
- package/esm/domain/replay/segmentCollection/segmentCollection.js +158 -0
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js +113 -0
- package/esm/domain/requestCollection.js +36 -18
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/esm/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +6 -6
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +105 -74
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +99 -59
- package/esm/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +33 -0
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +1 -18
- package/esm/domain/rumEventsCollection/view/trackViews.js +21 -19
- package/esm/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/esm/domain/rumSessionManager.js +6 -3
- package/esm/domain/tracing/getDocumentTraceId.js +1 -9
- package/esm/domain/trackEventCounts.js +10 -2
- package/esm/domain/waitPageActivityEnd.js +5 -1
- package/esm/transport/startRumBatch.js +5 -7
- package/esm/types/index.js +1 -0
- package/esm/types/sessionReplayConstants.js +45 -0
- package/package.json +3 -3
- package/src/boot/recorderApi.js +166 -0
- package/src/boot/rum.entry.js +4 -1
- package/src/boot/rum.js +38 -10
- package/src/boot/rumPublicApi.js +13 -3
- package/src/boot/startRecording.js +77 -0
- package/src/constants.js +37 -0
- package/src/domain/assembly.js +1 -6
- package/src/domain/configuration.js +10 -2
- package/src/domain/contexts/foregroundContexts.js +140 -0
- package/src/domain/contexts/internalContext.js +10 -4
- package/src/domain/contexts/urlContexts.js +29 -15
- package/src/domain/domMutationCollection.js +14 -6
- package/src/domain/initViewportObservable.js +46 -0
- package/src/domain/locationChangeObservable.js +17 -25
- package/src/domain/performanceCollection.js +42 -42
- package/src/domain/replay/record/elementsScrollPositions.js +22 -0
- package/src/domain/replay/record/index.js +7 -0
- package/src/domain/replay/record/mutationBatch.js +38 -0
- package/src/domain/replay/record/mutationObserver.js +393 -0
- package/src/domain/replay/record/observers.js +562 -0
- package/src/domain/replay/record/privacy.js +304 -0
- package/src/domain/replay/record/record.js +158 -0
- package/src/domain/replay/record/serializationUtils.js +134 -0
- package/src/domain/replay/record/serialize.js +497 -0
- package/src/domain/replay/record/shadowRootsController.js +58 -0
- package/src/domain/replay/record/utils.js +44 -0
- package/src/domain/replay/record/viewports.js +89 -0
- package/src/domain/replay/replayStats.js +67 -0
- package/src/domain/replay/segmentCollection/buildReplayPayload.js +34 -0
- package/src/domain/replay/segmentCollection/deflateWorker.js +4577 -0
- package/src/domain/replay/segmentCollection/index.js +6 -0
- package/src/domain/replay/segmentCollection/segment.js +87 -0
- package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
- package/src/domain/replay/segmentCollection/startDeflateWorker.js +101 -0
- package/src/domain/requestCollection.js +64 -28
- package/src/domain/rumEventsCollection/actions/actionCollection.js +11 -4
- package/src/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +7 -4
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +9 -6
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +130 -108
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +26 -27
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +162 -92
- package/src/domain/rumEventsCollection/error/errorCollection.js +11 -5
- package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +38 -0
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/src/domain/rumEventsCollection/view/trackViews.js +98 -68
- package/src/domain/rumEventsCollection/view/viewCollection.js +15 -7
- package/src/domain/rumSessionManager.js +33 -19
- package/src/domain/tracing/getDocumentTraceId.js +6 -9
- package/src/domain/trackEventCounts.js +10 -4
- package/src/domain/waitPageActivityEnd.js +4 -1
- package/src/transport/startRumBatch.js +29 -24
- package/src/types/index.js +1 -0
- package/src/types/sessionReplayConstants.js +49 -0
|
@@ -3,130 +3,144 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.STABLE_ATTRIBUTES = void 0;
|
|
7
|
+
exports.getSelectorFromElement = getSelectorFromElement;
|
|
8
|
+
exports.supportScopeSelector = supportScopeSelector;
|
|
7
9
|
|
|
8
10
|
var _browserCore = require("@cloudcare/browser-core");
|
|
9
11
|
|
|
12
|
+
var _getActionNameFromElement = require("./getActionNameFromElement");
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Stable attributes are attributes that are commonly used to identify parts of a UI (ex:
|
|
12
16
|
* component). Those attribute values should not be generated randomly (hardcoded most of the time)
|
|
13
17
|
* and stay the same across deploys. They are not necessarily unique across the document.
|
|
14
18
|
*/
|
|
15
|
-
var STABLE_ATTRIBUTES = [
|
|
19
|
+
var STABLE_ATTRIBUTES = [_getActionNameFromElement.DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE, // Common test attributes (list provided by google recorder)
|
|
16
20
|
'data-testid', 'data-test', 'data-qa', 'data-cy', 'data-test-id', 'data-qa-id', 'data-testing', // FullStory decorator attributes:
|
|
17
|
-
'data-component', 'data-element', 'data-source-file'];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var attributeSelectors = getStableAttributeSelectors();
|
|
21
|
+
'data-component', 'data-element', 'data-source-file']; // Selectors to use if they target a single element on the whole document. Those selectors are
|
|
22
|
+
// considered as "stable" and uniquely identify an element regardless of the page state. If we find
|
|
23
|
+
// one, we should consider the selector "complete" and stop iterating over ancestors.
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
25
|
+
exports.STABLE_ATTRIBUTES = STABLE_ATTRIBUTES;
|
|
26
|
+
var GLOBALLY_UNIQUE_SELECTOR_GETTERS = [getStableAttributeSelector, getIDSelector]; // Selectors to use if they target a single element among an element descendants. Those selectors
|
|
27
|
+
// are more brittle than "globally unique" selectors and should be combined with ancestor selectors
|
|
28
|
+
// to improve specificity.
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
selector: getSelectorFromElement(element, [getIDSelector], [getClassSelector]),
|
|
30
|
-
selector_with_stable_attributes: getSelectorFromElement(element, attributeSelectors.concat(getIDSelector), attributeSelectors.concat(getClassSelector)),
|
|
31
|
-
selector_without_classes: getSelectorFromElement(element, attributeSelectors.concat(getIDSelector), attributeSelectors)
|
|
32
|
-
};
|
|
33
|
-
}
|
|
30
|
+
var UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS = [getStableAttributeSelector, getClassSelector, getTagNameSelector];
|
|
34
31
|
|
|
35
|
-
function getSelectorFromElement(targetElement,
|
|
32
|
+
function getSelectorFromElement(targetElement, actionNameAttribute) {
|
|
36
33
|
var targetElementSelector = [];
|
|
37
34
|
var element = targetElement;
|
|
38
35
|
|
|
39
36
|
while (element && element.nodeName !== 'HTML') {
|
|
40
|
-
var globallyUniqueSelector = findSelector(element,
|
|
37
|
+
var globallyUniqueSelector = findSelector(element, GLOBALLY_UNIQUE_SELECTOR_GETTERS, isSelectorUniqueGlobally, actionNameAttribute, targetElementSelector);
|
|
41
38
|
|
|
42
39
|
if (globallyUniqueSelector) {
|
|
43
|
-
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
var uniqueSelectorAmongChildren = findSelector(element, uniqueAmongChildrenSelectorStrategies, isSelectorUniqueAmongChildren);
|
|
48
|
-
|
|
49
|
-
if (uniqueSelectorAmongChildren) {
|
|
50
|
-
targetElementSelector.unshift(uniqueSelectorAmongChildren);
|
|
51
|
-
} else {
|
|
52
|
-
targetElementSelector.unshift(getPositionSelector(element));
|
|
40
|
+
return globallyUniqueSelector;
|
|
53
41
|
}
|
|
54
42
|
|
|
43
|
+
var uniqueSelectorAmongChildren = findSelector(element, UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS, isSelectorUniqueAmongSiblings, actionNameAttribute, targetElementSelector);
|
|
44
|
+
targetElementSelector = uniqueSelectorAmongChildren || combineSelector(getPositionSelector(element), targetElementSelector);
|
|
55
45
|
element = element.parentElement;
|
|
56
46
|
}
|
|
57
47
|
|
|
58
|
-
return targetElementSelector
|
|
48
|
+
return targetElementSelector;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isGeneratedValue(value) {
|
|
52
|
+
// To compute the "URL path group", the backend replaces every URL path parts as a question mark
|
|
53
|
+
// if it thinks the part is an identifier. The condition it uses is to checks whether a digit is
|
|
54
|
+
// present.
|
|
55
|
+
//
|
|
56
|
+
// Here, we use the same strategy: if a the value contains a digit, we consider it generated. This
|
|
57
|
+
// strategy might be a bit naive and fail in some cases, but there are many fallbacks to generate
|
|
58
|
+
// CSS selectors so it should be fine most of the time. We might want to allow customers to
|
|
59
|
+
// provide their own `isGeneratedValue` at some point.
|
|
60
|
+
return /[0-9]/.test(value);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function getIDSelector(element) {
|
|
62
|
-
if (element.id) {
|
|
64
|
+
if (element.id && !isGeneratedValue(element.id)) {
|
|
63
65
|
return '#' + (0, _browserCore.cssEscape)(element.id);
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
function getClassSelector(element) {
|
|
70
|
+
if (element.tagName === 'BODY') {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
68
74
|
if (element.classList.length > 0) {
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
for (var i = 0; i < element.classList.length; i += 1) {
|
|
76
|
+
var className = element.classList[i];
|
|
77
|
+
|
|
78
|
+
if (isGeneratedValue(className)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return element.tagName + '.' + (0, _browserCore.cssEscape)(className);
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
86
|
|
|
76
|
-
|
|
87
|
+
function getTagNameSelector(element) {
|
|
88
|
+
return element.tagName;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getStableAttributeSelector(element, actionNameAttribute) {
|
|
92
|
+
if (actionNameAttribute) {
|
|
93
|
+
var selector = getAttributeSelector(actionNameAttribute);
|
|
77
94
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return function (element) {
|
|
82
|
-
return getAttributeSelector(attribute, element);
|
|
83
|
-
};
|
|
84
|
-
});
|
|
95
|
+
if (selector) {
|
|
96
|
+
return selector;
|
|
97
|
+
}
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
for (var i = 0; i < STABLE_ATTRIBUTES.length; i++) {
|
|
101
|
+
var attributeName = STABLE_ATTRIBUTES[i];
|
|
102
|
+
var selector = getAttributeSelector(attributeName);
|
|
103
|
+
|
|
104
|
+
if (selector) {
|
|
105
|
+
return selector;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
89
108
|
|
|
90
|
-
function getAttributeSelector(attributeName
|
|
91
|
-
|
|
92
|
-
|
|
109
|
+
function getAttributeSelector(attributeName) {
|
|
110
|
+
if (element.hasAttribute(attributeName)) {
|
|
111
|
+
return element.tagName + '[' + attributeName + '="' + (0, _browserCore.cssEscape)(element.getAttribute(attributeName)) + '"]';
|
|
112
|
+
}
|
|
93
113
|
}
|
|
94
114
|
}
|
|
95
115
|
|
|
96
116
|
function getPositionSelector(element) {
|
|
97
|
-
var
|
|
98
|
-
var
|
|
99
|
-
var currentIndex = 0;
|
|
100
|
-
var elementIndex;
|
|
117
|
+
var sibling = element.parentElement && element.parentElement.firstElementChild;
|
|
118
|
+
var elementIndex = 1;
|
|
101
119
|
|
|
102
|
-
while (sibling) {
|
|
120
|
+
while (sibling && sibling !== element) {
|
|
103
121
|
if (sibling.tagName === element.tagName) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (sibling === element) {
|
|
107
|
-
elementIndex = currentIndex;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (elementIndex !== undefined && currentIndex > 1) {
|
|
111
|
-
// Performance improvement: avoid iterating over all children, stop as soon as we are sure
|
|
112
|
-
// the element is not alone
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
122
|
+
elementIndex += 1;
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
sibling = sibling.nextElementSibling;
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
return
|
|
128
|
+
return element.tagName + ':nth-of-type(' + elementIndex + ')';
|
|
121
129
|
}
|
|
122
130
|
|
|
123
|
-
function findSelector(element, selectorGetters, predicate) {
|
|
131
|
+
function findSelector(element, selectorGetters, predicate, actionNameAttribute, childSelector) {
|
|
124
132
|
for (var i = 0; i < selectorGetters.length; i++) {
|
|
125
133
|
var selectorGetter = selectorGetters[i];
|
|
126
|
-
var
|
|
134
|
+
var elementSelector = selectorGetter(element, actionNameAttribute);
|
|
127
135
|
|
|
128
|
-
if (
|
|
129
|
-
|
|
136
|
+
if (!elementSelector) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var fullSelector = combineSelector(elementSelector, childSelector);
|
|
141
|
+
|
|
142
|
+
if (predicate(element, fullSelector)) {
|
|
143
|
+
return fullSelector;
|
|
130
144
|
}
|
|
131
145
|
}
|
|
132
146
|
}
|
|
@@ -134,15 +148,37 @@ function findSelector(element, selectorGetters, predicate) {
|
|
|
134
148
|
function isSelectorUniqueGlobally(element, selector) {
|
|
135
149
|
return element.ownerDocument.body.querySelectorAll(selector).length === 1;
|
|
136
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Check whether the selector is unique among the element siblings. In other words, it returns true
|
|
153
|
+
* if "ELEMENT_PARENT > SELECTOR" returns a single element.
|
|
154
|
+
*
|
|
155
|
+
* The result will be less accurate on browsers that don't support :scope (i. e. IE): it will check
|
|
156
|
+
* for any element matching the selector contained in the parent (in other words,
|
|
157
|
+
* "ELEMENT_PARENT SELECTOR" returns a single element), regardless of whether the selector is a
|
|
158
|
+
* direct descendent of the element parent. This should not impact results too much: if it
|
|
159
|
+
* inaccurately returns false, we'll just fall back to another strategy.
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
function isSelectorUniqueAmongSiblings(element, selector) {
|
|
164
|
+
return element.parentElement.querySelectorAll(supportScopeSelector() ? combineSelector(':scope', selector) : selector).length === 1;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function combineSelector(parent, child) {
|
|
168
|
+
return child ? parent + '>' + child : parent;
|
|
169
|
+
}
|
|
137
170
|
|
|
138
|
-
|
|
139
|
-
for (var i = 0; i < element.parentElement.children.length; i++) {
|
|
140
|
-
var sibling = element.parentElement.children[i];
|
|
171
|
+
var supportScopeSelectorCache;
|
|
141
172
|
|
|
142
|
-
|
|
143
|
-
|
|
173
|
+
function supportScopeSelector() {
|
|
174
|
+
if (supportScopeSelectorCache === undefined) {
|
|
175
|
+
try {
|
|
176
|
+
document.querySelector(':scope');
|
|
177
|
+
supportScopeSelectorCache = true;
|
|
178
|
+
} catch (_unused) {
|
|
179
|
+
supportScopeSelectorCache = false;
|
|
144
180
|
}
|
|
145
181
|
}
|
|
146
182
|
|
|
147
|
-
return
|
|
183
|
+
return supportScopeSelectorCache;
|
|
148
184
|
}
|
|
@@ -8,50 +8,42 @@ exports.listenActionEvents = listenActionEvents;
|
|
|
8
8
|
var _browserCore = require("@cloudcare/browser-core");
|
|
9
9
|
|
|
10
10
|
function listenActionEvents(events) {
|
|
11
|
-
var onClick = events.onClick;
|
|
12
|
-
var onPointerDown = events.onPointerDown;
|
|
13
|
-
var hasSelectionChanged = false;
|
|
14
11
|
var selectionEmptyAtPointerDown;
|
|
15
|
-
var
|
|
12
|
+
var userActivity = {
|
|
13
|
+
selection: false,
|
|
14
|
+
input: false
|
|
15
|
+
};
|
|
16
16
|
var clickContext;
|
|
17
17
|
var listeners = [(0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.POINTER_DOWN, function (event) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
if (isValidPointerEvent(event)) {
|
|
19
|
+
selectionEmptyAtPointerDown = isSelectionEmpty();
|
|
20
|
+
userActivity = {
|
|
21
|
+
selection: false,
|
|
22
|
+
input: false
|
|
23
|
+
};
|
|
24
|
+
clickContext = events.onPointerDown(event);
|
|
23
25
|
}
|
|
24
26
|
}, {
|
|
25
27
|
capture: true
|
|
26
28
|
}), (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.SELECTION_CHANGE, function () {
|
|
27
29
|
if (!selectionEmptyAtPointerDown || !isSelectionEmpty()) {
|
|
28
|
-
|
|
30
|
+
userActivity.selection = true;
|
|
29
31
|
}
|
|
30
32
|
}, {
|
|
31
33
|
capture: true
|
|
32
|
-
}), (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.
|
|
33
|
-
if (
|
|
34
|
+
}), (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.POINTER_UP, function (event) {
|
|
35
|
+
if (isValidPointerEvent(event) && clickContext) {
|
|
34
36
|
// Use a scoped variable to make sure the value is not changed by other clicks
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
if (!hasInputChanged) {
|
|
41
|
-
setTimeout(function () {
|
|
42
|
-
userActivity.input = hasInputChanged;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
onClick(clickContext, clickEvent, function () {
|
|
47
|
-
return userActivity;
|
|
37
|
+
var localUserActivity = userActivity;
|
|
38
|
+
events.onPointerUp(clickContext, event, function () {
|
|
39
|
+
return localUserActivity;
|
|
48
40
|
});
|
|
49
41
|
clickContext = undefined;
|
|
50
42
|
}
|
|
51
43
|
}, {
|
|
52
44
|
capture: true
|
|
53
45
|
}), (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.INPUT, function () {
|
|
54
|
-
|
|
46
|
+
userActivity.input = true;
|
|
55
47
|
}, {
|
|
56
48
|
capture: true
|
|
57
49
|
})];
|
|
@@ -69,6 +61,8 @@ function isSelectionEmpty() {
|
|
|
69
61
|
return !selection || selection.isCollapsed;
|
|
70
62
|
}
|
|
71
63
|
|
|
72
|
-
function
|
|
73
|
-
return event.target instanceof Element
|
|
64
|
+
function isValidPointerEvent(event) {
|
|
65
|
+
return event.target instanceof Element && // Only consider 'primary' pointer events for now. Multi-touch support could be implemented in
|
|
66
|
+
// the future.
|
|
67
|
+
event.isPrimary !== false;
|
|
74
68
|
}
|
|
@@ -36,15 +36,14 @@ function trackClickActions(lifeCycle, domMutationObservable, configuration) {
|
|
|
36
36
|
lifeCycle.subscribe(_browserCore.LifeCycleEventType.SESSION_RENEWED, function () {
|
|
37
37
|
history.reset();
|
|
38
38
|
});
|
|
39
|
-
lifeCycle.subscribe(_browserCore.LifeCycleEventType.BEFORE_UNLOAD, stopClickChain);
|
|
40
39
|
lifeCycle.subscribe(_browserCore.LifeCycleEventType.VIEW_ENDED, stopClickChain);
|
|
41
40
|
|
|
42
41
|
var _listenActionEvents = (0, _listenActionEvents2.listenActionEvents)({
|
|
43
42
|
onPointerDown: function onPointerDown(pointerDownEvent) {
|
|
44
|
-
return processPointerDown(configuration, pointerDownEvent);
|
|
43
|
+
return processPointerDown(configuration, lifeCycle, domMutationObservable, history, pointerDownEvent);
|
|
45
44
|
},
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
onPointerUp: function onPointerUp(data, startEvent, getUserActivity) {
|
|
46
|
+
startClickAction(configuration, lifeCycle, domMutationObservable, history, stopObservable, appendClickToClickChain, data.clickActionBase, startEvent, getUserActivity, data.hadActivityOnPointerDown);
|
|
48
47
|
}
|
|
49
48
|
});
|
|
50
49
|
|
|
@@ -77,53 +76,85 @@ function trackClickActions(lifeCycle, domMutationObservable, configuration) {
|
|
|
77
76
|
});
|
|
78
77
|
}
|
|
79
78
|
}
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
function processPointerDown(configuration, lifeCycle, domMutationObservable, history, pointerDownEvent) {
|
|
82
|
+
if (!configuration.trackFrustrations && history.find()) {
|
|
83
|
+
// TODO: remove this in a future major version. To keep retrocompatibility, ignore any new
|
|
84
|
+
// action if another one is already occurring.
|
|
85
|
+
return;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
var clickActionBase = computeClickActionBase(pointerDownEvent, configuration.actionNameAttribute);
|
|
89
|
+
|
|
90
|
+
if (!configuration.trackFrustrations && !clickActionBase.name) {
|
|
91
|
+
// TODO: remove this in a future major version. To keep retrocompatibility, ignore any action
|
|
92
|
+
// with a blank name
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
var _hadActivityOnPointerDown = false;
|
|
97
|
+
(0, _waitPageActivityEnd2.waitPageActivityEnd)(lifeCycle, domMutationObservable, configuration, function (pageActivityEndEvent) {
|
|
98
|
+
_hadActivityOnPointerDown = pageActivityEndEvent.hadActivity;
|
|
99
|
+
}, // We don't care about the activity duration, we just want to know whether an activity did happen
|
|
100
|
+
// within the "validation delay" or not. Limit the duration so the callback is called sooner.
|
|
101
|
+
_waitPageActivityEnd2.PAGE_ACTIVITY_VALIDATION_DELAY);
|
|
102
|
+
return {
|
|
103
|
+
clickActionBase: clickActionBase,
|
|
104
|
+
hadActivityOnPointerDown: function hadActivityOnPointerDown() {
|
|
105
|
+
return _hadActivityOnPointerDown;
|
|
91
106
|
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function startClickAction(configuration, lifeCycle, domMutationObservable, history, stopObservable, appendClickToClickChain, clickActionBase, startEvent, getUserActivity, hadActivityOnPointerDown) {
|
|
111
|
+
var click = newClick(lifeCycle, history, getUserActivity, clickActionBase, startEvent);
|
|
92
112
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
113
|
+
if (configuration.trackFrustrations) {
|
|
114
|
+
appendClickToClickChain(click);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var _waitPageActivityEnd = (0, _waitPageActivityEnd2.waitPageActivityEnd)(lifeCycle, domMutationObservable, configuration, function (pageActivityEndEvent) {
|
|
118
|
+
if (pageActivityEndEvent.hadActivity && pageActivityEndEvent.end < click.startClocks.timeStamp) {
|
|
119
|
+
// If the clock is looking weird, just discard the click
|
|
120
|
+
click.discard();
|
|
121
|
+
} else {
|
|
122
|
+
if (pageActivityEndEvent.hadActivity) {
|
|
123
|
+
click.stop(pageActivityEndEvent.end);
|
|
124
|
+
} else if (hadActivityOnPointerDown()) {
|
|
125
|
+
click.stop( // using the click start as activity end, so the click will have some activity but its
|
|
126
|
+
// duration will be 0 (as the activity started before the click start)
|
|
127
|
+
click.startClocks.timeStamp);
|
|
97
128
|
} else {
|
|
98
|
-
click.stop(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
129
|
+
click.stop();
|
|
130
|
+
} // Validate or discard the click only if we don't track frustrations. It'll be done when
|
|
131
|
+
// the click chain is finalized.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
if (!configuration.trackFrustrations) {
|
|
135
|
+
if (!pageActivityEndEvent.hadActivity) {
|
|
136
|
+
// If we are not tracking frustrations, we should discard the click to keep backward
|
|
137
|
+
// compatibility.
|
|
138
|
+
click.discard();
|
|
139
|
+
} else {
|
|
140
|
+
click.validate();
|
|
109
141
|
}
|
|
110
142
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
var viewEndedSubscription = lifeCycle.subscribe(_browserCore.LifeCycleEventType.VIEW_ENDED, function (data) {
|
|
114
|
-
click.stop(data.endClocks.timeStamp);
|
|
115
|
-
});
|
|
116
|
-
var stopSubscription = stopObservable.subscribe(function () {
|
|
117
|
-
click.stop();
|
|
118
|
-
});
|
|
119
|
-
click.stopObservable.subscribe(function () {
|
|
120
|
-
viewEndedSubscription.unsubscribe();
|
|
121
|
-
|
|
122
|
-
_waitPageActivityEnd.stop();
|
|
143
|
+
}
|
|
144
|
+
}, CLICK_ACTION_MAX_DURATION);
|
|
123
145
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
var stopWaitPageActivityEnd = _waitPageActivityEnd.stop;
|
|
147
|
+
var viewEndedSubscription = lifeCycle.subscribe(_browserCore.LifeCycleEventType.VIEW_ENDED, function (data) {
|
|
148
|
+
click.stop(data.endClocks.timeStamp);
|
|
149
|
+
});
|
|
150
|
+
var stopSubscription = stopObservable.subscribe(function () {
|
|
151
|
+
click.stop();
|
|
152
|
+
});
|
|
153
|
+
click.stopObservable.subscribe(function () {
|
|
154
|
+
viewEndedSubscription.unsubscribe();
|
|
155
|
+
stopWaitPageActivityEnd();
|
|
156
|
+
stopSubscription.unsubscribe();
|
|
157
|
+
});
|
|
127
158
|
}
|
|
128
159
|
|
|
129
160
|
function computeClickActionBase(event, actionNameAttribute) {
|
|
@@ -145,7 +176,7 @@ function computeClickActionBase(event, actionNameAttribute) {
|
|
|
145
176
|
// }
|
|
146
177
|
|
|
147
178
|
return {
|
|
148
|
-
type:
|
|
179
|
+
type: _browserCore.ActionType.CLICK,
|
|
149
180
|
target: target,
|
|
150
181
|
position: position,
|
|
151
182
|
name: (0, _getActionNameFromElement.getActionNameFromElement)(event.target, actionNameAttribute)
|
|
@@ -154,18 +185,23 @@ function computeClickActionBase(event, actionNameAttribute) {
|
|
|
154
185
|
|
|
155
186
|
var ClickStatus = {
|
|
156
187
|
// Initial state, the click is still ongoing.
|
|
157
|
-
ONGOING:
|
|
188
|
+
ONGOING: 0,
|
|
158
189
|
// The click is no more ongoing but still needs to be validated or discarded.
|
|
159
|
-
STOPPED:
|
|
190
|
+
STOPPED: 1,
|
|
160
191
|
// Final state, the click has been stopped and validated or discarded.
|
|
161
|
-
FINALIZED:
|
|
192
|
+
FINALIZED: 2
|
|
162
193
|
};
|
|
163
194
|
|
|
164
|
-
function newClick(lifeCycle, history, getUserActivity, clickActionBase,
|
|
195
|
+
function newClick(lifeCycle, history, getUserActivity, clickActionBase, startEvent) {
|
|
165
196
|
var id = (0, _browserCore.UUID)();
|
|
166
197
|
var startClocks = (0, _browserCore.clocksNow)();
|
|
167
198
|
var historyEntry = history.add(id, startClocks.relative);
|
|
168
|
-
var eventCountsSubscription = (0, _trackEventCounts.trackEventCounts)(
|
|
199
|
+
var eventCountsSubscription = (0, _trackEventCounts.trackEventCounts)({
|
|
200
|
+
lifeCycle: lifeCycle,
|
|
201
|
+
isChildEvent: function isChildEvent(event) {
|
|
202
|
+
return event.action !== undefined && ((0, _browserCore.isArray)(event.action.id) ? (0, _browserCore.includes)(event.action.id, id) : event.action.id === id);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
169
205
|
var status = ClickStatus.ONGOING;
|
|
170
206
|
var activityEndTime;
|
|
171
207
|
var frustrationTypes = [];
|
|
@@ -190,21 +226,25 @@ function newClick(lifeCycle, history, getUserActivity, clickActionBase, clickEve
|
|
|
190
226
|
}
|
|
191
227
|
|
|
192
228
|
return {
|
|
193
|
-
event:
|
|
229
|
+
event: startEvent,
|
|
194
230
|
stop: stop,
|
|
195
|
-
startClocks: startClocks,
|
|
196
231
|
stopObservable: stopObservable,
|
|
197
|
-
hasError:
|
|
198
|
-
|
|
232
|
+
hasError: function hasError() {
|
|
233
|
+
return eventCountsSubscription.eventCounts.errorCount > 0;
|
|
234
|
+
},
|
|
235
|
+
hasPageActivity: function hasPageActivity() {
|
|
236
|
+
return activityEndTime !== undefined;
|
|
237
|
+
},
|
|
199
238
|
getUserActivity: getUserActivity,
|
|
200
239
|
addFrustration: function addFrustration(frustrationType) {
|
|
201
240
|
frustrationTypes.push(frustrationType);
|
|
202
241
|
},
|
|
242
|
+
startClocks: startClocks,
|
|
203
243
|
isStopped: function isStopped() {
|
|
204
244
|
return status === ClickStatus.STOPPED || status === ClickStatus.FINALIZED;
|
|
205
245
|
},
|
|
206
246
|
clone: function clone() {
|
|
207
|
-
return newClick(lifeCycle, history, getUserActivity, clickActionBase,
|
|
247
|
+
return newClick(lifeCycle, history, getUserActivity, clickActionBase, startEvent);
|
|
208
248
|
},
|
|
209
249
|
validate: function validate(domEvents) {
|
|
210
250
|
stop();
|
|
@@ -228,8 +268,8 @@ function newClick(lifeCycle, history, getUserActivity, clickActionBase, clickEve
|
|
|
228
268
|
errorCount: errorCount,
|
|
229
269
|
longTaskCount: longTaskCount
|
|
230
270
|
},
|
|
231
|
-
events: (0, _browserCore.isNullUndefinedDefaultValue)(domEvents, [
|
|
232
|
-
event:
|
|
271
|
+
events: (0, _browserCore.isNullUndefinedDefaultValue)(domEvents, [startEvent]),
|
|
272
|
+
event: startEvent
|
|
233
273
|
}, clickActionBase);
|
|
234
274
|
lifeCycle.notify(_browserCore.LifeCycleEventType.AUTO_ACTION_COMPLETED, clickAction);
|
|
235
275
|
status = ClickStatus.FINALIZED;
|
|
@@ -12,7 +12,7 @@ var _trackConsoleError = require("./trackConsoleError");
|
|
|
12
12
|
|
|
13
13
|
var _trackReportError = require("./trackReportError");
|
|
14
14
|
|
|
15
|
-
function startErrorCollection(lifeCycle) {
|
|
15
|
+
function startErrorCollection(lifeCycle, foregroundContexts) {
|
|
16
16
|
var errorObservable = new _browserCore.Observable();
|
|
17
17
|
(0, _trackConsoleError.trackConsoleError)(errorObservable);
|
|
18
18
|
(0, _browserCore.trackRuntimeError)(errorObservable);
|
|
@@ -22,15 +22,15 @@ function startErrorCollection(lifeCycle) {
|
|
|
22
22
|
error: error
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
-
return doStartErrorCollection(lifeCycle);
|
|
25
|
+
return doStartErrorCollection(lifeCycle, foregroundContexts);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function doStartErrorCollection(lifeCycle) {
|
|
28
|
+
function doStartErrorCollection(lifeCycle, foregroundContexts) {
|
|
29
29
|
lifeCycle.subscribe(_browserCore.LifeCycleEventType.RAW_ERROR_COLLECTED, function (error) {
|
|
30
30
|
lifeCycle.notify(_browserCore.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, (0, _browserCore.assign)({
|
|
31
31
|
customerContext: error.customerContext,
|
|
32
32
|
savedCommonContext: error.savedCommonContext
|
|
33
|
-
}, processError(error.error)));
|
|
33
|
+
}, processError(error.error, foregroundContexts)));
|
|
34
34
|
});
|
|
35
35
|
return {
|
|
36
36
|
addError: function addError(providedError, savedCommonContext) {
|
|
@@ -54,7 +54,7 @@ function doStartErrorCollection(lifeCycle) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function processError(error) {
|
|
57
|
+
function processError(error, foregroundContexts) {
|
|
58
58
|
var rawRumEvent = {
|
|
59
59
|
date: error.startClocks.timeStamp,
|
|
60
60
|
error: {
|
|
@@ -70,6 +70,14 @@ function processError(error) {
|
|
|
70
70
|
},
|
|
71
71
|
type: _browserCore.RumEventType.ERROR
|
|
72
72
|
};
|
|
73
|
+
var inForeground = foregroundContexts.isInForegroundAt(error.startClocks.relative);
|
|
74
|
+
|
|
75
|
+
if (inForeground) {
|
|
76
|
+
rawRumEvent.view = {
|
|
77
|
+
in_foreground: inForeground
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
return {
|
|
74
82
|
rawRumEvent: rawRumEvent,
|
|
75
83
|
startTime: error.startClocks.relative,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = void 0;
|
|
7
|
+
exports.trackViewEventCounts = trackViewEventCounts;
|
|
8
|
+
|
|
9
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
10
|
+
|
|
11
|
+
var _trackEventCounts2 = require("../../trackEventCounts");
|
|
12
|
+
|
|
13
|
+
// Some events are not being counted as they transcend views. To reduce the occurrence;
|
|
14
|
+
// an arbitrary delay is added for stopping event counting after the view ends.
|
|
15
|
+
//
|
|
16
|
+
// Ideally, we would not stop and keep counting events until the end of the session.
|
|
17
|
+
// But this might have a small performance impact if there are many many views:
|
|
18
|
+
// we would need to go through each event to see if the related view matches.
|
|
19
|
+
// So let's have a fairly short delay to avoid impacting performances too much.
|
|
20
|
+
//
|
|
21
|
+
// In the future, we could have views stored in a data structure similar to ContextHistory. Whenever
|
|
22
|
+
// a child event is collected, we could look into this history to find the matching view and
|
|
23
|
+
// increase the associated and increase its counter. Having a centralized data structure for it
|
|
24
|
+
// would allow us to look for views more efficiently.
|
|
25
|
+
//
|
|
26
|
+
// For now, having a small cleanup delay will already improve the situation in most cases.
|
|
27
|
+
var KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = 5 * _browserCore.ONE_MINUTE;
|
|
28
|
+
exports.KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY;
|
|
29
|
+
|
|
30
|
+
function trackViewEventCounts(lifeCycle, viewId, onChange) {
|
|
31
|
+
var _trackEventCounts = (0, _trackEventCounts2.trackEventCounts)({
|
|
32
|
+
lifeCycle: lifeCycle,
|
|
33
|
+
isChildEvent: function isChildEvent(event) {
|
|
34
|
+
return event.view.id === viewId;
|
|
35
|
+
},
|
|
36
|
+
onChange: onChange
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
scheduleStop: function scheduleStop() {
|
|
41
|
+
setTimeout(_trackEventCounts.stop, KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY);
|
|
42
|
+
},
|
|
43
|
+
eventCounts: _trackEventCounts.eventCounts
|
|
44
|
+
};
|
|
45
|
+
}
|