@cloudcare/browser-rum 2.1.5 → 2.2.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/README.md +1 -2
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/rum.js +57 -48
- package/cjs/boot/rumPublicApi.js +169 -134
- package/cjs/domain/assembly.js +58 -44
- package/cjs/domain/configuration.js +67 -0
- package/cjs/domain/contexts/internalContext.js +45 -0
- package/cjs/domain/contexts/urlContexts.js +68 -0
- package/cjs/domain/contexts/viewContexts.js +43 -0
- package/cjs/domain/domMutationCollection.js +44 -31
- package/cjs/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +25 -25
- package/cjs/domain/performanceCollection.js +55 -24
- package/cjs/domain/requestCollection.js +117 -0
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +22 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +82 -0
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +78 -0
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +163 -0
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +74 -0
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +263 -0
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +33 -53
- package/cjs/domain/rumEventsCollection/error/trackConsoleError.js +26 -0
- package/cjs/domain/rumEventsCollection/error/trackReportError.js +26 -0
- package/cjs/domain/rumEventsCollection/longTask/longTaskCollection.js +46 -17
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +49 -9
- package/cjs/domain/rumEventsCollection/view/trackFirstHidden.js +7 -5
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +61 -24
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +91 -51
- package/cjs/domain/rumEventsCollection/view/trackViews.js +119 -86
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +41 -31
- package/cjs/domain/rumSessionManager.js +95 -0
- package/cjs/domain/tracing/tracer.js +9 -10
- package/cjs/domain/trackEventCounts.js +9 -6
- package/cjs/domain/usr/index.js +30 -0
- package/cjs/domain/waitPageActivityEnd.js +163 -0
- package/cjs/transport/startRumBatch.js +38 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.js +55 -48
- package/esm/boot/rumPublicApi.js +167 -135
- package/esm/domain/assembly.js +58 -44
- package/esm/domain/configuration.js +53 -0
- package/esm/domain/contexts/internalContext.js +38 -0
- package/esm/domain/contexts/urlContexts.js +58 -0
- package/esm/domain/contexts/viewContexts.js +32 -0
- package/esm/domain/domMutationCollection.js +43 -33
- package/esm/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +26 -24
- package/esm/domain/performanceCollection.js +56 -26
- package/esm/domain/requestCollection.js +102 -0
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +23 -5
- package/esm/domain/rumEventsCollection/actions/clickChain.js +69 -0
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +64 -0
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +60 -47
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +139 -0
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +66 -0
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +244 -0
- package/esm/domain/rumEventsCollection/error/errorCollection.js +32 -54
- package/esm/domain/rumEventsCollection/error/trackConsoleError.js +18 -0
- package/esm/domain/rumEventsCollection/error/trackReportError.js +18 -0
- package/esm/domain/rumEventsCollection/longTask/longTaskCollection.js +30 -18
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +31 -9
- package/esm/domain/rumEventsCollection/view/trackFirstHidden.js +8 -6
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +43 -26
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +75 -51
- package/esm/domain/rumEventsCollection/view/trackViews.js +120 -85
- package/esm/domain/rumEventsCollection/view/viewCollection.js +42 -32
- package/esm/domain/rumSessionManager.js +80 -0
- package/esm/domain/tracing/skywalkingTracer.js +1 -1
- package/esm/domain/tracing/tracer.js +8 -9
- package/esm/domain/trackEventCounts.js +9 -6
- package/esm/domain/usr/index.js +17 -0
- package/esm/domain/waitPageActivityEnd.js +147 -0
- package/esm/transport/startRumBatch.js +30 -0
- package/package.json +3 -3
- package/src/boot/rum.js +79 -59
- package/src/boot/rumPublicApi.js +165 -171
- package/src/domain/.DS_Store +0 -0
- package/src/domain/assembly.js +77 -54
- package/src/domain/configuration.js +69 -0
- package/src/domain/contexts/internalContext.js +39 -0
- package/src/domain/contexts/urlContexts.js +76 -0
- package/src/domain/contexts/viewContexts.js +37 -0
- package/src/domain/domMutationCollection.js +48 -32
- package/src/domain/{rumEventsCollection/view/trackLocationChanges.js → locationChangeObservable.js} +28 -28
- package/src/domain/performanceCollection.js +62 -45
- package/src/domain/requestCollection.js +103 -0
- package/src/domain/rumEventsCollection/actions/actionCollection.js +34 -11
- package/src/domain/rumEventsCollection/actions/clickChain.js +90 -0
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +84 -0
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +73 -62
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +157 -0
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +85 -0
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +326 -0
- package/src/domain/rumEventsCollection/error/errorCollection.js +53 -69
- package/src/domain/rumEventsCollection/error/trackConsoleError.js +21 -0
- package/src/domain/rumEventsCollection/error/trackReportError.js +22 -0
- package/src/domain/rumEventsCollection/longTask/longTaskCollection.js +29 -18
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +39 -23
- package/src/domain/rumEventsCollection/view/trackFirstHidden.js +9 -6
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +63 -42
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +80 -61
- package/src/domain/rumEventsCollection/view/trackViews.js +171 -134
- package/src/domain/rumEventsCollection/view/viewCollection.js +69 -49
- package/src/domain/rumSessionManager.js +90 -0
- package/src/domain/tracing/jaegerTracer.js +5 -5
- package/src/domain/tracing/skywalkingTracer.js +3 -3
- package/src/domain/tracing/tracer.js +50 -38
- package/src/domain/tracing/w3cTraceParentTracer.js +5 -5
- package/src/domain/tracing/zipkinMultiTracer.js +5 -5
- package/src/domain/tracing/zipkinSingleTracer.js +5 -5
- package/src/domain/trackEventCounts.js +10 -6
- package/src/domain/usr/index.js +16 -0
- package/src/domain/waitPageActivityEnd.js +192 -0
- package/src/transport/startRumBatch.js +48 -0
- package/cjs/domain/internalContext.js +0 -34
- package/cjs/domain/parentContexts.js +0 -143
- package/cjs/domain/requestCollections.js +0 -131
- package/cjs/domain/rumEventsCollection/actions/trackActions.js +0 -114
- package/cjs/domain/rumSession.js +0 -82
- package/cjs/domain/trackPageActivities.js +0 -166
- package/cjs/transport/batch.js +0 -81
- package/esm/domain/internalContext.js +0 -27
- package/esm/domain/parentContexts.js +0 -130
- package/esm/domain/requestCollections.js +0 -118
- package/esm/domain/rumEventsCollection/actions/trackActions.js +0 -103
- package/esm/domain/rumSession.js +0 -70
- package/esm/domain/trackPageActivities.js +0 -149
- package/esm/transport/batch.js +0 -74
- package/src/domain/internalContext.js +0 -28
- package/src/domain/parentContexts.js +0 -171
- package/src/domain/requestCollections.js +0 -118
- package/src/domain/rumEventsCollection/actions/trackActions.js +0 -113
- package/src/domain/rumSession.js +0 -92
- package/src/domain/trackPageActivities.js +0 -170
- package/src/transport/batch.js +0 -85
|
@@ -13,35 +13,31 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
13
13
|
|
|
14
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
var DEFAULT_PROGRAMMATIC_ATTRIBUTE = 'data-guance-action-name';
|
|
17
|
+
|
|
18
|
+
function getActionNameFromElement(element, userProgrammaticAttribute) {
|
|
17
19
|
// Proceed to get the action name in two steps:
|
|
18
20
|
// * first, get the name programmatically, explicitly defined by the user.
|
|
19
21
|
// * then, use strategies that are known to return good results. Those strategies will be used on
|
|
20
22
|
// the element and a few parents, but it's likely that they won't succeed at all.
|
|
21
23
|
// * if no name is found this way, use strategies returning less accurate names as a fallback.
|
|
22
24
|
// Those are much likely to succeed.
|
|
23
|
-
return getActionNameFromElementProgrammatically(element) || getActionNameFromElementForStrategies(element, priorityStrategies) || getActionNameFromElementForStrategies(element, fallbackStrategies) || '';
|
|
25
|
+
return getActionNameFromElementProgrammatically(element, DEFAULT_PROGRAMMATIC_ATTRIBUTE) || userProgrammaticAttribute && getActionNameFromElementProgrammatically(element, userProgrammaticAttribute) || getActionNameFromElementForStrategies(element, userProgrammaticAttribute, priorityStrategies) || getActionNameFromElementForStrategies(element, userProgrammaticAttribute, fallbackStrategies) || '';
|
|
24
26
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Get the action name from the attribute 'data-dd-action-name' on the element or any of its parent.
|
|
27
|
-
*/
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
var PROGRAMMATIC_ATTRIBUTE = 'data-df-action-name';
|
|
31
|
-
|
|
32
|
-
function getActionNameFromElementProgrammatically(targetElement) {
|
|
28
|
+
function getActionNameFromElementProgrammatically(targetElement, programmaticAttribute) {
|
|
33
29
|
var elementWithAttribute; // We don't use getActionNameFromElementForStrategies here, because we want to consider all parents,
|
|
34
30
|
// without limit. It is up to the user to declare a relevant naming strategy.
|
|
35
31
|
// If available, use element.closest() to match get the attribute from the element or any of its
|
|
36
32
|
// parent. Else fallback to a more traditional implementation.
|
|
37
33
|
|
|
38
34
|
if (supportsElementClosest()) {
|
|
39
|
-
elementWithAttribute = targetElement.closest('[' +
|
|
35
|
+
elementWithAttribute = targetElement.closest('[' + programmaticAttribute + ']');
|
|
40
36
|
} else {
|
|
41
37
|
var element = targetElement;
|
|
42
38
|
|
|
43
39
|
while (element) {
|
|
44
|
-
if (element.hasAttribute(
|
|
40
|
+
if (element.hasAttribute(programmaticAttribute)) {
|
|
45
41
|
elementWithAttribute = element;
|
|
46
42
|
break;
|
|
47
43
|
}
|
|
@@ -54,21 +50,23 @@ function getActionNameFromElementProgrammatically(targetElement) {
|
|
|
54
50
|
return;
|
|
55
51
|
}
|
|
56
52
|
|
|
57
|
-
var name = elementWithAttribute.getAttribute(
|
|
53
|
+
var name = elementWithAttribute.getAttribute(programmaticAttribute);
|
|
58
54
|
return truncate(normalizeWhitespace(name.trim()));
|
|
59
55
|
}
|
|
60
56
|
|
|
61
57
|
var priorityStrategies = [// associated LABEL text
|
|
62
|
-
function (element) {
|
|
58
|
+
function (element, userProgrammaticAttribute) {
|
|
63
59
|
// IE does not support element.labels, so we fallback to a CSS selector based on the element id
|
|
64
60
|
// instead
|
|
65
61
|
if (supportsLabelProperty()) {
|
|
66
62
|
if ('labels' in element && element.labels && element.labels.length > 0) {
|
|
67
|
-
return getTextualContent(element.labels[0]);
|
|
63
|
+
return getTextualContent(element.labels[0], userProgrammaticAttribute);
|
|
68
64
|
}
|
|
69
65
|
} else if (element.id) {
|
|
70
|
-
var label = element.ownerDocument && element.ownerDocument.
|
|
71
|
-
|
|
66
|
+
var label = element.ownerDocument && (0, _browserCore.find)(element.ownerDocument.querySelectorAll('label'), function (label) {
|
|
67
|
+
return label.htmlFor === element.id;
|
|
68
|
+
});
|
|
69
|
+
return label && getTextualContent(label, userProgrammaticAttribute);
|
|
72
70
|
}
|
|
73
71
|
}, // INPUT button (and associated) value
|
|
74
72
|
function (element) {
|
|
@@ -81,14 +79,14 @@ function (element) {
|
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
}, // BUTTON, LABEL or button-like element text
|
|
84
|
-
function (element) {
|
|
82
|
+
function (element, userProgrammaticAttribute) {
|
|
85
83
|
if (element.nodeName === 'BUTTON' || element.nodeName === 'LABEL' || element.getAttribute('role') === 'button') {
|
|
86
|
-
return getTextualContent(element);
|
|
84
|
+
return getTextualContent(element, userProgrammaticAttribute);
|
|
87
85
|
}
|
|
88
86
|
}, function (element) {
|
|
89
87
|
return element.getAttribute('aria-label');
|
|
90
88
|
}, // associated element text designated by the aria-labelledby attribute
|
|
91
|
-
function (element) {
|
|
89
|
+
function (element, userProgrammaticAttribute) {
|
|
92
90
|
var labelledByAttribute = element.getAttribute('aria-labelledby');
|
|
93
91
|
|
|
94
92
|
if (labelledByAttribute) {
|
|
@@ -118,8 +116,8 @@ function (element) {
|
|
|
118
116
|
return getTextualContent(element.options[0]);
|
|
119
117
|
}
|
|
120
118
|
}];
|
|
121
|
-
var fallbackStrategies = [function (element) {
|
|
122
|
-
return getTextualContent(element);
|
|
119
|
+
var fallbackStrategies = [function (element, userProgrammaticAttribute) {
|
|
120
|
+
return getTextualContent(element, userProgrammaticAttribute);
|
|
123
121
|
}];
|
|
124
122
|
/**
|
|
125
123
|
* Iterates over the target element and its parent, using the strategies list to get an action name.
|
|
@@ -128,7 +126,7 @@ var fallbackStrategies = [function (element) {
|
|
|
128
126
|
|
|
129
127
|
var MAX_PARENTS_TO_CONSIDER = 10;
|
|
130
128
|
|
|
131
|
-
function getActionNameFromElementForStrategies(targetElement, strategies) {
|
|
129
|
+
function getActionNameFromElementForStrategies(targetElement, userProgrammaticAttribute, strategies) {
|
|
132
130
|
var element = targetElement;
|
|
133
131
|
var recursionCounter = 0;
|
|
134
132
|
|
|
@@ -139,7 +137,7 @@ function getActionNameFromElementForStrategies(targetElement, strategies) {
|
|
|
139
137
|
try {
|
|
140
138
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
141
139
|
var strategy = _step.value;
|
|
142
|
-
var name = strategy(element);
|
|
140
|
+
var name = strategy(element, userProgrammaticAttribute);
|
|
143
141
|
|
|
144
142
|
if (typeof name === 'string') {
|
|
145
143
|
var trimmedName = name.trim();
|
|
@@ -180,7 +178,7 @@ function getElementById(refElement, id) {
|
|
|
180
178
|
return refElement.ownerDocument ? refElement.ownerDocument.getElementById(id) : null;
|
|
181
179
|
}
|
|
182
180
|
|
|
183
|
-
function getTextualContent(element) {
|
|
181
|
+
function getTextualContent(element, userProgrammaticAttribute) {
|
|
184
182
|
if (element.isContentEditable) {
|
|
185
183
|
return;
|
|
186
184
|
}
|
|
@@ -188,18 +186,33 @@ function getTextualContent(element) {
|
|
|
188
186
|
if ('innerText' in element) {
|
|
189
187
|
var text = element.innerText;
|
|
190
188
|
|
|
189
|
+
var removeTextFromElements = function removeTextFromElements(query) {
|
|
190
|
+
var list = element.querySelectorAll(query);
|
|
191
|
+
|
|
192
|
+
for (var index = 0; index < list.length; index += 1) {
|
|
193
|
+
var _element = list[index];
|
|
194
|
+
|
|
195
|
+
if ('innerText' in _element) {
|
|
196
|
+
var textToReplace = _element.innerText;
|
|
197
|
+
|
|
198
|
+
if (textToReplace && textToReplace.trim().length > 0) {
|
|
199
|
+
text = text.replace(textToReplace, '');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
191
205
|
if (!supportsInnerTextScriptAndStyleRemoval()) {
|
|
192
206
|
// remove the inner text of SCRIPT and STYLES from the result. This is a bit dirty, but should
|
|
193
207
|
// be relatively fast and work in most cases.
|
|
194
|
-
|
|
208
|
+
removeTextFromElements('script, style');
|
|
209
|
+
} // remove the text of elements with programmatic attribute value
|
|
195
210
|
|
|
196
|
-
for (var i = 0; i < elementsTextToRemove.length; i += 1) {
|
|
197
|
-
var innerText = elementsTextToRemove[i].innerText;
|
|
198
211
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
212
|
+
removeTextFromElements('[' + DEFAULT_PROGRAMMATIC_ATTRIBUTE + ']');
|
|
213
|
+
|
|
214
|
+
if (userProgrammaticAttribute) {
|
|
215
|
+
removeTextFromElements('[' + userProgrammaticAttribute + ']');
|
|
203
216
|
}
|
|
204
217
|
|
|
205
218
|
return text;
|
|
@@ -208,26 +221,26 @@ function getTextualContent(element) {
|
|
|
208
221
|
return element.textContent;
|
|
209
222
|
}
|
|
210
223
|
/**
|
|
211
|
-
* Returns true if element.innerText excludes the text from inline SCRIPT and STYLE element.
|
|
212
|
-
* should be the case everywhere except on
|
|
213
|
-
*
|
|
224
|
+
* Returns true if element.innerText excludes the text from inline SCRIPT and STYLE element. This
|
|
225
|
+
* should be the case everywhere except on Internet Explorer 10 and 11 (see [1])
|
|
226
|
+
*
|
|
227
|
+
* The innerText property relies on what is actually rendered to compute its output, so to check if
|
|
228
|
+
* it actually excludes SCRIPT and STYLE content, a solution would be to create a style element, set
|
|
229
|
+
* its content to '*', inject it in the document body, and check if the style element innerText
|
|
230
|
+
* property returns '*'. Using a new `document` instance won't work as it is not rendered.
|
|
231
|
+
*
|
|
232
|
+
* This solution requires specific CSP rules (see [2]) to be set by the customer. We want to avoid
|
|
233
|
+
* this, so instead we rely on browser detection. In case of false negative, the impact should be
|
|
234
|
+
* low, since we rely on this result to remove the SCRIPT and STYLE innerText (which will be empty)
|
|
235
|
+
* from a parent element innerText.
|
|
236
|
+
*
|
|
237
|
+
* [1]: https://web.archive.org/web/20210602165716/http://perfectionkills.com/the-poor-misunderstood-innerText/#diff-with-textContent
|
|
238
|
+
* [2]: https://github.com/DataDog/browser-sdk/issues/1084
|
|
214
239
|
*/
|
|
215
240
|
|
|
216
241
|
|
|
217
|
-
var supportsInnerTextScriptAndStyleRemovalResult;
|
|
218
|
-
|
|
219
242
|
function supportsInnerTextScriptAndStyleRemoval() {
|
|
220
|
-
|
|
221
|
-
var style = document.createElement('style');
|
|
222
|
-
style.textContent = '*';
|
|
223
|
-
var div = document.createElement('div');
|
|
224
|
-
div.appendChild(style);
|
|
225
|
-
document.body.appendChild(div);
|
|
226
|
-
supportsInnerTextScriptAndStyleRemovalResult = div.innerText === '';
|
|
227
|
-
document.body.removeChild(div);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return supportsInnerTextScriptAndStyleRemovalResult;
|
|
243
|
+
return !(0, _browserCore.isIE)();
|
|
231
244
|
}
|
|
232
245
|
/**
|
|
233
246
|
* Returns true if the browser supports the element.labels property. This should be the case
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSelectorsFromElement = getSelectorsFromElement;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
9
|
+
|
|
10
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
11
|
+
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Stable attributes are attributes that are commonly used to identify parts of a UI (ex:
|
|
18
|
+
* component). Those attribute values should not be generated randomly (hardcoded most of the time)
|
|
19
|
+
* and stay the same across deploys. They are not necessarily unique across the document.
|
|
20
|
+
*/
|
|
21
|
+
var STABLE_ATTRIBUTES = ['data-guance-action-name', // Common test attributes (list provided by google recorder)
|
|
22
|
+
'data-testid', 'data-test', 'data-qa', 'data-cy', 'data-test-id', 'data-qa-id', 'data-testing', // FullStory decorator attributes:
|
|
23
|
+
'data-component', 'data-element', 'data-source-file'];
|
|
24
|
+
|
|
25
|
+
function getSelectorsFromElement(element, actionNameAttribute) {
|
|
26
|
+
var attributeSelectors = getStableAttributeSelectors();
|
|
27
|
+
|
|
28
|
+
if (actionNameAttribute) {
|
|
29
|
+
attributeSelectors = [function (element) {
|
|
30
|
+
return getAttributeSelector(actionNameAttribute, element);
|
|
31
|
+
}].concat(attributeSelectors);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
selector: getSelectorFromElement(element, [getIDSelector], [getClassSelector]),
|
|
36
|
+
selector_with_stable_attributes: getSelectorFromElement(element, attributeSelectors.concat(getIDSelector), attributeSelectors.concat(getClassSelector)),
|
|
37
|
+
selector_without_classes: getSelectorFromElement(element, attributeSelectors.concat(getIDSelector), attributeSelectors)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getSelectorFromElement(targetElement, globallyUniqueSelectorStrategies, uniqueAmongChildrenSelectorStrategies) {
|
|
42
|
+
var targetElementSelector = [];
|
|
43
|
+
var element = targetElement;
|
|
44
|
+
|
|
45
|
+
while (element && element.nodeName !== 'HTML') {
|
|
46
|
+
var globallyUniqueSelector = findSelector(element, globallyUniqueSelectorStrategies, isSelectorUniqueGlobally);
|
|
47
|
+
|
|
48
|
+
if (globallyUniqueSelector) {
|
|
49
|
+
targetElementSelector.unshift(globallyUniqueSelector);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var uniqueSelectorAmongChildren = findSelector(element, uniqueAmongChildrenSelectorStrategies, isSelectorUniqueAmongChildren);
|
|
54
|
+
|
|
55
|
+
if (uniqueSelectorAmongChildren) {
|
|
56
|
+
targetElementSelector.unshift(uniqueSelectorAmongChildren);
|
|
57
|
+
} else {
|
|
58
|
+
targetElementSelector.unshift(getPositionSelector(element));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
element = element.parentElement;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return targetElementSelector.join('>');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getIDSelector(element) {
|
|
68
|
+
if (element.id) {
|
|
69
|
+
return '#' + (0, _browserCore.cssEscape)(element.id);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getClassSelector(element) {
|
|
74
|
+
if (element.classList.length > 0) {
|
|
75
|
+
var orderedClassList = (0, _browserCore.arrayFrom)(element.classList).sort();
|
|
76
|
+
return element.tagName + (0, _browserCore.map)(orderedClassList, function (className) {
|
|
77
|
+
return '.' + (0, _browserCore.cssEscape)(className);
|
|
78
|
+
}).join('');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var stableAttributeSelectorsCache;
|
|
83
|
+
|
|
84
|
+
function getStableAttributeSelectors() {
|
|
85
|
+
if (!stableAttributeSelectorsCache) {
|
|
86
|
+
stableAttributeSelectorsCache = (0, _browserCore.map)(STABLE_ATTRIBUTES, function (attribute) {
|
|
87
|
+
return function (element) {
|
|
88
|
+
return getAttributeSelector(attribute, element);
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return stableAttributeSelectorsCache;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getAttributeSelector(attributeName, element) {
|
|
97
|
+
if (element.hasAttribute(attributeName)) {
|
|
98
|
+
return element.tagName + '[' + attributeName + '="' + (0, _browserCore.cssEscape)(element.getAttribute(attributeName)) + '"]';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getPositionSelector(element) {
|
|
103
|
+
var parent = element.parentElement;
|
|
104
|
+
var sibling = parent.firstElementChild;
|
|
105
|
+
var currentIndex = 0;
|
|
106
|
+
var elementIndex;
|
|
107
|
+
|
|
108
|
+
while (sibling) {
|
|
109
|
+
if (sibling.tagName === element.tagName) {
|
|
110
|
+
currentIndex += 1;
|
|
111
|
+
|
|
112
|
+
if (sibling === element) {
|
|
113
|
+
elementIndex = currentIndex;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (elementIndex !== undefined && currentIndex > 1) {
|
|
117
|
+
// Performance improvement: avoid iterating over all children, stop as soon as we are sure
|
|
118
|
+
// the element is not alone
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
sibling = sibling.nextElementSibling;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return currentIndex === 1 ? element.tagName : element.tagName + ':nth-of-type(' + elementIndex + ')';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function findSelector(element, selectorGetters, predicate) {
|
|
130
|
+
var _iterator = _createForOfIteratorHelper(selectorGetters),
|
|
131
|
+
_step;
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
135
|
+
var selectorGetter = _step.value;
|
|
136
|
+
var selector = selectorGetter(element);
|
|
137
|
+
|
|
138
|
+
if (selector && predicate(element, selector)) {
|
|
139
|
+
return selector;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
_iterator.e(err);
|
|
144
|
+
} finally {
|
|
145
|
+
_iterator.f();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isSelectorUniqueGlobally(element, selector) {
|
|
150
|
+
return element.ownerDocument.body.querySelectorAll(selector).length === 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function isSelectorUniqueAmongChildren(element, selector) {
|
|
154
|
+
for (var i = 0; i < element.parentElement.children.length; i++) {
|
|
155
|
+
var sibling = element.parentElement.children[i];
|
|
156
|
+
|
|
157
|
+
if (sibling !== element && (0, _browserCore.elementMatches)(sibling, selector)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.listenActionEvents = listenActionEvents;
|
|
7
|
+
|
|
8
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
9
|
+
|
|
10
|
+
function listenActionEvents(events) {
|
|
11
|
+
var onClick = events.onClick;
|
|
12
|
+
var onPointerDown = events.onPointerDown;
|
|
13
|
+
var hasSelectionChanged = false;
|
|
14
|
+
var selectionEmptyAtPointerDown;
|
|
15
|
+
var hasInputChanged = false;
|
|
16
|
+
var clickContext;
|
|
17
|
+
var listeners = [(0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.POINTER_DOWN, function (event) {
|
|
18
|
+
hasSelectionChanged = false;
|
|
19
|
+
selectionEmptyAtPointerDown = isSelectionEmpty();
|
|
20
|
+
|
|
21
|
+
if (isMouseEventOnElement(event)) {
|
|
22
|
+
clickContext = onPointerDown(event);
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
capture: true
|
|
26
|
+
}), (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.SELECTION_CHANGE, function () {
|
|
27
|
+
if (!selectionEmptyAtPointerDown || !isSelectionEmpty()) {
|
|
28
|
+
hasSelectionChanged = true;
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
capture: true
|
|
32
|
+
}), (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.CLICK, function (clickEvent) {
|
|
33
|
+
if (isMouseEventOnElement(clickEvent) && clickContext) {
|
|
34
|
+
// Use a scoped variable to make sure the value is not changed by other clicks
|
|
35
|
+
var userActivity = {
|
|
36
|
+
selection: hasSelectionChanged,
|
|
37
|
+
input: hasInputChanged
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (!hasInputChanged) {
|
|
41
|
+
setTimeout(function () {
|
|
42
|
+
userActivity.input = hasInputChanged;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
onClick(clickContext, clickEvent, function () {
|
|
47
|
+
return userActivity;
|
|
48
|
+
});
|
|
49
|
+
clickContext = undefined;
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
capture: true
|
|
53
|
+
}), (0, _browserCore.addEventListener)(window, _browserCore.DOM_EVENT.INPUT, function () {
|
|
54
|
+
hasInputChanged = true;
|
|
55
|
+
}, {
|
|
56
|
+
capture: true
|
|
57
|
+
})];
|
|
58
|
+
return {
|
|
59
|
+
stop: function stop() {
|
|
60
|
+
(0, _browserCore.each)(listeners, function (listener) {
|
|
61
|
+
return listener.stop();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isSelectionEmpty() {
|
|
68
|
+
var selection = window.getSelection();
|
|
69
|
+
return !selection || selection.isCollapsed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isMouseEventOnElement(event) {
|
|
73
|
+
return event.target instanceof Element;
|
|
74
|
+
}
|