@cloudcare/browser-rum 2.2.15 → 3.0.1
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 +388 -0
- package/cjs/domain/replay/record/observers.js +470 -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 +4400 -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 +127 -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 +336 -0
- package/esm/domain/replay/record/observers.js +454 -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 +4393 -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 +114 -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 +403 -0
- package/src/domain/replay/record/observers.js +565 -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 +4584 -0
- package/src/domain/replay/segmentCollection/index.js +6 -0
- package/src/domain/replay/segmentCollection/segment.js +86 -0
- package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
- package/src/domain/replay/segmentCollection/startDeflateWorker.js +102 -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
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isElementNode,
|
|
3
|
+
getParentNode,
|
|
4
|
+
isTextNode
|
|
5
|
+
} from '@cloudcare/browser-core'
|
|
6
|
+
import {
|
|
7
|
+
NodePrivacyLevel,
|
|
8
|
+
PRIVACY_ATTR_NAME,
|
|
9
|
+
PRIVACY_ATTR_VALUE_ALLOW,
|
|
10
|
+
PRIVACY_ATTR_VALUE_MASK,
|
|
11
|
+
PRIVACY_ATTR_VALUE_MASK_USER_INPUT,
|
|
12
|
+
PRIVACY_ATTR_VALUE_HIDDEN,
|
|
13
|
+
PRIVACY_CLASS_ALLOW,
|
|
14
|
+
PRIVACY_CLASS_MASK,
|
|
15
|
+
PRIVACY_CLASS_MASK_USER_INPUT,
|
|
16
|
+
PRIVACY_CLASS_HIDDEN,
|
|
17
|
+
FORM_PRIVATE_TAG_NAMES,
|
|
18
|
+
CENSORED_STRING_MARK
|
|
19
|
+
} from '../../../constants'
|
|
20
|
+
|
|
21
|
+
export var MAX_ATTRIBUTE_VALUE_CHAR_LENGTH = 100_000
|
|
22
|
+
|
|
23
|
+
var TEXT_MASKING_CHAR = 'x'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get node privacy level by iterating over its ancestors. When the direct parent privacy level is
|
|
27
|
+
* know, it is best to use something like:
|
|
28
|
+
*
|
|
29
|
+
* derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel)
|
|
30
|
+
*/
|
|
31
|
+
export function getNodePrivacyLevel(node, defaultPrivacyLevel) {
|
|
32
|
+
var parentNode = getParentNode(node)
|
|
33
|
+
var parentNodePrivacyLevel = parentNode
|
|
34
|
+
? getNodePrivacyLevel(parentNode, defaultPrivacyLevel)
|
|
35
|
+
: defaultPrivacyLevel
|
|
36
|
+
var selfNodePrivacyLevel = getNodeSelfPrivacyLevel(node)
|
|
37
|
+
return reducePrivacyLevel(selfNodePrivacyLevel, parentNodePrivacyLevel)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Reduces the next privacy level based on self + parent privacy levels
|
|
42
|
+
*/
|
|
43
|
+
export function reducePrivacyLevel(childPrivacyLevel, parentNodePrivacyLevel) {
|
|
44
|
+
switch (parentNodePrivacyLevel) {
|
|
45
|
+
// These values cannot be overridden
|
|
46
|
+
case NodePrivacyLevel.HIDDEN:
|
|
47
|
+
case NodePrivacyLevel.IGNORE:
|
|
48
|
+
return parentNodePrivacyLevel
|
|
49
|
+
}
|
|
50
|
+
switch (childPrivacyLevel) {
|
|
51
|
+
case NodePrivacyLevel.ALLOW:
|
|
52
|
+
case NodePrivacyLevel.MASK:
|
|
53
|
+
case NodePrivacyLevel.MASK_USER_INPUT:
|
|
54
|
+
case NodePrivacyLevel.HIDDEN:
|
|
55
|
+
case NodePrivacyLevel.IGNORE:
|
|
56
|
+
return childPrivacyLevel
|
|
57
|
+
default:
|
|
58
|
+
return parentNodePrivacyLevel
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Determines the node's own privacy level without checking for ancestors.
|
|
64
|
+
*/
|
|
65
|
+
export function getNodeSelfPrivacyLevel(node) {
|
|
66
|
+
// Only Element types can have a privacy level set
|
|
67
|
+
if (!isElementNode(node)) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var privAttr = node.getAttribute(PRIVACY_ATTR_NAME)
|
|
72
|
+
|
|
73
|
+
// Overrules for replay purpose
|
|
74
|
+
if (node.tagName === 'BASE') {
|
|
75
|
+
return NodePrivacyLevel.ALLOW
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Overrules to enforce end-user protection
|
|
79
|
+
if (node.tagName === 'INPUT') {
|
|
80
|
+
var inputElement = node
|
|
81
|
+
if (
|
|
82
|
+
inputElement.type === 'password' ||
|
|
83
|
+
inputElement.type === 'email' ||
|
|
84
|
+
inputElement.type === 'tel'
|
|
85
|
+
) {
|
|
86
|
+
return NodePrivacyLevel.MASK
|
|
87
|
+
}
|
|
88
|
+
if (inputElement.type === 'hidden') {
|
|
89
|
+
return NodePrivacyLevel.MASK
|
|
90
|
+
}
|
|
91
|
+
var autocomplete = inputElement.getAttribute('autocomplete')
|
|
92
|
+
// Handle input[autocomplete=cc-number/cc-csc/cc-exp/cc-exp-month/cc-exp-year]
|
|
93
|
+
if (autocomplete && autocomplete.indexOf('cc-') === 0) {
|
|
94
|
+
return NodePrivacyLevel.MASK
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Check HTML privacy attributes and classes
|
|
99
|
+
if (
|
|
100
|
+
privAttr === PRIVACY_ATTR_VALUE_HIDDEN ||
|
|
101
|
+
node.classList.contains(PRIVACY_CLASS_HIDDEN)
|
|
102
|
+
) {
|
|
103
|
+
return NodePrivacyLevel.HIDDEN
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
privAttr === PRIVACY_ATTR_VALUE_MASK ||
|
|
108
|
+
node.classList.contains(PRIVACY_CLASS_MASK)
|
|
109
|
+
) {
|
|
110
|
+
return NodePrivacyLevel.MASK
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (
|
|
114
|
+
privAttr === PRIVACY_ATTR_VALUE_MASK_USER_INPUT ||
|
|
115
|
+
node.classList.contains(PRIVACY_CLASS_MASK_USER_INPUT)
|
|
116
|
+
) {
|
|
117
|
+
return NodePrivacyLevel.MASK_USER_INPUT
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
privAttr === PRIVACY_ATTR_VALUE_ALLOW ||
|
|
122
|
+
node.classList.contains(PRIVACY_CLASS_ALLOW)
|
|
123
|
+
) {
|
|
124
|
+
return NodePrivacyLevel.ALLOW
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (shouldIgnoreElement(node)) {
|
|
128
|
+
return NodePrivacyLevel.IGNORE
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Helper aiming to unify `mask` and `mask-user-input` privacy levels:
|
|
134
|
+
*
|
|
135
|
+
* In the `mask` case, it is trivial: we should mask the element.
|
|
136
|
+
*
|
|
137
|
+
* In the `mask-user-input` case, we should mask the element only if it is a "form" element or the
|
|
138
|
+
* direct parent is a form element for text nodes).
|
|
139
|
+
*
|
|
140
|
+
* Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a
|
|
141
|
+
* node if it is ignored or hidden? it doesn't matter since it won't be serialized).
|
|
142
|
+
*/
|
|
143
|
+
export function shouldMaskNode(node, privacyLevel) {
|
|
144
|
+
switch (privacyLevel) {
|
|
145
|
+
case NodePrivacyLevel.MASK:
|
|
146
|
+
case NodePrivacyLevel.HIDDEN:
|
|
147
|
+
case NodePrivacyLevel.IGNORE:
|
|
148
|
+
return true
|
|
149
|
+
case NodePrivacyLevel.MASK_USER_INPUT:
|
|
150
|
+
return isTextNode(node)
|
|
151
|
+
? isFormElement(node.parentNode)
|
|
152
|
+
: isFormElement(node)
|
|
153
|
+
default:
|
|
154
|
+
return false
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function isFormElement(node) {
|
|
159
|
+
if (!node || node.nodeType !== node.ELEMENT_NODE) {
|
|
160
|
+
return false
|
|
161
|
+
}
|
|
162
|
+
var element = node
|
|
163
|
+
if (element.tagName === 'INPUT') {
|
|
164
|
+
switch (element.type) {
|
|
165
|
+
case 'button':
|
|
166
|
+
case 'color':
|
|
167
|
+
case 'reset':
|
|
168
|
+
case 'submit':
|
|
169
|
+
return false
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return !!FORM_PRIVATE_TAG_NAMES[element.tagName]
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Text censoring non-destructively maintains whitespace characters in order to preserve text shape
|
|
177
|
+
* during replay.
|
|
178
|
+
*/
|
|
179
|
+
export var censorText = function (text) {
|
|
180
|
+
return text.replace(/\S/g, TEXT_MASKING_CHAR)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function getTextContent(
|
|
184
|
+
textNode,
|
|
185
|
+
ignoreWhiteSpace,
|
|
186
|
+
parentNodePrivacyLevel
|
|
187
|
+
) {
|
|
188
|
+
// The parent node may not be a html element which has a tagName attribute.
|
|
189
|
+
// So just let it be undefined which is ok in this use case.
|
|
190
|
+
var parentTagName = textNode.parentElement?.tagName
|
|
191
|
+
var textContent = textNode.textContent || ''
|
|
192
|
+
|
|
193
|
+
if (ignoreWhiteSpace && !textContent.trim()) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
var nodePrivacyLevel = parentNodePrivacyLevel
|
|
198
|
+
|
|
199
|
+
var isStyle = parentTagName === 'STYLE' ? true : undefined
|
|
200
|
+
var isScript = parentTagName === 'SCRIPT'
|
|
201
|
+
|
|
202
|
+
if (isScript) {
|
|
203
|
+
// For perf reasons, we don't record script (heuristic)
|
|
204
|
+
textContent = CENSORED_STRING_MARK
|
|
205
|
+
} else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
|
|
206
|
+
// Should never occur, but just in case, we set to CENSORED_MARK.
|
|
207
|
+
textContent = CENSORED_STRING_MARK
|
|
208
|
+
} else if (
|
|
209
|
+
shouldMaskNode(textNode, nodePrivacyLevel) &&
|
|
210
|
+
// Style tags are `overruled` (Use `hide` to enforce privacy)
|
|
211
|
+
!isStyle
|
|
212
|
+
) {
|
|
213
|
+
if (
|
|
214
|
+
// Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP
|
|
215
|
+
parentTagName === 'DATALIST' ||
|
|
216
|
+
parentTagName === 'SELECT' ||
|
|
217
|
+
parentTagName === 'OPTGROUP'
|
|
218
|
+
) {
|
|
219
|
+
if (!textContent.trim()) {
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
} else if (parentTagName === 'OPTION') {
|
|
223
|
+
// <Option> has low entropy in charset + text length, so use `CENSORED_STRING_MARK` when masked
|
|
224
|
+
textContent = CENSORED_STRING_MARK
|
|
225
|
+
} else {
|
|
226
|
+
textContent = censorText(textContent)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return textContent
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* TODO: Preserve CSS element order, and record the presence of the tag, just don't render
|
|
234
|
+
* We don't need this logic on the recorder side.
|
|
235
|
+
* For security related meta's, customer can mask themmanually given they
|
|
236
|
+
* are easy to identify in the HEAD tag.
|
|
237
|
+
*/
|
|
238
|
+
export function shouldIgnoreElement(element) {
|
|
239
|
+
if (element.nodeName === 'SCRIPT') {
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (element.nodeName === 'LINK') {
|
|
244
|
+
var relAttribute = getLowerCaseAttribute('rel')
|
|
245
|
+
return (
|
|
246
|
+
// Link as script - Ignore only when rel=preload, modulepreload or prefetch
|
|
247
|
+
(/preload|prefetch/i.test(relAttribute) &&
|
|
248
|
+
getLowerCaseAttribute('as') === 'script') ||
|
|
249
|
+
// Favicons
|
|
250
|
+
relAttribute === 'shortcut icon' ||
|
|
251
|
+
relAttribute === 'icon'
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (element.nodeName === 'META') {
|
|
256
|
+
var nameAttribute = getLowerCaseAttribute('name')
|
|
257
|
+
var relAttribute = getLowerCaseAttribute('rel')
|
|
258
|
+
var propertyAttribute = getLowerCaseAttribute('property')
|
|
259
|
+
return (
|
|
260
|
+
// Favicons
|
|
261
|
+
/^msapplication-tile(image|color)$/.test(nameAttribute) ||
|
|
262
|
+
nameAttribute === 'application-name' ||
|
|
263
|
+
relAttribute === 'icon' ||
|
|
264
|
+
relAttribute === 'apple-touch-icon' ||
|
|
265
|
+
relAttribute === 'shortcut icon' ||
|
|
266
|
+
// Description
|
|
267
|
+
nameAttribute === 'keywords' ||
|
|
268
|
+
nameAttribute === 'description' ||
|
|
269
|
+
// Social
|
|
270
|
+
/^(og|twitter|fb):/.test(propertyAttribute) ||
|
|
271
|
+
/^(og|twitter):/.test(nameAttribute) ||
|
|
272
|
+
nameAttribute === 'pinterest' ||
|
|
273
|
+
// Robots
|
|
274
|
+
nameAttribute === 'robots' ||
|
|
275
|
+
nameAttribute === 'googlebot' ||
|
|
276
|
+
nameAttribute === 'bingbot' ||
|
|
277
|
+
// Http headers. Ex: X-UA-Compatible, Content-Type, Content-Language, cache-control,
|
|
278
|
+
// X-Translated-By
|
|
279
|
+
element.hasAttribute('http-equiv') ||
|
|
280
|
+
// Authorship
|
|
281
|
+
nameAttribute === 'author' ||
|
|
282
|
+
nameAttribute === 'generator' ||
|
|
283
|
+
nameAttribute === 'framework' ||
|
|
284
|
+
nameAttribute === 'publisher' ||
|
|
285
|
+
nameAttribute === 'progid' ||
|
|
286
|
+
/^article:/.test(propertyAttribute) ||
|
|
287
|
+
/^product:/.test(propertyAttribute) ||
|
|
288
|
+
// Verification
|
|
289
|
+
nameAttribute === 'google-site-verification' ||
|
|
290
|
+
nameAttribute === 'yandex-verification' ||
|
|
291
|
+
nameAttribute === 'csrf-token' ||
|
|
292
|
+
nameAttribute === 'p:domain_verify' ||
|
|
293
|
+
nameAttribute === 'verify-v1' ||
|
|
294
|
+
nameAttribute === 'verification' ||
|
|
295
|
+
nameAttribute === 'shopify-checkout-api-token'
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function getLowerCaseAttribute(name) {
|
|
300
|
+
return (element.getAttribute(name) || '').toLowerCase()
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return false
|
|
304
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { timeStampNow } from '@cloudcare/browser-core'
|
|
2
|
+
import { getViewportDimension } from '../../initViewportObservable'
|
|
3
|
+
|
|
4
|
+
import { RecordType, IncrementalSource } from '../../../types'
|
|
5
|
+
import { serializeDocument, SerializationContextStatus } from './serialize'
|
|
6
|
+
import { initObservers } from './observers'
|
|
7
|
+
|
|
8
|
+
import { getVisualViewport, getScrollX, getScrollY } from './viewports'
|
|
9
|
+
import { assembleIncrementalSnapshot } from './utils'
|
|
10
|
+
import { createElementsScrollPositions } from './elementsScrollPositions'
|
|
11
|
+
import { initShadowRootsController } from './shadowRootsController'
|
|
12
|
+
|
|
13
|
+
export function record(options) {
|
|
14
|
+
var emit = options.emit
|
|
15
|
+
// runtime checks for user options
|
|
16
|
+
if (!emit) {
|
|
17
|
+
throw new Error('emit function is required')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var elementsScrollPositions = createElementsScrollPositions()
|
|
21
|
+
|
|
22
|
+
var mutationCb = function (mutation) {
|
|
23
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.Mutation, mutation))
|
|
24
|
+
}
|
|
25
|
+
var inputCb = function (s) {
|
|
26
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.Input, s))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var shadowRootsController = initShadowRootsController(options.configuration, {
|
|
30
|
+
mutationCb,
|
|
31
|
+
inputCb
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
var takeFullSnapshot = function (timestamp, serializationContext) {
|
|
35
|
+
if (typeof timestamp === 'undefined') {
|
|
36
|
+
timestamp = timeStampNow()
|
|
37
|
+
}
|
|
38
|
+
if (typeof serializationContext === 'undefined') {
|
|
39
|
+
serializationContext = {
|
|
40
|
+
status: SerializationContextStatus.INITIAL_FULL_SNAPSHOT,
|
|
41
|
+
elementsScrollPositions: elementsScrollPositions,
|
|
42
|
+
shadowRootsController: shadowRootsController
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var _viewportDimension = getViewportDimension()
|
|
46
|
+
var width = _viewportDimension.width
|
|
47
|
+
var height = _viewportDimension.height
|
|
48
|
+
emit({
|
|
49
|
+
data: {
|
|
50
|
+
height: height,
|
|
51
|
+
href: window.location.href,
|
|
52
|
+
width: width
|
|
53
|
+
},
|
|
54
|
+
type: RecordType.Meta,
|
|
55
|
+
timestamp: timestamp
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
emit({
|
|
59
|
+
data: {
|
|
60
|
+
has_focus: document.hasFocus()
|
|
61
|
+
},
|
|
62
|
+
type: RecordType.Focus,
|
|
63
|
+
timestamp: timestamp
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
emit({
|
|
67
|
+
data: {
|
|
68
|
+
node: serializeDocument(
|
|
69
|
+
document,
|
|
70
|
+
options.configuration,
|
|
71
|
+
serializationContext
|
|
72
|
+
),
|
|
73
|
+
initialOffset: {
|
|
74
|
+
left: getScrollX(),
|
|
75
|
+
top: getScrollY()
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
type: RecordType.FullSnapshot,
|
|
79
|
+
timestamp: timestamp
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
if (window.visualViewport) {
|
|
83
|
+
emit({
|
|
84
|
+
data: getVisualViewport(),
|
|
85
|
+
type: RecordType.VisualViewport,
|
|
86
|
+
timestamp: timestamp
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
takeFullSnapshot()
|
|
92
|
+
var _initObservers = initObservers({
|
|
93
|
+
lifeCycle: options.lifeCycle,
|
|
94
|
+
configuration: options.configuration,
|
|
95
|
+
elementsScrollPositions: elementsScrollPositions,
|
|
96
|
+
inputCb: inputCb,
|
|
97
|
+
mediaInteractionCb: function (p) {
|
|
98
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.MediaInteraction, p))
|
|
99
|
+
},
|
|
100
|
+
mouseInteractionCb: function (mouseInteractionRecord) {
|
|
101
|
+
emit(mouseInteractionRecord)
|
|
102
|
+
},
|
|
103
|
+
mousemoveCb: function (positions, source) {
|
|
104
|
+
emit(assembleIncrementalSnapshot(source, { positions: positions }))
|
|
105
|
+
},
|
|
106
|
+
mutationCb: mutationCb,
|
|
107
|
+
scrollCb: function (p) {
|
|
108
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.Scroll, p))
|
|
109
|
+
},
|
|
110
|
+
styleSheetCb: function (r) {
|
|
111
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.StyleSheetRule, r))
|
|
112
|
+
},
|
|
113
|
+
viewportResizeCb: function (d) {
|
|
114
|
+
emit(assembleIncrementalSnapshot(IncrementalSource.ViewportResize, d))
|
|
115
|
+
},
|
|
116
|
+
frustrationCb: function (frustrationRecord) {
|
|
117
|
+
emit(frustrationRecord)
|
|
118
|
+
},
|
|
119
|
+
focusCb: function (data) {
|
|
120
|
+
emit({
|
|
121
|
+
data: data,
|
|
122
|
+
type: RecordType.Focus,
|
|
123
|
+
timestamp: timeStampNow()
|
|
124
|
+
})
|
|
125
|
+
},
|
|
126
|
+
visualViewportResizeCb: function (data) {
|
|
127
|
+
emit({
|
|
128
|
+
data: data,
|
|
129
|
+
type: RecordType.VisualViewport,
|
|
130
|
+
timestamp: timeStampNow()
|
|
131
|
+
})
|
|
132
|
+
},
|
|
133
|
+
shadowRootsController: shadowRootsController
|
|
134
|
+
})
|
|
135
|
+
var stopObservers = _initObservers.stop
|
|
136
|
+
var flushMutationsFromObservers = _initObservers.flush
|
|
137
|
+
function flushMutations() {
|
|
138
|
+
shadowRootsController.flush()
|
|
139
|
+
flushMutationsFromObservers()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
stop: function () {
|
|
144
|
+
shadowRootsController.stop()
|
|
145
|
+
stopObservers()
|
|
146
|
+
},
|
|
147
|
+
takeSubsequentFullSnapshot: function (timestamp) {
|
|
148
|
+
flushMutations()
|
|
149
|
+
takeFullSnapshot(timestamp, {
|
|
150
|
+
shadowRootsController: shadowRootsController,
|
|
151
|
+
status: SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT,
|
|
152
|
+
elementsScrollPositions: elementsScrollPositions
|
|
153
|
+
})
|
|
154
|
+
},
|
|
155
|
+
flushMutations: flushMutations,
|
|
156
|
+
shadowRootsController: shadowRootsController
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getParentNode,
|
|
3
|
+
isNodeShadowRoot,
|
|
4
|
+
buildUrl
|
|
5
|
+
} from '@cloudcare/browser-core'
|
|
6
|
+
import { CENSORED_STRING_MARK } from '../../../constants'
|
|
7
|
+
import { shouldMaskNode } from './privacy'
|
|
8
|
+
|
|
9
|
+
var serializedNodeIds = new WeakMap()
|
|
10
|
+
|
|
11
|
+
export function hasSerializedNode(node) {
|
|
12
|
+
return serializedNodeIds.has(node)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function nodeAndAncestorsHaveSerializedNode(node) {
|
|
16
|
+
var current = node
|
|
17
|
+
while (current) {
|
|
18
|
+
if (!hasSerializedNode(current) && !isNodeShadowRoot(current)) {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
current = getParentNode(current)
|
|
22
|
+
}
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getSerializedNodeId(node) {
|
|
27
|
+
return serializedNodeIds.get(node)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function setSerializedNodeId(node, serializeNodeId) {
|
|
31
|
+
serializedNodeIds.set(node, serializeNodeId)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the element "value" to be serialized as an attribute or an input update record. It respects
|
|
36
|
+
* the input privacy mode of the element.
|
|
37
|
+
* PERFROMANCE OPTIMIZATION: Assumes that privacy level `HIDDEN` is never encountered because of earlier checks.
|
|
38
|
+
*/
|
|
39
|
+
export function getElementInputValue(element, nodePrivacyLevel) {
|
|
40
|
+
/*
|
|
41
|
+
BROWSER SPEC NOTE: <input>, <select>
|
|
42
|
+
For some <input> elements, the `value` is an exceptional property/attribute that has the
|
|
43
|
+
value synced between el.value and el.getAttribute()
|
|
44
|
+
input[type=button,checkbox,hidden,image,radio,reset,submit]
|
|
45
|
+
*/
|
|
46
|
+
var tagName = element.tagName
|
|
47
|
+
var value = element.value
|
|
48
|
+
|
|
49
|
+
if (shouldMaskNode(element, nodePrivacyLevel)) {
|
|
50
|
+
var type = element.type
|
|
51
|
+
if (
|
|
52
|
+
tagName === 'INPUT' &&
|
|
53
|
+
(type === 'button' || type === 'submit' || type === 'reset')
|
|
54
|
+
) {
|
|
55
|
+
// Overrule `MASK` privacy level for button-like element values, as they are used during replay
|
|
56
|
+
// to display their label. They can still be hidden via the "hidden" privacy attribute or class name.
|
|
57
|
+
return value
|
|
58
|
+
} else if (!value || tagName === 'OPTION') {
|
|
59
|
+
// <Option> value provides no benefit
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
return CENSORED_STRING_MARK
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (tagName === 'OPTION' || tagName === 'SELECT') {
|
|
66
|
+
return element.value
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (tagName !== 'INPUT' && tagName !== 'TEXTAREA') {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return value
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm
|
|
77
|
+
export var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//
|
|
78
|
+
export var DATA_URI = /^data:.*,/i
|
|
79
|
+
|
|
80
|
+
export function switchToAbsoluteUrl(cssText, cssHref) {
|
|
81
|
+
return cssText.replace(
|
|
82
|
+
URL_IN_CSS_REF,
|
|
83
|
+
function (
|
|
84
|
+
matchingSubstring,
|
|
85
|
+
singleQuote,
|
|
86
|
+
urlWrappedInSingleQuotes,
|
|
87
|
+
doubleQuote,
|
|
88
|
+
urlWrappedInDoubleQuotes,
|
|
89
|
+
urlNotWrappedInQuotes
|
|
90
|
+
) {
|
|
91
|
+
var url =
|
|
92
|
+
urlWrappedInSingleQuotes ||
|
|
93
|
+
urlWrappedInDoubleQuotes ||
|
|
94
|
+
urlNotWrappedInQuotes
|
|
95
|
+
|
|
96
|
+
if (!cssHref || !url || ABSOLUTE_URL.test(url) || DATA_URI.test(url)) {
|
|
97
|
+
return matchingSubstring
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var quote = singleQuote || doubleQuote || ''
|
|
101
|
+
return `url(${quote}${makeUrlAbsolute(url, cssHref)}${quote})`
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function makeUrlAbsolute(url, baseUrl) {
|
|
107
|
+
try {
|
|
108
|
+
return buildUrl(url, baseUrl).href
|
|
109
|
+
} catch (_) {
|
|
110
|
+
return url
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function serializeStyleSheets(cssStyleSheets) {
|
|
115
|
+
if (cssStyleSheets === undefined || cssStyleSheets.length === 0) {
|
|
116
|
+
return undefined
|
|
117
|
+
}
|
|
118
|
+
return cssStyleSheets.map(function (cssStyleSheet) {
|
|
119
|
+
var rules = cssStyleSheet.cssRules || cssStyleSheet.rules
|
|
120
|
+
var cssRules = Array.from(rules, function (cssRule) {
|
|
121
|
+
return cssRule.cssText
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
var styleSheet = {
|
|
125
|
+
cssRules: cssRules,
|
|
126
|
+
disabled: cssStyleSheet.disabled || undefined,
|
|
127
|
+
media:
|
|
128
|
+
cssStyleSheet.media.length > 0
|
|
129
|
+
? Array.from(cssStyleSheet.media)
|
|
130
|
+
: undefined
|
|
131
|
+
}
|
|
132
|
+
return styleSheet
|
|
133
|
+
})
|
|
134
|
+
}
|