@cloudcare/browser-rum 3.3.9 → 3.3.10
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/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +16 -27
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +58 -38
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +13 -3
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/domain/deflate/deflateWorker.js +1 -1
- package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +17 -28
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +59 -38
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +14 -4
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/package.json +4 -4
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +28 -30
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +78 -37
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +20 -4
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { cssEscape } from '@cloudcare/browser-core'
|
|
1
|
+
import { cssEscape, isNodeShadowRoot } from '@cloudcare/browser-core'
|
|
2
2
|
import { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './getActionNameFromElement'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Internal marker used to represent a shadow root boundary. This is not a valid CSS selector and
|
|
6
|
+
* needs to be split before querying each successive shadow root.
|
|
7
|
+
*/
|
|
8
|
+
export var SHADOW_DOM_MARKER = '::shadow '
|
|
3
9
|
/**
|
|
4
10
|
* Stable attributes are attributes that are commonly used to identify parts of a UI (ex:
|
|
5
11
|
* component). Those attribute values should not be generated randomly (hardcoded most of the time)
|
|
@@ -43,13 +49,58 @@ export function getSelectorFromElement(targetElement, actionNameAttribute) {
|
|
|
43
49
|
// parents, and we cannot determine if it's unique in the document.
|
|
44
50
|
return
|
|
45
51
|
}
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
|
|
53
|
+
var subtrees = getAllSubtreeTargets(targetElement)
|
|
54
|
+
var selectorParts = []
|
|
55
|
+
for (var index = 0; index < subtrees.length; index += 1) {
|
|
56
|
+
var subtree = subtrees[index]
|
|
57
|
+
var selector = getSelectorFromElementWithinSubtree(
|
|
58
|
+
subtree.target,
|
|
59
|
+
subtree.rootNode,
|
|
60
|
+
actionNameAttribute
|
|
61
|
+
)
|
|
62
|
+
if (!selector) {
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
selectorParts.push(selector)
|
|
66
|
+
}
|
|
67
|
+
return selectorParts.join(SHADOW_DOM_MARKER)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Return each root and target pair from the document down to the target element.
|
|
72
|
+
*/
|
|
73
|
+
function getAllSubtreeTargets(element) {
|
|
74
|
+
var result = []
|
|
75
|
+
var currentTarget = element
|
|
76
|
+
while (currentTarget) {
|
|
77
|
+
var rootNode =
|
|
78
|
+
typeof currentTarget.getRootNode === 'function'
|
|
79
|
+
? currentTarget.getRootNode()
|
|
80
|
+
: currentTarget.ownerDocument
|
|
81
|
+
result.push({ rootNode: rootNode, target: currentTarget })
|
|
82
|
+
if (isNodeShadowRoot(rootNode)) {
|
|
83
|
+
currentTarget = rootNode.host
|
|
84
|
+
} else {
|
|
85
|
+
break
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return result.reverse()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getSelectorFromElementWithinSubtree(
|
|
92
|
+
targetElement,
|
|
93
|
+
rootNode,
|
|
94
|
+
actionNameAttribute
|
|
95
|
+
) {
|
|
96
|
+
var targetElementSelector
|
|
97
|
+
var currentElement = targetElement
|
|
48
98
|
while (currentElement && currentElement.nodeName !== 'HTML') {
|
|
49
99
|
const globallyUniqueSelector = findSelector(
|
|
50
100
|
currentElement,
|
|
101
|
+
rootNode,
|
|
51
102
|
GLOBALLY_UNIQUE_SELECTOR_GETTERS,
|
|
52
|
-
|
|
103
|
+
isSelectorUniqueWithinRoot,
|
|
53
104
|
actionNameAttribute,
|
|
54
105
|
targetElementSelector
|
|
55
106
|
)
|
|
@@ -58,6 +109,7 @@ export function getSelectorFromElement(targetElement, actionNameAttribute) {
|
|
|
58
109
|
}
|
|
59
110
|
const uniqueSelectorAmongChildren = findSelector(
|
|
60
111
|
currentElement,
|
|
112
|
+
rootNode,
|
|
61
113
|
UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS,
|
|
62
114
|
isSelectorUniqueAmongSiblings,
|
|
63
115
|
actionNameAttribute,
|
|
@@ -72,32 +124,6 @@ export function getSelectorFromElement(targetElement, actionNameAttribute) {
|
|
|
72
124
|
|
|
73
125
|
currentElement = currentElement.parentElement
|
|
74
126
|
}
|
|
75
|
-
// while (element && element.nodeName !== 'HTML') {
|
|
76
|
-
// var globallyUniqueSelector = findSelector(
|
|
77
|
-
// element,
|
|
78
|
-
// GLOBALLY_UNIQUE_SELECTOR_GETTERS,
|
|
79
|
-
// isSelectorUniqueGlobally,
|
|
80
|
-
// actionNameAttribute,
|
|
81
|
-
// targetElementSelector
|
|
82
|
-
// )
|
|
83
|
-
// if (globallyUniqueSelector) {
|
|
84
|
-
// return globallyUniqueSelector
|
|
85
|
-
// }
|
|
86
|
-
|
|
87
|
-
// var uniqueSelectorAmongChildren = findSelector(
|
|
88
|
-
// element,
|
|
89
|
-
// UNIQUE_AMONG_CHILDREN_SELECTOR_GETTERS,
|
|
90
|
-
// isSelectorUniqueAmongSiblings,
|
|
91
|
-
// actionNameAttribute,
|
|
92
|
-
// targetElementSelector
|
|
93
|
-
// )
|
|
94
|
-
// targetElementSelector =
|
|
95
|
-
// uniqueSelectorAmongChildren ||
|
|
96
|
-
// combineSelector(getPositionSelector(element), targetElementSelector)
|
|
97
|
-
|
|
98
|
-
// element = element.parentElement
|
|
99
|
-
// }
|
|
100
|
-
|
|
101
127
|
return targetElementSelector
|
|
102
128
|
}
|
|
103
129
|
function isGeneratedValue(value) {
|
|
@@ -166,7 +192,8 @@ function getStableAttributeSelector(element, actionNameAttribute) {
|
|
|
166
192
|
}
|
|
167
193
|
|
|
168
194
|
function getPositionSelector(element) {
|
|
169
|
-
var
|
|
195
|
+
var parentNode = element.parentNode
|
|
196
|
+
var sibling = parentNode && parentNode.firstElementChild
|
|
170
197
|
var elementIndex = 1
|
|
171
198
|
|
|
172
199
|
while (sibling && sibling !== element) {
|
|
@@ -184,6 +211,7 @@ function getPositionSelector(element) {
|
|
|
184
211
|
|
|
185
212
|
function findSelector(
|
|
186
213
|
element,
|
|
214
|
+
rootNode,
|
|
187
215
|
selectorGetters,
|
|
188
216
|
predicate,
|
|
189
217
|
actionNameAttribute,
|
|
@@ -195,15 +223,20 @@ function findSelector(
|
|
|
195
223
|
if (!elementSelector) {
|
|
196
224
|
continue
|
|
197
225
|
}
|
|
198
|
-
if (predicate(element, elementSelector, childSelector)) {
|
|
226
|
+
if (predicate(element, rootNode, elementSelector, childSelector)) {
|
|
199
227
|
return combineSelector(elementSelector, childSelector)
|
|
200
228
|
}
|
|
201
229
|
}
|
|
202
230
|
}
|
|
203
231
|
|
|
204
|
-
function
|
|
232
|
+
function isSelectorUniqueWithinRoot(
|
|
233
|
+
element,
|
|
234
|
+
rootNode,
|
|
235
|
+
elementSelector,
|
|
236
|
+
childSelector
|
|
237
|
+
) {
|
|
205
238
|
return (
|
|
206
|
-
|
|
239
|
+
rootNode.querySelectorAll(
|
|
207
240
|
combineSelector(elementSelector, childSelector)
|
|
208
241
|
).length === 1
|
|
209
242
|
)
|
|
@@ -220,6 +253,7 @@ function isSelectorUniqueGlobally(element, elementSelector, childSelector) {
|
|
|
220
253
|
*/
|
|
221
254
|
function isSelectorUniqueAmongSiblings(
|
|
222
255
|
currentElement,
|
|
256
|
+
rootNode,
|
|
223
257
|
currentElementSelector,
|
|
224
258
|
childSelector
|
|
225
259
|
) {
|
|
@@ -238,10 +272,17 @@ function isSelectorUniqueAmongSiblings(
|
|
|
238
272
|
sibling.querySelector(scopedSelector) !== null
|
|
239
273
|
}
|
|
240
274
|
|
|
241
|
-
|
|
242
|
-
|
|
275
|
+
let sibling = currentElement.previousElementSibling
|
|
276
|
+
while (sibling) {
|
|
277
|
+
if (isSiblingMatching(sibling)) {
|
|
278
|
+
return false
|
|
279
|
+
}
|
|
280
|
+
sibling = sibling.previousElementSibling
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
sibling = currentElement.nextElementSibling
|
|
243
284
|
while (sibling) {
|
|
244
|
-
if (
|
|
285
|
+
if (isSiblingMatching(sibling)) {
|
|
245
286
|
return false
|
|
246
287
|
}
|
|
247
288
|
sibling = sibling.nextElementSibling
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
ActionType,
|
|
16
16
|
isNullUndefinedDefaultValue,
|
|
17
17
|
isArray,
|
|
18
|
-
includes
|
|
18
|
+
includes,
|
|
19
|
+
isNodeShadowHost
|
|
19
20
|
} from '@cloudcare/browser-core'
|
|
20
21
|
import { trackEventCounts } from '../../trackEventCounts'
|
|
21
22
|
import {
|
|
@@ -213,8 +214,9 @@ function startClickAction(
|
|
|
213
214
|
}
|
|
214
215
|
|
|
215
216
|
function computeClickActionBase(event, actionNameAttribute) {
|
|
216
|
-
var
|
|
217
|
-
var
|
|
217
|
+
var target = getEventTarget(event)
|
|
218
|
+
var rect = target.getBoundingClientRect()
|
|
219
|
+
var selector = getSelectorFromElement(target, actionNameAttribute)
|
|
218
220
|
if (selector) {
|
|
219
221
|
updateInteractionSelector(event.timeStamp, selector)
|
|
220
222
|
}
|
|
@@ -229,10 +231,24 @@ function computeClickActionBase(event, actionNameAttribute) {
|
|
|
229
231
|
x: Math.round(event.clientX - rect.left),
|
|
230
232
|
y: Math.round(event.clientY - rect.top)
|
|
231
233
|
},
|
|
232
|
-
name: getActionNameFromElement(
|
|
234
|
+
name: getActionNameFromElement(target, actionNameAttribute)
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
|
|
238
|
+
function getEventTarget(event) {
|
|
239
|
+
if (
|
|
240
|
+
event.composed === true &&
|
|
241
|
+
isNodeShadowHost(event.target) &&
|
|
242
|
+
typeof event.composedPath === 'function'
|
|
243
|
+
) {
|
|
244
|
+
var composedPath = event.composedPath()
|
|
245
|
+
if (composedPath.length > 0 && composedPath[0] instanceof Element) {
|
|
246
|
+
return composedPath[0]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return event.target
|
|
250
|
+
}
|
|
251
|
+
|
|
236
252
|
var ClickStatus = {
|
|
237
253
|
// Initial state, the click is still ongoing.
|
|
238
254
|
ONGOING: 0,
|