@cloudcare/browser-rum 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/domain/replay/record/privacy.js +1 -3
- package/cjs/domain/replay/record/serializationUtils.js +101 -0
- package/cjs/domain/replay/record/serialize.js +40 -13
- package/cjs/domain/rumSessionManager.js +1 -1
- package/esm/boot/buildEnv.js +1 -1
- package/esm/domain/replay/record/privacy.js +1 -3
- package/esm/domain/replay/record/serializationUtils.js +97 -0
- package/esm/domain/replay/record/serialize.js +41 -14
- package/esm/domain/rumSessionManager.js +1 -1
- package/package.json +2 -2
- package/src/domain/replay/record/privacy.js +1 -1
- package/src/domain/replay/record/serializationUtils.js +81 -2
- package/src/domain/replay/record/serialize.js +51 -12
- package/src/domain/rumSessionManager.js +1 -1
package/cjs/boot/buildEnv.js
CHANGED
|
@@ -173,11 +173,9 @@ var censorText = function censorText(text) {
|
|
|
173
173
|
exports.censorText = censorText;
|
|
174
174
|
|
|
175
175
|
function getTextContent(textNode, ignoreWhiteSpace, parentNodePrivacyLevel) {
|
|
176
|
-
var _textNode$parentEleme;
|
|
177
|
-
|
|
178
176
|
// The parent node may not be a html element which has a tagName attribute.
|
|
179
177
|
// So just let it be undefined which is ok in this use case.
|
|
180
|
-
var parentTagName =
|
|
178
|
+
var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
|
|
181
179
|
var textContent = textNode.textContent || '';
|
|
182
180
|
|
|
183
181
|
if (ignoreWhiteSpace && !textContent.trim()) {
|
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.URL_IN_CSS_REF = exports.DATA_URI = exports.ABSOLUTE_URL = void 0;
|
|
7
|
+
exports.absoluteToDoc = absoluteToDoc;
|
|
8
|
+
exports.getAbsoluteSrcsetString = getAbsoluteSrcsetString;
|
|
7
9
|
exports.getElementInputValue = getElementInputValue;
|
|
8
10
|
exports.getSerializedNodeId = getSerializedNodeId;
|
|
9
11
|
exports.hasSerializedNode = hasSerializedNode;
|
|
@@ -89,6 +91,19 @@ function getElementInputValue(element, nodePrivacyLevel) {
|
|
|
89
91
|
return value;
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
function extractOrigin(url) {
|
|
95
|
+
var origin = '';
|
|
96
|
+
|
|
97
|
+
if (url.indexOf('//') > -1) {
|
|
98
|
+
origin = url.split('/').slice(0, 3).join('/');
|
|
99
|
+
} else {
|
|
100
|
+
origin = url.split('/')[0];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
origin = origin.split('?')[0];
|
|
104
|
+
return origin;
|
|
105
|
+
}
|
|
106
|
+
|
|
92
107
|
var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
|
|
93
108
|
exports.URL_IN_CSS_REF = URL_IN_CSS_REF;
|
|
94
109
|
var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//;
|
|
@@ -105,6 +120,11 @@ function switchToAbsoluteUrl(cssText, cssHref) {
|
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
var quote = singleQuote || doubleQuote || '';
|
|
123
|
+
|
|
124
|
+
if (url[0] === '/') {
|
|
125
|
+
return 'url('.concat(quote).concat(extractOrigin(cssHref) + url).concat(quote, ')');
|
|
126
|
+
}
|
|
127
|
+
|
|
108
128
|
return "url(".concat(quote).concat(makeUrlAbsolute(url, cssHref)).concat(quote, ")");
|
|
109
129
|
});
|
|
110
130
|
}
|
|
@@ -134,4 +154,85 @@ function serializeStyleSheets(cssStyleSheets) {
|
|
|
134
154
|
};
|
|
135
155
|
return styleSheet;
|
|
136
156
|
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function absoluteToDoc(doc, attributeValue) {
|
|
160
|
+
if (!attributeValue || attributeValue.trim() === '') {
|
|
161
|
+
return attributeValue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
var a = doc.createElement('a');
|
|
165
|
+
a.href = attributeValue;
|
|
166
|
+
return a.href;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
|
|
170
|
+
var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
|
|
171
|
+
|
|
172
|
+
function getAbsoluteSrcsetString(doc, attributeValue) {
|
|
173
|
+
if (attributeValue.trim() === '') {
|
|
174
|
+
return attributeValue;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
var pos = 0;
|
|
178
|
+
|
|
179
|
+
function collectCharacters(regEx) {
|
|
180
|
+
var chars;
|
|
181
|
+
var match = regEx.exec(attributeValue.substring(pos));
|
|
182
|
+
|
|
183
|
+
if (match) {
|
|
184
|
+
chars = match[0];
|
|
185
|
+
pos += chars.length;
|
|
186
|
+
return chars;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return '';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
var output = [];
|
|
193
|
+
|
|
194
|
+
while (true) {
|
|
195
|
+
collectCharacters(SRCSET_COMMAS_OR_SPACES);
|
|
196
|
+
|
|
197
|
+
if (pos >= attributeValue.length) {
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
var url = collectCharacters(SRCSET_NOT_SPACES);
|
|
202
|
+
|
|
203
|
+
if (url.slice(-1) === ',') {
|
|
204
|
+
url = absoluteToDoc(doc, url.substring(0, url.length - 1));
|
|
205
|
+
output.push(url);
|
|
206
|
+
} else {
|
|
207
|
+
var descriptorsStr = '';
|
|
208
|
+
url = absoluteToDoc(doc, url);
|
|
209
|
+
var inParens = false;
|
|
210
|
+
|
|
211
|
+
while (true) {
|
|
212
|
+
var c = attributeValue.charAt(pos);
|
|
213
|
+
|
|
214
|
+
if (c === '') {
|
|
215
|
+
output.push((url + descriptorsStr).trim());
|
|
216
|
+
break;
|
|
217
|
+
} else if (!inParens) {
|
|
218
|
+
if (c === ',') {
|
|
219
|
+
pos += 1;
|
|
220
|
+
output.push((url + descriptorsStr).trim());
|
|
221
|
+
break;
|
|
222
|
+
} else if (c === '(') {
|
|
223
|
+
inParens = true;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
if (c === ')') {
|
|
227
|
+
inParens = false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
descriptorsStr += c;
|
|
232
|
+
pos += 1;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return output.join(', ');
|
|
137
238
|
}
|
|
@@ -216,11 +216,9 @@ function serializeElementNode(element, options) {
|
|
|
216
216
|
|
|
217
217
|
|
|
218
218
|
function serializeTextNode(textNode, options) {
|
|
219
|
-
var _textNode$parentEleme;
|
|
220
|
-
|
|
221
219
|
// The parent node may not be a html element which has a tagName attribute.
|
|
222
220
|
// So just let it be undefined which is ok in this use case.
|
|
223
|
-
var parentTagName =
|
|
221
|
+
var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
|
|
224
222
|
var textContent = (0, _privacy.getTextContent)(textNode, options.ignoreWhiteSpace || false, options.parentNodePrivacyLevel);
|
|
225
223
|
|
|
226
224
|
if (!textContent) {
|
|
@@ -324,19 +322,24 @@ function getValidTagName(tagName) {
|
|
|
324
322
|
return processedTagName;
|
|
325
323
|
}
|
|
326
324
|
|
|
327
|
-
function getCssRulesString(
|
|
328
|
-
|
|
329
|
-
|
|
325
|
+
function getCssRulesString(cssStyleSheet) {
|
|
326
|
+
if (!cssStyleSheet) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
330
329
|
|
|
331
|
-
|
|
332
|
-
var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
|
|
333
|
-
return (0, _serializationUtils.switchToAbsoluteUrl)(styleSheetCssText, s.href);
|
|
334
|
-
}
|
|
330
|
+
var rules;
|
|
335
331
|
|
|
336
|
-
|
|
337
|
-
|
|
332
|
+
try {
|
|
333
|
+
rules = cssStyleSheet.rules || cssStyleSheet.cssRules;
|
|
334
|
+
} catch (_unused) {// if css is protected by CORS we cannot access cssRules see: https://www.w3.org/TR/cssom-1/#the-cssstylesheet-interface
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!rules) {
|
|
338
338
|
return null;
|
|
339
339
|
}
|
|
340
|
+
|
|
341
|
+
var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
|
|
342
|
+
return (0, _serializationUtils.switchToAbsoluteUrl)(styleSheetCssText, cssStyleSheet.href);
|
|
340
343
|
}
|
|
341
344
|
|
|
342
345
|
function getCssRuleString(rule) {
|
|
@@ -351,6 +354,30 @@ function isSVGElement(el) {
|
|
|
351
354
|
return el.tagName === 'svg' || el instanceof SVGElement;
|
|
352
355
|
}
|
|
353
356
|
|
|
357
|
+
function transformAttribute(doc, tagName, name, value) {
|
|
358
|
+
if (name === 'src' || name === 'href' && value && !(tagName === 'use' && value[0] === '#')) {
|
|
359
|
+
return (0, _serializationUtils.absoluteToDoc)(doc, value);
|
|
360
|
+
} else if (name === 'xlink:href' && value && value[0] !== '#') {
|
|
361
|
+
return (0, _serializationUtils.absoluteToDoc)(doc, value);
|
|
362
|
+
} else if (name === 'background' && value && (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
|
|
363
|
+
return (0, _serializationUtils.absoluteToDoc)(doc, value);
|
|
364
|
+
} else if (name === 'srcset' && value) {
|
|
365
|
+
return (0, _serializationUtils.getAbsoluteSrcsetString)(doc, value);
|
|
366
|
+
} else if (name === 'style' && value) {
|
|
367
|
+
return (0, _serializationUtils.switchToAbsoluteUrl)(value, getHref());
|
|
368
|
+
} else if (tagName === 'object' && name === 'data' && value) {
|
|
369
|
+
return (0, _serializationUtils.absoluteToDoc)(doc, value);
|
|
370
|
+
} else {
|
|
371
|
+
return value;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function getHref() {
|
|
376
|
+
var a = document.createElement('a');
|
|
377
|
+
a.href = '';
|
|
378
|
+
return a.href;
|
|
379
|
+
}
|
|
380
|
+
|
|
354
381
|
function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
|
|
355
382
|
if (nodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN) {
|
|
356
383
|
return {};
|
|
@@ -366,7 +393,7 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
|
|
|
366
393
|
var attributeValue = serializeAttribute(element, nodePrivacyLevel, attributeName, options.configuration);
|
|
367
394
|
|
|
368
395
|
if (attributeValue !== null) {
|
|
369
|
-
safeAttrs[attributeName] = attributeValue;
|
|
396
|
+
safeAttrs[attributeName] = transformAttribute(doc, tagName, attributeName, attributeValue);
|
|
370
397
|
}
|
|
371
398
|
}
|
|
372
399
|
|
|
@@ -75,7 +75,7 @@ function computeSessionState(configuration, rawTrackingType) {
|
|
|
75
75
|
|
|
76
76
|
if (hasValidRumSession(rawTrackingType)) {
|
|
77
77
|
trackingType = rawTrackingType;
|
|
78
|
-
} else if (!(0, _browserCore.performDraw)(configuration.
|
|
78
|
+
} else if (!(0, _browserCore.performDraw)(configuration.sessionSampleRate)) {
|
|
79
79
|
trackingType = RumTrackingType.NOT_TRACKED;
|
|
80
80
|
} else if (!(0, _browserCore.performDraw)(configuration.sessionReplaySampleRate)) {
|
|
81
81
|
trackingType = RumTrackingType.TRACKED_WITHOUT_SESSION_REPLAY;
|
package/esm/boot/buildEnv.js
CHANGED
|
@@ -151,11 +151,9 @@ export var censorText = function censorText(text) {
|
|
|
151
151
|
return text.replace(/\S/g, TEXT_MASKING_CHAR);
|
|
152
152
|
};
|
|
153
153
|
export function getTextContent(textNode, ignoreWhiteSpace, parentNodePrivacyLevel) {
|
|
154
|
-
var _textNode$parentEleme;
|
|
155
|
-
|
|
156
154
|
// The parent node may not be a html element which has a tagName attribute.
|
|
157
155
|
// So just let it be undefined which is ok in this use case.
|
|
158
|
-
var parentTagName =
|
|
156
|
+
var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
|
|
159
157
|
var textContent = textNode.textContent || '';
|
|
160
158
|
|
|
161
159
|
if (ignoreWhiteSpace && !textContent.trim()) {
|
|
@@ -65,6 +65,20 @@ export function getElementInputValue(element, nodePrivacyLevel) {
|
|
|
65
65
|
|
|
66
66
|
return value;
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
function extractOrigin(url) {
|
|
70
|
+
var origin = '';
|
|
71
|
+
|
|
72
|
+
if (url.indexOf('//') > -1) {
|
|
73
|
+
origin = url.split('/').slice(0, 3).join('/');
|
|
74
|
+
} else {
|
|
75
|
+
origin = url.split('/')[0];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
origin = origin.split('?')[0];
|
|
79
|
+
return origin;
|
|
80
|
+
}
|
|
81
|
+
|
|
68
82
|
export var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
|
|
69
83
|
export var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//;
|
|
70
84
|
export var DATA_URI = /^data:.*,/i;
|
|
@@ -77,6 +91,11 @@ export function switchToAbsoluteUrl(cssText, cssHref) {
|
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
var quote = singleQuote || doubleQuote || '';
|
|
94
|
+
|
|
95
|
+
if (url[0] === '/') {
|
|
96
|
+
return 'url('.concat(quote).concat(extractOrigin(cssHref) + url).concat(quote, ')');
|
|
97
|
+
}
|
|
98
|
+
|
|
80
99
|
return "url(".concat(quote).concat(makeUrlAbsolute(url, cssHref)).concat(quote, ")");
|
|
81
100
|
});
|
|
82
101
|
}
|
|
@@ -104,4 +123,82 @@ export function serializeStyleSheets(cssStyleSheets) {
|
|
|
104
123
|
};
|
|
105
124
|
return styleSheet;
|
|
106
125
|
});
|
|
126
|
+
}
|
|
127
|
+
export function absoluteToDoc(doc, attributeValue) {
|
|
128
|
+
if (!attributeValue || attributeValue.trim() === '') {
|
|
129
|
+
return attributeValue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var a = doc.createElement('a');
|
|
133
|
+
a.href = attributeValue;
|
|
134
|
+
return a.href;
|
|
135
|
+
}
|
|
136
|
+
var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
|
|
137
|
+
var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
|
|
138
|
+
export function getAbsoluteSrcsetString(doc, attributeValue) {
|
|
139
|
+
if (attributeValue.trim() === '') {
|
|
140
|
+
return attributeValue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var pos = 0;
|
|
144
|
+
|
|
145
|
+
function collectCharacters(regEx) {
|
|
146
|
+
var chars;
|
|
147
|
+
var match = regEx.exec(attributeValue.substring(pos));
|
|
148
|
+
|
|
149
|
+
if (match) {
|
|
150
|
+
chars = match[0];
|
|
151
|
+
pos += chars.length;
|
|
152
|
+
return chars;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var output = [];
|
|
159
|
+
|
|
160
|
+
while (true) {
|
|
161
|
+
collectCharacters(SRCSET_COMMAS_OR_SPACES);
|
|
162
|
+
|
|
163
|
+
if (pos >= attributeValue.length) {
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var url = collectCharacters(SRCSET_NOT_SPACES);
|
|
168
|
+
|
|
169
|
+
if (url.slice(-1) === ',') {
|
|
170
|
+
url = absoluteToDoc(doc, url.substring(0, url.length - 1));
|
|
171
|
+
output.push(url);
|
|
172
|
+
} else {
|
|
173
|
+
var descriptorsStr = '';
|
|
174
|
+
url = absoluteToDoc(doc, url);
|
|
175
|
+
var inParens = false;
|
|
176
|
+
|
|
177
|
+
while (true) {
|
|
178
|
+
var c = attributeValue.charAt(pos);
|
|
179
|
+
|
|
180
|
+
if (c === '') {
|
|
181
|
+
output.push((url + descriptorsStr).trim());
|
|
182
|
+
break;
|
|
183
|
+
} else if (!inParens) {
|
|
184
|
+
if (c === ',') {
|
|
185
|
+
pos += 1;
|
|
186
|
+
output.push((url + descriptorsStr).trim());
|
|
187
|
+
break;
|
|
188
|
+
} else if (c === '(') {
|
|
189
|
+
inParens = true;
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
if (c === ')') {
|
|
193
|
+
inParens = false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
descriptorsStr += c;
|
|
198
|
+
pos += 1;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return output.join(', ');
|
|
107
204
|
}
|
|
@@ -3,7 +3,7 @@ import { STABLE_ATTRIBUTES } from '../../rumEventsCollection/actions/getSelector
|
|
|
3
3
|
import { NodePrivacyLevel, PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_HIDDEN, CENSORED_STRING_MARK, CENSORED_IMG_MARK } from '../../../constants';
|
|
4
4
|
import { NodeType } from '../../../types';
|
|
5
5
|
import { getTextContent, shouldMaskNode, reducePrivacyLevel, getNodeSelfPrivacyLevel, MAX_ATTRIBUTE_VALUE_CHAR_LENGTH } from './privacy';
|
|
6
|
-
import { getSerializedNodeId, setSerializedNodeId, getElementInputValue, switchToAbsoluteUrl, serializeStyleSheets } from './serializationUtils'; // Those values are the only one that can be used when inheriting privacy levels from parent to
|
|
6
|
+
import { getSerializedNodeId, setSerializedNodeId, getElementInputValue, switchToAbsoluteUrl, serializeStyleSheets, absoluteToDoc, getAbsoluteSrcsetString } from './serializationUtils'; // Those values are the only one that can be used when inheriting privacy levels from parent to
|
|
7
7
|
// children during serialization, since HIDDEN and IGNORE shouldn't serialize their children. This
|
|
8
8
|
// ensures that no children are serialized when they shouldn't.
|
|
9
9
|
|
|
@@ -192,11 +192,9 @@ export function serializeElementNode(element, options) {
|
|
|
192
192
|
*/
|
|
193
193
|
|
|
194
194
|
function serializeTextNode(textNode, options) {
|
|
195
|
-
var _textNode$parentEleme;
|
|
196
|
-
|
|
197
195
|
// The parent node may not be a html element which has a tagName attribute.
|
|
198
196
|
// So just let it be undefined which is ok in this use case.
|
|
199
|
-
var parentTagName =
|
|
197
|
+
var parentTagName = textNode.parentElement && textNode.parentElement.tagName;
|
|
200
198
|
var textContent = getTextContent(textNode, options.ignoreWhiteSpace || false, options.parentNodePrivacyLevel);
|
|
201
199
|
|
|
202
200
|
if (!textContent) {
|
|
@@ -298,19 +296,24 @@ function getValidTagName(tagName) {
|
|
|
298
296
|
return processedTagName;
|
|
299
297
|
}
|
|
300
298
|
|
|
301
|
-
function getCssRulesString(
|
|
302
|
-
|
|
303
|
-
|
|
299
|
+
function getCssRulesString(cssStyleSheet) {
|
|
300
|
+
if (!cssStyleSheet) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
304
303
|
|
|
305
|
-
|
|
306
|
-
var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
|
|
307
|
-
return switchToAbsoluteUrl(styleSheetCssText, s.href);
|
|
308
|
-
}
|
|
304
|
+
var rules;
|
|
309
305
|
|
|
310
|
-
|
|
311
|
-
|
|
306
|
+
try {
|
|
307
|
+
rules = cssStyleSheet.rules || cssStyleSheet.cssRules;
|
|
308
|
+
} catch (_unused) {// if css is protected by CORS we cannot access cssRules see: https://www.w3.org/TR/cssom-1/#the-cssstylesheet-interface
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (!rules) {
|
|
312
312
|
return null;
|
|
313
313
|
}
|
|
314
|
+
|
|
315
|
+
var styleSheetCssText = Array.from(rules, getCssRuleString).join('');
|
|
316
|
+
return switchToAbsoluteUrl(styleSheetCssText, cssStyleSheet.href);
|
|
314
317
|
}
|
|
315
318
|
|
|
316
319
|
function getCssRuleString(rule) {
|
|
@@ -325,6 +328,30 @@ function isSVGElement(el) {
|
|
|
325
328
|
return el.tagName === 'svg' || el instanceof SVGElement;
|
|
326
329
|
}
|
|
327
330
|
|
|
331
|
+
function transformAttribute(doc, tagName, name, value) {
|
|
332
|
+
if (name === 'src' || name === 'href' && value && !(tagName === 'use' && value[0] === '#')) {
|
|
333
|
+
return absoluteToDoc(doc, value);
|
|
334
|
+
} else if (name === 'xlink:href' && value && value[0] !== '#') {
|
|
335
|
+
return absoluteToDoc(doc, value);
|
|
336
|
+
} else if (name === 'background' && value && (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
|
|
337
|
+
return absoluteToDoc(doc, value);
|
|
338
|
+
} else if (name === 'srcset' && value) {
|
|
339
|
+
return getAbsoluteSrcsetString(doc, value);
|
|
340
|
+
} else if (name === 'style' && value) {
|
|
341
|
+
return switchToAbsoluteUrl(value, getHref());
|
|
342
|
+
} else if (tagName === 'object' && name === 'data' && value) {
|
|
343
|
+
return absoluteToDoc(doc, value);
|
|
344
|
+
} else {
|
|
345
|
+
return value;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function getHref() {
|
|
350
|
+
var a = document.createElement('a');
|
|
351
|
+
a.href = '';
|
|
352
|
+
return a.href;
|
|
353
|
+
}
|
|
354
|
+
|
|
328
355
|
function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
|
|
329
356
|
if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
|
|
330
357
|
return {};
|
|
@@ -340,7 +367,7 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
|
|
|
340
367
|
var attributeValue = serializeAttribute(element, nodePrivacyLevel, attributeName, options.configuration);
|
|
341
368
|
|
|
342
369
|
if (attributeValue !== null) {
|
|
343
|
-
safeAttrs[attributeName] = attributeValue;
|
|
370
|
+
safeAttrs[attributeName] = transformAttribute(doc, tagName, attributeName, attributeValue);
|
|
344
371
|
}
|
|
345
372
|
}
|
|
346
373
|
|
|
@@ -60,7 +60,7 @@ function computeSessionState(configuration, rawTrackingType) {
|
|
|
60
60
|
|
|
61
61
|
if (hasValidRumSession(rawTrackingType)) {
|
|
62
62
|
trackingType = rawTrackingType;
|
|
63
|
-
} else if (!performDraw(configuration.
|
|
63
|
+
} else if (!performDraw(configuration.sessionSampleRate)) {
|
|
64
64
|
trackingType = RumTrackingType.NOT_TRACKED;
|
|
65
65
|
} else if (!performDraw(configuration.sessionReplaySampleRate)) {
|
|
66
66
|
trackingType = RumTrackingType.TRACKED_WITHOUT_SESSION_REPLAY;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-rum",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
|
|
31
31
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "1e601c6b4281ab8745eeefb8da2099510652d9ec"
|
|
33
33
|
}
|
|
@@ -187,7 +187,7 @@ export function getTextContent(
|
|
|
187
187
|
) {
|
|
188
188
|
// The parent node may not be a html element which has a tagName attribute.
|
|
189
189
|
// So just let it be undefined which is ok in this use case.
|
|
190
|
-
var parentTagName = textNode.parentElement
|
|
190
|
+
var parentTagName = textNode.parentElement && textNode.parentElement.tagName
|
|
191
191
|
var textContent = textNode.textContent || ''
|
|
192
192
|
|
|
193
193
|
if (ignoreWhiteSpace && !textContent.trim()) {
|
|
@@ -72,7 +72,16 @@ export function getElementInputValue(element, nodePrivacyLevel) {
|
|
|
72
72
|
|
|
73
73
|
return value
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
function extractOrigin(url) {
|
|
76
|
+
var origin = ''
|
|
77
|
+
if (url.indexOf('//') > -1) {
|
|
78
|
+
origin = url.split('/').slice(0, 3).join('/')
|
|
79
|
+
} else {
|
|
80
|
+
origin = url.split('/')[0]
|
|
81
|
+
}
|
|
82
|
+
origin = origin.split('?')[0]
|
|
83
|
+
return origin
|
|
84
|
+
}
|
|
76
85
|
export var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm
|
|
77
86
|
export var ABSOLUTE_URL = /^[A-Za-z]+:|^\/\//
|
|
78
87
|
export var DATA_URI = /^data:.*,/i
|
|
@@ -96,8 +105,13 @@ export function switchToAbsoluteUrl(cssText, cssHref) {
|
|
|
96
105
|
if (!cssHref || !url || ABSOLUTE_URL.test(url) || DATA_URI.test(url)) {
|
|
97
106
|
return matchingSubstring
|
|
98
107
|
}
|
|
99
|
-
|
|
100
108
|
var quote = singleQuote || doubleQuote || ''
|
|
109
|
+
if (url[0] === '/') {
|
|
110
|
+
return 'url('
|
|
111
|
+
.concat(quote)
|
|
112
|
+
.concat(extractOrigin(cssHref) + url)
|
|
113
|
+
.concat(quote, ')')
|
|
114
|
+
}
|
|
101
115
|
return `url(${quote}${makeUrlAbsolute(url, cssHref)}${quote})`
|
|
102
116
|
}
|
|
103
117
|
)
|
|
@@ -132,3 +146,68 @@ export function serializeStyleSheets(cssStyleSheets) {
|
|
|
132
146
|
return styleSheet
|
|
133
147
|
})
|
|
134
148
|
}
|
|
149
|
+
export function absoluteToDoc(doc, attributeValue) {
|
|
150
|
+
if (!attributeValue || attributeValue.trim() === '') {
|
|
151
|
+
return attributeValue
|
|
152
|
+
}
|
|
153
|
+
var a = doc.createElement('a')
|
|
154
|
+
a.href = attributeValue
|
|
155
|
+
return a.href
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/
|
|
159
|
+
var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/
|
|
160
|
+
export function getAbsoluteSrcsetString(doc, attributeValue) {
|
|
161
|
+
if (attributeValue.trim() === '') {
|
|
162
|
+
return attributeValue
|
|
163
|
+
}
|
|
164
|
+
var pos = 0
|
|
165
|
+
function collectCharacters(regEx) {
|
|
166
|
+
var chars
|
|
167
|
+
var match = regEx.exec(attributeValue.substring(pos))
|
|
168
|
+
if (match) {
|
|
169
|
+
chars = match[0]
|
|
170
|
+
pos += chars.length
|
|
171
|
+
return chars
|
|
172
|
+
}
|
|
173
|
+
return ''
|
|
174
|
+
}
|
|
175
|
+
var output = []
|
|
176
|
+
while (true) {
|
|
177
|
+
collectCharacters(SRCSET_COMMAS_OR_SPACES)
|
|
178
|
+
if (pos >= attributeValue.length) {
|
|
179
|
+
break
|
|
180
|
+
}
|
|
181
|
+
var url = collectCharacters(SRCSET_NOT_SPACES)
|
|
182
|
+
if (url.slice(-1) === ',') {
|
|
183
|
+
url = absoluteToDoc(doc, url.substring(0, url.length - 1))
|
|
184
|
+
output.push(url)
|
|
185
|
+
} else {
|
|
186
|
+
var descriptorsStr = ''
|
|
187
|
+
url = absoluteToDoc(doc, url)
|
|
188
|
+
var inParens = false
|
|
189
|
+
while (true) {
|
|
190
|
+
var c = attributeValue.charAt(pos)
|
|
191
|
+
if (c === '') {
|
|
192
|
+
output.push((url + descriptorsStr).trim())
|
|
193
|
+
break
|
|
194
|
+
} else if (!inParens) {
|
|
195
|
+
if (c === ',') {
|
|
196
|
+
pos += 1
|
|
197
|
+
output.push((url + descriptorsStr).trim())
|
|
198
|
+
break
|
|
199
|
+
} else if (c === '(') {
|
|
200
|
+
inParens = true
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
if (c === ')') {
|
|
204
|
+
inParens = false
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
descriptorsStr += c
|
|
208
|
+
pos += 1
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return output.join(', ')
|
|
213
|
+
}
|