@cloudcare/browser-rum 3.3.12 → 3.3.14
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 +22 -2
- package/cjs/boot/recorderApi.js.map +1 -1
- package/cjs/boot/startRecording.js +54 -1
- package/cjs/boot/startRecording.js.map +1 -1
- package/cjs/domain/assembly.js +15 -2
- package/cjs/domain/assembly.js.map +1 -1
- package/cjs/domain/configuration.js +1 -0
- package/cjs/domain/configuration.js.map +1 -1
- package/cjs/domain/deflate/deflateWorker.js +1 -1
- package/cjs/domain/privacy.js +278 -0
- package/cjs/domain/privacy.js.map +1 -0
- package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/cjs/domain/replay/record/mutationObserver.js +16 -6
- package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
- package/cjs/domain/replay/record/privacy.js +11 -272
- package/cjs/domain/replay/record/privacy.js.map +1 -1
- package/cjs/domain/replay/record/record.js +94 -8
- package/cjs/domain/replay/record/record.js.map +1 -1
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +45 -17
- package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/cjs/domain/replay/timeAnchor.js +27 -0
- package/cjs/domain/replay/timeAnchor.js.map +1 -0
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +81 -19
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/trackViews.js +45 -7
- package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -1
- package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/cjs/domain/rumSessionManager.js +2 -2
- package/cjs/domain/rumSessionManager.js.map +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/recorderApi.js +23 -3
- package/esm/boot/recorderApi.js.map +1 -1
- package/esm/boot/startRecording.js +54 -1
- package/esm/boot/startRecording.js.map +1 -1
- package/esm/domain/assembly.js +16 -3
- package/esm/domain/assembly.js.map +1 -1
- package/esm/domain/configuration.js +1 -0
- package/esm/domain/configuration.js.map +1 -1
- package/esm/domain/deflate/deflateWorker.js +1 -1
- package/esm/domain/privacy.js +266 -0
- package/esm/domain/privacy.js.map +1 -0
- package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
- package/esm/domain/replay/record/mutationObserver.js +16 -6
- package/esm/domain/replay/record/mutationObserver.js.map +1 -1
- package/esm/domain/replay/record/privacy.js +1 -266
- package/esm/domain/replay/record/privacy.js.map +1 -1
- package/esm/domain/replay/record/record.js +78 -9
- package/esm/domain/replay/record/record.js.map +1 -1
- package/esm/domain/replay/segmentCollection/segmentCollection.js +45 -17
- package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
- package/esm/domain/replay/timeAnchor.js +20 -0
- package/esm/domain/replay/timeAnchor.js.map +1 -0
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +80 -18
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/trackViews.js +46 -8
- package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
- package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -1
- package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
- package/esm/domain/rumSessionManager.js +2 -2
- package/esm/domain/rumSessionManager.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/recorderApi.js +25 -3
- package/src/boot/startRecording.js +61 -1
- package/src/domain/assembly.js +18 -4
- package/src/domain/configuration.js +4 -0
- package/src/domain/privacy.js +356 -0
- package/src/domain/replay/record/mutationObserver.js +21 -11
- package/src/domain/replay/record/privacy.js +1 -356
- package/src/domain/replay/record/record.js +129 -8
- package/src/domain/replay/segmentCollection/segmentCollection.js +83 -18
- package/src/domain/replay/timeAnchor.js +33 -0
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +148 -21
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +19 -5
- package/src/domain/rumEventsCollection/view/trackViews.js +83 -12
- package/src/domain/rumEventsCollection/view/viewCollection.js +2 -1
- package/src/domain/rumSessionManager.js +2 -2
|
@@ -1,266 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { NodePrivacyLevel, PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_ALLOW, PRIVACY_ATTR_VALUE_MASK, PRIVACY_ATTR_VALUE_MASK_USER_INPUT, PRIVACY_ATTR_VALUE_HIDDEN, PRIVACY_CLASS_ALLOW, PRIVACY_CLASS_MASK, PRIVACY_CLASS_MASK_USER_INPUT, PRIVACY_CLASS_HIDDEN, FORM_PRIVATE_TAG_NAMES, CENSORED_STRING_MARK } from '../../../constants';
|
|
3
|
-
export var MAX_ATTRIBUTE_VALUE_CHAR_LENGTH = 100000;
|
|
4
|
-
var TEXT_MASKING_CHAR = 'x';
|
|
5
|
-
export var MAX_PRIVACY_ANCESTOR_DEPTH = 1000;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get node privacy level by iterating over its ancestors. When the direct parent privacy level is
|
|
9
|
-
* know, it is best to use something like:
|
|
10
|
-
*
|
|
11
|
-
* derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel)
|
|
12
|
-
*/
|
|
13
|
-
export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache) {
|
|
14
|
-
if (cache && cache.has(node)) {
|
|
15
|
-
return cache.get(node);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Resolve ancestors iteratively so an adversarially deep DOM cannot grow the
|
|
19
|
-
// JavaScript stack. If the watermark is crossed, fail closed: hiding the
|
|
20
|
-
// branch is safer than spending unbounded time resolving its privacy chain.
|
|
21
|
-
var unresolvedNodes = [];
|
|
22
|
-
var currentNode = node;
|
|
23
|
-
var inheritedPrivacyLevel;
|
|
24
|
-
while (currentNode) {
|
|
25
|
-
if (cache && cache.has(currentNode)) {
|
|
26
|
-
inheritedPrivacyLevel = cache.get(currentNode);
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
if (unresolvedNodes.length >= MAX_PRIVACY_ANCESTOR_DEPTH) {
|
|
30
|
-
inheritedPrivacyLevel = NodePrivacyLevel.HIDDEN;
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
unresolvedNodes.push(currentNode);
|
|
34
|
-
currentNode = getParentNode(currentNode);
|
|
35
|
-
}
|
|
36
|
-
if (inheritedPrivacyLevel === undefined) {
|
|
37
|
-
inheritedPrivacyLevel = defaultPrivacyLevel;
|
|
38
|
-
}
|
|
39
|
-
while (unresolvedNodes.length) {
|
|
40
|
-
var unresolvedNode = unresolvedNodes.pop();
|
|
41
|
-
inheritedPrivacyLevel = reducePrivacyLevel(getNodeSelfPrivacyLevel(unresolvedNode), inheritedPrivacyLevel);
|
|
42
|
-
if (cache) {
|
|
43
|
-
cache.set(unresolvedNode, inheritedPrivacyLevel);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return inheritedPrivacyLevel;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Reduces the next privacy level based on self + parent privacy levels
|
|
51
|
-
*/
|
|
52
|
-
export function reducePrivacyLevel(childPrivacyLevel, parentNodePrivacyLevel) {
|
|
53
|
-
switch (parentNodePrivacyLevel) {
|
|
54
|
-
// These values cannot be overridden
|
|
55
|
-
case NodePrivacyLevel.HIDDEN:
|
|
56
|
-
case NodePrivacyLevel.IGNORE:
|
|
57
|
-
return parentNodePrivacyLevel;
|
|
58
|
-
}
|
|
59
|
-
switch (childPrivacyLevel) {
|
|
60
|
-
case NodePrivacyLevel.ALLOW:
|
|
61
|
-
case NodePrivacyLevel.MASK:
|
|
62
|
-
case NodePrivacyLevel.MASK_USER_INPUT:
|
|
63
|
-
case NodePrivacyLevel.HIDDEN:
|
|
64
|
-
case NodePrivacyLevel.IGNORE:
|
|
65
|
-
return childPrivacyLevel;
|
|
66
|
-
default:
|
|
67
|
-
return parentNodePrivacyLevel;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Determines the node's own privacy level without checking for ancestors.
|
|
73
|
-
*/
|
|
74
|
-
export function getNodeSelfPrivacyLevel(node) {
|
|
75
|
-
// Only Element types can have a privacy level set
|
|
76
|
-
if (!isElementNode(node)) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
var privAttr = node.getAttribute(PRIVACY_ATTR_NAME);
|
|
80
|
-
|
|
81
|
-
// Overrules for replay purpose
|
|
82
|
-
if (node.tagName === 'BASE') {
|
|
83
|
-
return NodePrivacyLevel.ALLOW;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Overrules to enforce end-user protection
|
|
87
|
-
if (node.tagName === 'INPUT') {
|
|
88
|
-
var inputElement = node;
|
|
89
|
-
if (inputElement.type === 'password' || inputElement.type === 'email' || inputElement.type === 'tel') {
|
|
90
|
-
return NodePrivacyLevel.MASK;
|
|
91
|
-
}
|
|
92
|
-
if (inputElement.type === 'hidden') {
|
|
93
|
-
return NodePrivacyLevel.MASK;
|
|
94
|
-
}
|
|
95
|
-
var autocomplete = inputElement.getAttribute('autocomplete');
|
|
96
|
-
// Handle input[autocomplete=cc-number/cc-csc/cc-exp/cc-exp-month/cc-exp-year]
|
|
97
|
-
if (autocomplete && autocomplete.indexOf('cc-') === 0) {
|
|
98
|
-
return NodePrivacyLevel.MASK;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Check HTML privacy attributes and classes
|
|
103
|
-
if (privAttr === PRIVACY_ATTR_VALUE_HIDDEN || node.classList.contains(PRIVACY_CLASS_HIDDEN)) {
|
|
104
|
-
return NodePrivacyLevel.HIDDEN;
|
|
105
|
-
}
|
|
106
|
-
if (privAttr === PRIVACY_ATTR_VALUE_MASK || node.classList.contains(PRIVACY_CLASS_MASK)) {
|
|
107
|
-
return NodePrivacyLevel.MASK;
|
|
108
|
-
}
|
|
109
|
-
if (privAttr === PRIVACY_ATTR_VALUE_MASK_USER_INPUT || node.classList.contains(PRIVACY_CLASS_MASK_USER_INPUT)) {
|
|
110
|
-
return NodePrivacyLevel.MASK_USER_INPUT;
|
|
111
|
-
}
|
|
112
|
-
if (privAttr === PRIVACY_ATTR_VALUE_ALLOW || node.classList.contains(PRIVACY_CLASS_ALLOW)) {
|
|
113
|
-
return NodePrivacyLevel.ALLOW;
|
|
114
|
-
}
|
|
115
|
-
if (shouldIgnoreElement(node)) {
|
|
116
|
-
return NodePrivacyLevel.IGNORE;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Helper aiming to unify `mask` and `mask-user-input` privacy levels:
|
|
122
|
-
*
|
|
123
|
-
* In the `mask` case, it is trivial: we should mask the element.
|
|
124
|
-
*
|
|
125
|
-
* In the `mask-user-input` case, we should mask the element only if it is a "form" element or the
|
|
126
|
-
* direct parent is a form element for text nodes).
|
|
127
|
-
*
|
|
128
|
-
* Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a
|
|
129
|
-
* node if it is ignored or hidden? it doesn't matter since it won't be serialized).
|
|
130
|
-
*/
|
|
131
|
-
export function shouldMaskNode(configuration, node, privacyLevel) {
|
|
132
|
-
if (configuration.shouldMaskNode && configuration.shouldMaskNode(node, privacyLevel) === true) return true;
|
|
133
|
-
switch (privacyLevel) {
|
|
134
|
-
case NodePrivacyLevel.MASK:
|
|
135
|
-
case NodePrivacyLevel.HIDDEN:
|
|
136
|
-
case NodePrivacyLevel.IGNORE:
|
|
137
|
-
return true;
|
|
138
|
-
case NodePrivacyLevel.MASK_USER_INPUT:
|
|
139
|
-
return isTextNode(node) ? isFormElement(node.parentNode) : isFormElement(node);
|
|
140
|
-
default:
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function isFormElement(node) {
|
|
145
|
-
if (!node || node.nodeType !== node.ELEMENT_NODE) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
var element = node;
|
|
149
|
-
if (element.tagName === 'INPUT') {
|
|
150
|
-
switch (element.type) {
|
|
151
|
-
case 'button':
|
|
152
|
-
case 'color':
|
|
153
|
-
case 'reset':
|
|
154
|
-
case 'submit':
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return !!FORM_PRIVATE_TAG_NAMES[element.tagName];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Text censoring non-destructively maintains whitespace characters in order to preserve text shape
|
|
163
|
-
* during replay.
|
|
164
|
-
*/
|
|
165
|
-
export var censorText = function censorText(text) {
|
|
166
|
-
return text.replace(/\S/g, TEXT_MASKING_CHAR);
|
|
167
|
-
};
|
|
168
|
-
export function getTextContent(configuration, textNode, ignoreWhiteSpace, parentNodePrivacyLevel) {
|
|
169
|
-
// The parent node may not be a html element which has a tagName attribute.
|
|
170
|
-
// So just let it be undefined which is ok in this use case.
|
|
171
|
-
var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
|
|
172
|
-
var textContent = textNode.textContent || '';
|
|
173
|
-
if (ignoreWhiteSpace && !textContent.trim()) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
var nodePrivacyLevel = parentNodePrivacyLevel;
|
|
177
|
-
|
|
178
|
-
// var isStyle = parentTagName === 'STYLE' ? true : undefined
|
|
179
|
-
var isScript = parentTagName === 'SCRIPT';
|
|
180
|
-
if (isScript) {
|
|
181
|
-
// For perf reasons, we don't record script (heuristic)
|
|
182
|
-
textContent = CENSORED_STRING_MARK;
|
|
183
|
-
} else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
|
|
184
|
-
// Should never occur, but just in case, we set to CENSORED_MARK.
|
|
185
|
-
textContent = CENSORED_STRING_MARK;
|
|
186
|
-
} else if (shouldMaskNode(configuration, textNode, nodePrivacyLevel)) {
|
|
187
|
-
if (
|
|
188
|
-
// Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP
|
|
189
|
-
parentTagName === 'DATALIST' || parentTagName === 'SELECT' || parentTagName === 'OPTGROUP') {
|
|
190
|
-
if (!textContent.trim()) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
} else if (parentTagName === 'OPTION') {
|
|
194
|
-
// <Option> has low entropy in charset + text length, so use `CENSORED_STRING_MARK` when masked
|
|
195
|
-
textContent = CENSORED_STRING_MARK;
|
|
196
|
-
} else {
|
|
197
|
-
textContent = censorText(textContent);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// else if (isStyle && textContent) {
|
|
201
|
-
// try {
|
|
202
|
-
// // try to read style sheet
|
|
203
|
-
// if (textNode.nextSibling || textNode.previousSibling) {
|
|
204
|
-
// // This is not the only child of the stylesheet.
|
|
205
|
-
// // We can't read all of the sheet's .cssRules and expect them
|
|
206
|
-
// // to _only_ include the current rule(s) added by the text node.
|
|
207
|
-
// // So we'll be conservative and keep textContent as-is.
|
|
208
|
-
// } else if (
|
|
209
|
-
// textNode.parentNode &&
|
|
210
|
-
// textNode.parentNode.sheet &&
|
|
211
|
-
// textNode.parentNode.sheet.cssRules
|
|
212
|
-
// ) {
|
|
213
|
-
// textContent = getCssRulesString(textNode.parentNode.sheet)
|
|
214
|
-
// }
|
|
215
|
-
// } catch (err) {}
|
|
216
|
-
// textContent = switchToAbsoluteUrl(textContent, getHref())
|
|
217
|
-
// }
|
|
218
|
-
return textContent;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* We don't need this logic on the recorder side.
|
|
223
|
-
* For security related meta's, customer can mask themmanually given they
|
|
224
|
-
* are easy to identify in the HEAD tag.
|
|
225
|
-
*/
|
|
226
|
-
export function shouldIgnoreElement(element) {
|
|
227
|
-
if (element.nodeName === 'SCRIPT') {
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
230
|
-
if (element.nodeName === 'LINK') {
|
|
231
|
-
var relAttribute = getLowerCaseAttribute('rel');
|
|
232
|
-
return (
|
|
233
|
-
// Link as script - Ignore only when rel=preload, modulepreload or prefetch
|
|
234
|
-
/preload|prefetch/i.test(relAttribute) && getLowerCaseAttribute('as') === 'script' ||
|
|
235
|
-
// Favicons
|
|
236
|
-
relAttribute === 'shortcut icon' || relAttribute === 'icon'
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
if (element.nodeName === 'META') {
|
|
240
|
-
var nameAttribute = getLowerCaseAttribute('name');
|
|
241
|
-
var relAttribute = getLowerCaseAttribute('rel');
|
|
242
|
-
var propertyAttribute = getLowerCaseAttribute('property');
|
|
243
|
-
return (
|
|
244
|
-
// Favicons
|
|
245
|
-
/^msapplication-tile(image|color)$/.test(nameAttribute) || nameAttribute === 'application-name' || relAttribute === 'icon' || relAttribute === 'apple-touch-icon' || relAttribute === 'shortcut icon' ||
|
|
246
|
-
// Description
|
|
247
|
-
nameAttribute === 'keywords' || nameAttribute === 'description' ||
|
|
248
|
-
// Social
|
|
249
|
-
/^(og|twitter|fb):/.test(propertyAttribute) || /^(og|twitter):/.test(nameAttribute) || nameAttribute === 'pinterest' ||
|
|
250
|
-
// Robots
|
|
251
|
-
nameAttribute === 'robots' || nameAttribute === 'googlebot' || nameAttribute === 'bingbot' ||
|
|
252
|
-
// Http headers. Ex: X-UA-Compatible, Content-Type, Content-Language, cache-control,
|
|
253
|
-
// X-Translated-By
|
|
254
|
-
element.hasAttribute('http-equiv') ||
|
|
255
|
-
// Authorship
|
|
256
|
-
nameAttribute === 'author' || nameAttribute === 'generator' || nameAttribute === 'framework' || nameAttribute === 'publisher' || nameAttribute === 'progid' || /^article:/.test(propertyAttribute) || /^product:/.test(propertyAttribute) ||
|
|
257
|
-
// Verification
|
|
258
|
-
nameAttribute === 'google-site-verification' || nameAttribute === 'yandex-verification' || nameAttribute === 'csrf-token' || nameAttribute === 'p:domain_verify' || nameAttribute === 'verify-v1' || nameAttribute === 'verification' || nameAttribute === 'shopify-checkout-api-token'
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
function getLowerCaseAttribute(name) {
|
|
262
|
-
return (element.getAttribute(name) || '').toLowerCase();
|
|
263
|
-
}
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
//# sourceMappingURL=privacy.js.map
|
|
1
|
+
export * from '../../privacy';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"privacy.js","names":[
|
|
1
|
+
{"version":3,"file":"privacy.js","names":[],"sources":["../../../../src/domain/replay/record/privacy.js"],"mappings":"AAAA,cAAc,eAAe","ignoreList":[]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
import { timeStampNow, getScrollX, getScrollY, assign, addTelemetryDebug, getParentNode } from '@cloudcare/browser-core';
|
|
2
|
+
import { timeStampNow, getScrollX, getScrollY, assign, addTelemetryDebug, getParentNode, setInterval, clearInterval } from '@cloudcare/browser-core';
|
|
3
3
|
import { getViewportDimension } from '../../initViewportObservable';
|
|
4
|
+
import { SESSION_REPLAY_TIME_ANCHOR_INTERVAL, SESSION_REPLAY_TIME_ANCHOR_RECORD_TYPE, SESSION_REPLAY_TIME_ANCHOR_TAG } from '../timeAnchor';
|
|
5
|
+
export { SESSION_REPLAY_TIME_ANCHOR_INTERVAL, SESSION_REPLAY_TIME_ANCHOR_RECORD_TYPE, SESSION_REPLAY_TIME_ANCHOR_TAG } from '../timeAnchor';
|
|
4
6
|
import { RecordType, IncrementalSource } from '../../../types';
|
|
5
7
|
import { NodePrivacyLevel } from '../../../constants';
|
|
6
8
|
import { createMutationSerializerTask, SerializationContextStatus, getSerializedNodeApproxBytes, SERIALIZATION_MAX_NODE_COUNT, SERIALIZATION_MAX_APPROX_BYTES } from './serialize';
|
|
@@ -42,6 +44,8 @@ var FULL_SNAPSHOT_MAX_RESTART_COUNT = 3;
|
|
|
42
44
|
var FULL_SNAPSHOT_MAX_TOTAL_DURATION_MS = 1000;
|
|
43
45
|
var FULL_SNAPSHOT_MAX_WALL_DURATION_MS = 30000;
|
|
44
46
|
var FULL_SNAPSHOT_MUTATION_QUIET_DELAY_MS = 250;
|
|
47
|
+
var REPLAY_MEMORY_BUDGET_BYTES = 48 * 1024 * 1024;
|
|
48
|
+
var REPLAY_MEMORY_HIGH_WATERMARK_BYTES = 32 * 1024 * 1024;
|
|
45
49
|
export var MAX_FULL_SNAPSHOT_CANVAS_BASELINE_COUNT = 64;
|
|
46
50
|
var FULL_SNAPSHOT_CANVAS_BASELINE_TOTAL_TIMEOUT_MS = 2000;
|
|
47
51
|
var FULL_SNAPSHOT_CANVAS_BASELINE_ITEM_TIMEOUT_MS = 1000;
|
|
@@ -341,6 +345,55 @@ export function record(options) {
|
|
|
341
345
|
var pendingFullSnapshotBaselineRecords;
|
|
342
346
|
var pendingFullSnapshotBaselineMutationVersion;
|
|
343
347
|
var fullSnapshotWasPublished = false;
|
|
348
|
+
var replayMemoryBudget = options.$rMemoryBudget;
|
|
349
|
+
if (replayMemoryBudget) {
|
|
350
|
+
replayMemoryBudget.$rRecord = function () {
|
|
351
|
+
return pendingMutationAdmissionApproxBytes;
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
var lastReplayTimeAnchorTimestamp;
|
|
355
|
+
function emitReplayTimeAnchor() {
|
|
356
|
+
if (!fullSnapshotWasPublished || recordStopping || recordStopped || options.$rShouldEmitTimeAnchor && !options.$rShouldEmitTimeAnchor()) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
// A time anchor carries no replay state and is safe to drop. Do not put it
|
|
360
|
+
// on the shared deferred queue: `true` must mean that the segment layer
|
|
361
|
+
// actually admitted it, especially for the final stop boundary.
|
|
362
|
+
if (suppressRecordsUntilFullSnapshot || mutationPublicationBarrier || deferredRecords.length || deferredRecordAdmissionTimeout !== undefined || pendingMutationPayload || pendingMutationAdmissionQueue.length || mutationAdmissionEmitInProgress || mutationSourceFlushInProgress) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
var timestamp = timeStampNow();
|
|
366
|
+
if (timestamp === lastReplayTimeAnchorTimestamp) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
lastEmitWasLocallyBackpressured = false;
|
|
370
|
+
var accepted = rawEmit({
|
|
371
|
+
type: SESSION_REPLAY_TIME_ANCHOR_RECORD_TYPE,
|
|
372
|
+
timestamp: timestamp,
|
|
373
|
+
data: {
|
|
374
|
+
tag: SESSION_REPLAY_TIME_ANCHOR_TAG,
|
|
375
|
+
payload: {}
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
if (accepted === false) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
lastReplayTimeAnchorTimestamp = timestamp;
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
function emitPeriodicReplayTimeAnchor() {
|
|
385
|
+
// Keep the explicit page-exit anchor as the hidden boundary, but do not let
|
|
386
|
+
// the background timer extend the replay timeline while the Session is no
|
|
387
|
+
// longer renewed by visible-page activity.
|
|
388
|
+
if (document.visibilityState !== 'visible') {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
emitReplayTimeAnchor();
|
|
392
|
+
}
|
|
393
|
+
var replayTimeAnchorIntervalId = setInterval(emitPeriodicReplayTimeAnchor, SESSION_REPLAY_TIME_ANCHOR_INTERVAL);
|
|
394
|
+
registerInitializationCleanup(function () {
|
|
395
|
+
clearInterval(replayTimeAnchorIntervalId);
|
|
396
|
+
});
|
|
344
397
|
var domMutationVersion = 0;
|
|
345
398
|
var mutationActivityTargets = new Set();
|
|
346
399
|
var mutationActivityFlushScheduled = false;
|
|
@@ -444,9 +497,14 @@ export function record(options) {
|
|
|
444
497
|
if (pendingPublicationToken.$rPublished || pendingPublicationToken.$rQueued) {
|
|
445
498
|
return true;
|
|
446
499
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
500
|
+
// Serializing a newly added ancestor can stage an already-published
|
|
501
|
+
// descendant before the paired remove is normalized. This is the
|
|
502
|
+
// common DOM shape used by Cocos Creator when it inserts a wrapper and
|
|
503
|
+
// moves its existing GameCanvas into it. Until the destination add is
|
|
504
|
+
// queued, the node still belongs to the previously published replay
|
|
505
|
+
// tree and must remain eligible for the atomic remove + add transition.
|
|
506
|
+
// A genuinely new node has no previous publication token and therefore
|
|
507
|
+
// still falls through to false below.
|
|
450
508
|
}
|
|
451
509
|
var publicationToken = publicationTokenByNode.get(node);
|
|
452
510
|
return Boolean(publicationToken && (publicationToken.$rPublished || publicationToken.$rQueued));
|
|
@@ -781,10 +839,10 @@ export function record(options) {
|
|
|
781
839
|
function isPureAddMutationPayload(mutationPayload) {
|
|
782
840
|
return Boolean(mutationPayload && mutationPayload.adds.length && !mutationPayload.removes.length && !mutationPayload.texts.length && !mutationPayload.attributes.length);
|
|
783
841
|
}
|
|
784
|
-
function tryMergePendingPureAddMutationAdmission(entry) {
|
|
842
|
+
function tryMergePendingPureAddMutationAdmission(entry, admissionBytesLimit) {
|
|
785
843
|
var previousEntry = pendingMutationAdmissionQueue[pendingMutationAdmissionQueue.length - 1];
|
|
786
844
|
var mutationPayload = entry[0];
|
|
787
|
-
if (!previousEntry || previousEntry[3] || previousEntry.$rReferencedByDeferredRecord || !isPureAddMutationPayload(previousEntry[0]) || !isPureAddMutationPayload(mutationPayload) || previousEntry[1] + entry[1] > MAX_MUTATION_EMIT_APPROX_BYTES || pendingMutationAdmissionApproxBytes + entry[1] >
|
|
845
|
+
if (!previousEntry || previousEntry[3] || previousEntry.$rReferencedByDeferredRecord || !isPureAddMutationPayload(previousEntry[0]) || !isPureAddMutationPayload(mutationPayload) || previousEntry[1] + entry[1] > MAX_MUTATION_EMIT_APPROX_BYTES || pendingMutationAdmissionApproxBytes + entry[1] > admissionBytesLimit) {
|
|
788
846
|
return false;
|
|
789
847
|
}
|
|
790
848
|
|
|
@@ -811,12 +869,13 @@ export function record(options) {
|
|
|
811
869
|
});
|
|
812
870
|
return;
|
|
813
871
|
}
|
|
872
|
+
var admissionBytesLimit = replayMemoryBudget ? Math.min(MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES, REPLAY_MEMORY_BUDGET_BYTES - replayMemoryBudget.$rSegment()) : MAX_PENDING_MUTATION_ADMISSION_APPROX_BYTES;
|
|
814
873
|
for (var entryIndex = 0; entryIndex < mutationEntries.length; entryIndex += 1) {
|
|
815
874
|
var entry = mutationEntries[entryIndex];
|
|
816
|
-
if (tryMergePendingPureAddMutationAdmission(entry)) {
|
|
875
|
+
if (tryMergePendingPureAddMutationAdmission(entry, admissionBytesLimit)) {
|
|
817
876
|
continue;
|
|
818
877
|
}
|
|
819
|
-
if (pendingMutationAdmissionQueue.length + 1 > MAX_PENDING_MUTATION_ADMISSION_PAYLOADS || pendingMutationAdmissionApproxBytes + entry[1] >
|
|
878
|
+
if (pendingMutationAdmissionQueue.length + 1 > MAX_PENDING_MUTATION_ADMISSION_PAYLOADS || pendingMutationAdmissionApproxBytes + entry[1] > admissionBytesLimit) {
|
|
820
879
|
var rejectedTail = mutationEntries.slice(entryIndex);
|
|
821
880
|
rejectedTail.forEach(function (rejectedEntry) {
|
|
822
881
|
discardMutationMembership(rejectedEntry[0]);
|
|
@@ -1219,6 +1278,12 @@ export function record(options) {
|
|
|
1219
1278
|
}
|
|
1220
1279
|
}
|
|
1221
1280
|
function snapshotCanvasIfActive(canvas, snapshotOptions) {
|
|
1281
|
+
if (replayMemoryBudget && pendingMutationAdmissionApproxBytes + replayMemoryBudget.$rSegment() >= REPLAY_MEMORY_HIGH_WATERMARK_BYTES && snapshotOptions && (snapshotOptions.scheduler === 'continuous_snapshot' || snapshotOptions.scheduler === 'webgl_snapshot')) {
|
|
1282
|
+
return Promise.resolve({
|
|
1283
|
+
ok: false,
|
|
1284
|
+
reason: 'memory_pressure'
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1222
1287
|
if (isNodeIgnored(canvas)) {
|
|
1223
1288
|
return Promise.resolve({
|
|
1224
1289
|
ok: false,
|
|
@@ -2521,7 +2586,9 @@ export function record(options) {
|
|
|
2521
2586
|
firstCleanupError = error;
|
|
2522
2587
|
}
|
|
2523
2588
|
recordStopped = true;
|
|
2524
|
-
[
|
|
2589
|
+
[function () {
|
|
2590
|
+
clearInterval(replayTimeAnchorIntervalId);
|
|
2591
|
+
}, discardPendingMutationAdmissions, cancelMutationSourceFlushContinuation, cancelScheduledFullSnapshot, invalidateFullSnapshotCanvasBaseline, function () {
|
|
2525
2592
|
suppressRecordsUntilFullSnapshot = false;
|
|
2526
2593
|
previousReplayTreeAdmissionActive = false;
|
|
2527
2594
|
captureRecordsAgainstPreviousReplayTree = false;
|
|
@@ -2545,6 +2612,7 @@ export function record(options) {
|
|
|
2545
2612
|
}
|
|
2546
2613
|
var recorder = {
|
|
2547
2614
|
stop: stopRecording,
|
|
2615
|
+
$rEmitTimeAnchor: emitReplayTimeAnchor,
|
|
2548
2616
|
$rFlushCanvasCommands: function $rFlushCanvasCommands() {
|
|
2549
2617
|
// A previous boundary pass may have preserved the exact Canvas record
|
|
2550
2618
|
// after transient segment/encoder backpressure. Retry that object before
|
|
@@ -2605,6 +2673,7 @@ function createInactiveRecorder() {
|
|
|
2605
2673
|
var noop = function noop() {};
|
|
2606
2674
|
var recorder = {
|
|
2607
2675
|
stop: noop,
|
|
2676
|
+
$rEmitTimeAnchor: noop,
|
|
2608
2677
|
$rFlushCanvasCommands: noop,
|
|
2609
2678
|
snapshotCanvas: noop,
|
|
2610
2679
|
getSerializedNodeIdForDebug: noop,
|