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