@cloudcare/browser-rum 3.3.9 → 3.3.11
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 +26 -35
- 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 +15 -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 +27 -36
- 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 +16 -4
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/package.json +4 -4
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +62 -49
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +78 -37
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +27 -4
|
@@ -1,15 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
safeTruncate,
|
|
3
|
+
isIE,
|
|
4
|
+
find,
|
|
5
|
+
map,
|
|
6
|
+
filter,
|
|
7
|
+
getParentElement,
|
|
8
|
+
isNodeShadowRoot
|
|
9
|
+
} from '@cloudcare/browser-core'
|
|
2
10
|
|
|
3
11
|
export var DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE =
|
|
4
12
|
'data-guance-action-name'
|
|
5
13
|
|
|
6
|
-
export function getActionNameFromElement(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
export function getActionNameFromElement(
|
|
15
|
+
element,
|
|
16
|
+
userProgrammaticAttribute,
|
|
17
|
+
shouldIgnoreTextualFallback
|
|
18
|
+
) {
|
|
19
|
+
return (
|
|
20
|
+
getExplicitActionName(element, userProgrammaticAttribute) ||
|
|
21
|
+
getActionNameFromElementForStrategies(
|
|
22
|
+
element,
|
|
23
|
+
userProgrammaticAttribute,
|
|
24
|
+
shouldIgnoreTextualFallback
|
|
25
|
+
? shadowDomPriorityStrategies
|
|
26
|
+
: priorityStrategies
|
|
27
|
+
) ||
|
|
28
|
+
(!shouldIgnoreTextualFallback &&
|
|
29
|
+
getActionNameFromElementForStrategies(
|
|
30
|
+
element,
|
|
31
|
+
userProgrammaticAttribute,
|
|
32
|
+
fallbackStrategies
|
|
33
|
+
)) ||
|
|
34
|
+
''
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getExplicitActionName(element, userProgrammaticAttribute) {
|
|
13
39
|
return (
|
|
14
40
|
getActionNameFromElementProgrammatically(
|
|
15
41
|
element,
|
|
@@ -19,18 +45,7 @@ export function getActionNameFromElement(element, userProgrammaticAttribute) {
|
|
|
19
45
|
getActionNameFromElementProgrammatically(
|
|
20
46
|
element,
|
|
21
47
|
userProgrammaticAttribute
|
|
22
|
-
))
|
|
23
|
-
getActionNameFromElementForStrategies(
|
|
24
|
-
element,
|
|
25
|
-
userProgrammaticAttribute,
|
|
26
|
-
priorityStrategies
|
|
27
|
-
) ||
|
|
28
|
-
getActionNameFromElementForStrategies(
|
|
29
|
-
element,
|
|
30
|
-
userProgrammaticAttribute,
|
|
31
|
-
fallbackStrategies
|
|
32
|
-
) ||
|
|
33
|
-
''
|
|
48
|
+
))
|
|
34
49
|
)
|
|
35
50
|
}
|
|
36
51
|
|
|
@@ -41,21 +56,13 @@ function getActionNameFromElementProgrammatically(
|
|
|
41
56
|
var elementWithAttribute
|
|
42
57
|
// We don't use getActionNameFromElementForStrategies here, because we want to consider all parents,
|
|
43
58
|
// without limit. It is up to the user to declare a relevant naming strategy.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
-
} else {
|
|
51
|
-
var element = targetElement
|
|
52
|
-
while (element) {
|
|
53
|
-
if (element.hasAttribute(programmaticAttribute)) {
|
|
54
|
-
elementWithAttribute = element
|
|
55
|
-
break
|
|
56
|
-
}
|
|
57
|
-
element = element.parentElement
|
|
59
|
+
var element = targetElement
|
|
60
|
+
while (element) {
|
|
61
|
+
if (element.hasAttribute(programmaticAttribute)) {
|
|
62
|
+
elementWithAttribute = element
|
|
63
|
+
break
|
|
58
64
|
}
|
|
65
|
+
element = getParentElement(element)
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
if (!elementWithAttribute) {
|
|
@@ -143,6 +150,14 @@ var priorityStrategies = [
|
|
|
143
150
|
}
|
|
144
151
|
]
|
|
145
152
|
|
|
153
|
+
var shadowDomPriorityStrategies = priorityStrategies.concat([
|
|
154
|
+
function (element, userProgrammaticAttribute) {
|
|
155
|
+
if (element.nodeName === 'A' && element.hasAttribute('href')) {
|
|
156
|
+
return getTextualContent(element, userProgrammaticAttribute)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
])
|
|
160
|
+
|
|
146
161
|
var fallbackStrategies = [
|
|
147
162
|
function (element, userProgrammaticAttribute) {
|
|
148
163
|
return getTextualContent(element, userProgrammaticAttribute)
|
|
@@ -183,7 +198,7 @@ function getActionNameFromElementForStrategies(
|
|
|
183
198
|
if (element.nodeName === 'FORM') {
|
|
184
199
|
break
|
|
185
200
|
}
|
|
186
|
-
element = element
|
|
201
|
+
element = getParentElement(element)
|
|
187
202
|
recursionCounter += 1
|
|
188
203
|
}
|
|
189
204
|
}
|
|
@@ -197,6 +212,18 @@ function truncate(s) {
|
|
|
197
212
|
}
|
|
198
213
|
|
|
199
214
|
function getElementById(refElement, id) {
|
|
215
|
+
if (typeof refElement.getRootNode === 'function') {
|
|
216
|
+
var rootNode = refElement.getRootNode()
|
|
217
|
+
if (
|
|
218
|
+
isNodeShadowRoot(rootNode) &&
|
|
219
|
+
typeof rootNode.getElementById === 'function'
|
|
220
|
+
) {
|
|
221
|
+
var shadowElement = rootNode.getElementById(id)
|
|
222
|
+
if (shadowElement) {
|
|
223
|
+
return shadowElement
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
200
227
|
// Use the element ownerDocument here, because tests are executed in an iframe, so
|
|
201
228
|
// document.getElementById won't work.
|
|
202
229
|
return refElement.ownerDocument
|
|
@@ -279,17 +306,3 @@ function supportsLabelProperty() {
|
|
|
279
306
|
}
|
|
280
307
|
return supportsLabelPropertyResult
|
|
281
308
|
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Returns true if the browser supports the element.closest method. This should be the case
|
|
285
|
-
* everywhere except on Internet Explorer.
|
|
286
|
-
* Note: The result is computed lazily, because we don't want any DOM access when the SDK is
|
|
287
|
-
* evaluated.
|
|
288
|
-
*/
|
|
289
|
-
var supportsElementClosestResult
|
|
290
|
-
function supportsElementClosest() {
|
|
291
|
-
if (supportsElementClosestResult === undefined) {
|
|
292
|
-
supportsElementClosestResult = 'closest' in HTMLElement.prototype
|
|
293
|
-
}
|
|
294
|
-
return supportsElementClosestResult
|
|
295
|
-
}
|
|
@@ -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,9 @@ import {
|
|
|
15
15
|
ActionType,
|
|
16
16
|
isNullUndefinedDefaultValue,
|
|
17
17
|
isArray,
|
|
18
|
-
includes
|
|
18
|
+
includes,
|
|
19
|
+
isNodeShadowHost,
|
|
20
|
+
isElementNode
|
|
19
21
|
} from '@cloudcare/browser-core'
|
|
20
22
|
import { trackEventCounts } from '../../trackEventCounts'
|
|
21
23
|
import {
|
|
@@ -213,8 +215,9 @@ function startClickAction(
|
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
function computeClickActionBase(event, actionNameAttribute) {
|
|
216
|
-
var
|
|
217
|
-
var
|
|
218
|
+
var target = getEventTarget(event)
|
|
219
|
+
var rect = target.getBoundingClientRect()
|
|
220
|
+
var selector = getSelectorFromElement(target, actionNameAttribute)
|
|
218
221
|
if (selector) {
|
|
219
222
|
updateInteractionSelector(event.timeStamp, selector)
|
|
220
223
|
}
|
|
@@ -229,8 +232,28 @@ function computeClickActionBase(event, actionNameAttribute) {
|
|
|
229
232
|
x: Math.round(event.clientX - rect.left),
|
|
230
233
|
y: Math.round(event.clientY - rect.top)
|
|
231
234
|
},
|
|
232
|
-
name: getActionNameFromElement(
|
|
235
|
+
name: getActionNameFromElement(
|
|
236
|
+
target,
|
|
237
|
+
actionNameAttribute,
|
|
238
|
+
target !== event.target
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function getEventTarget(event) {
|
|
244
|
+
if (
|
|
245
|
+
event.composed === true &&
|
|
246
|
+
isNodeShadowHost(event.target) &&
|
|
247
|
+
typeof event.composedPath === 'function'
|
|
248
|
+
) {
|
|
249
|
+
var composedPath = event.composedPath()
|
|
250
|
+
// Wujie renders iframe-created elements in a shadow root. Use a node type check because those
|
|
251
|
+
// elements do not pass an instanceof Element check against the parent window constructor.
|
|
252
|
+
if (composedPath.length > 0 && isElementNode(composedPath[0])) {
|
|
253
|
+
return composedPath[0]
|
|
254
|
+
}
|
|
233
255
|
}
|
|
256
|
+
return event.target
|
|
234
257
|
}
|
|
235
258
|
|
|
236
259
|
var ClickStatus = {
|