@cloudcare/browser-rum 3.0.20 → 3.0.23
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/mutationBatch.js +1 -1
- package/cjs/domain/replay/record/mutationObserver.js +1 -1
- package/cjs/domain/replay/segmentCollection/segment.js +34 -22
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +28 -9
- package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +2 -3
- package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +9 -1
- package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +15 -4
- package/cjs/domain/rumEventsCollection/view/trackViews.js +2 -0
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rumPublicApi.js +3 -1
- package/esm/domain/replay/record/mutationBatch.js +16 -1
- package/esm/domain/replay/record/mutationObserver.js +102 -64
- package/esm/domain/replay/record/observers.js +5 -19
- package/esm/domain/replay/record/record.js +2 -2
- package/esm/domain/replay/record/serialize.js +10 -8
- package/esm/domain/replay/record/shadowRootsController.js +1 -1
- package/esm/domain/replay/replayStats.js +2 -2
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +3 -1
- package/esm/domain/replay/segmentCollection/segment.js +34 -22
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js +22 -7
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +1 -1
- package/esm/domain/rumEventsCollection/error/errorCollection.js +1 -1
- package/esm/domain/rumEventsCollection/resource/resourceCollection.js +2 -3
- package/esm/domain/rumEventsCollection/resource/resourceUtils.js +9 -1
- package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +15 -5
- package/esm/domain/rumEventsCollection/view/trackViews.js +2 -0
- package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -0
- package/esm/domain/tracing/traceIdentifier.js +1 -2
- package/package.json +8 -7
- package/src/boot/buildEnv.js +1 -1
- package/src/boot/recorderApi.js +0 -1
- package/src/domain/replay/segmentCollection/segment.js +41 -22
- package/src/domain/replay/segmentCollection/startDeflateWorker.js +26 -8
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +1 -6
- package/src/domain/rumEventsCollection/resource/resourceCollection.js +2 -2
- package/src/domain/rumEventsCollection/resource/resourceUtils.js +8 -1
- package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +19 -4
- package/src/domain/rumEventsCollection/view/trackViews.js +2 -1
- package/src/domain/rumEventsCollection/view/viewCollection.js +2 -0
- package/cjs/domain/replay/segmentCollection/deflateWorker.js +0 -4398
- package/esm/domain/replay/segmentCollection/deflateWorker.js +0 -4391
- package/src/domain/replay/segmentCollection/deflateWorker.js +0 -4583
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
var _eventTypeToMouseInte;
|
|
2
|
+
|
|
3
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
|
|
1
5
|
import { instrumentSetter, instrumentMethodAndCallOriginal, assign, throttle, DOM_EVENT, addEventListeners, addEventListener, noop, LifeCycleEventType, RumEventType, ActionType, isNodeShadowHost } from '@cloudcare/browser-core';
|
|
2
6
|
import { initViewportObservable } from '../../initViewportObservable';
|
|
3
7
|
import { NodePrivacyLevel } from '../../../constants';
|
|
@@ -81,25 +85,7 @@ export function initMoveObserver(cb) {
|
|
|
81
85
|
passive: true
|
|
82
86
|
}).stop;
|
|
83
87
|
}
|
|
84
|
-
var eventTypeToMouseInteraction = {
|
|
85
|
-
// Listen for pointerup DOM events instead of mouseup for MouseInteraction/MouseUp records. This
|
|
86
|
-
// allows to reference such records from Frustration records.
|
|
87
|
-
//
|
|
88
|
-
// In the context of supporting Mobile Session Replay, we introduced `PointerInteraction` records
|
|
89
|
-
// used by the Mobile SDKs in place of `MouseInteraction`. In the future, we should replace
|
|
90
|
-
// `MouseInteraction` by `PointerInteraction` in the Browser SDK so we have an uniform way to
|
|
91
|
-
// convey such interaction. This would cleanly solve the issue since we would have
|
|
92
|
-
// `PointerInteraction/Up` records that we could reference from `Frustration` records.
|
|
93
|
-
[DOM_EVENT.POINTER_UP]: MouseInteractionType.MouseUp,
|
|
94
|
-
[DOM_EVENT.MOUSE_DOWN]: MouseInteractionType.MouseDown,
|
|
95
|
-
[DOM_EVENT.CLICK]: MouseInteractionType.Click,
|
|
96
|
-
[DOM_EVENT.CONTEXT_MENU]: MouseInteractionType.ContextMenu,
|
|
97
|
-
[DOM_EVENT.DBL_CLICK]: MouseInteractionType.DblClick,
|
|
98
|
-
[DOM_EVENT.FOCUS]: MouseInteractionType.Focus,
|
|
99
|
-
[DOM_EVENT.BLUR]: MouseInteractionType.Blur,
|
|
100
|
-
[DOM_EVENT.TOUCH_START]: MouseInteractionType.TouchStart,
|
|
101
|
-
[DOM_EVENT.TOUCH_END]: MouseInteractionType.TouchEnd
|
|
102
|
-
};
|
|
88
|
+
var eventTypeToMouseInteraction = (_eventTypeToMouseInte = {}, _defineProperty(_eventTypeToMouseInte, DOM_EVENT.POINTER_UP, MouseInteractionType.MouseUp), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.MOUSE_DOWN, MouseInteractionType.MouseDown), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.CLICK, MouseInteractionType.Click), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.CONTEXT_MENU, MouseInteractionType.ContextMenu), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.DBL_CLICK, MouseInteractionType.DblClick), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.FOCUS, MouseInteractionType.Focus), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.BLUR, MouseInteractionType.Blur), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.TOUCH_START, MouseInteractionType.TouchStart), _defineProperty(_eventTypeToMouseInte, DOM_EVENT.TOUCH_END, MouseInteractionType.TouchEnd), _eventTypeToMouseInte);
|
|
103
89
|
export function initMouseInteractionObserver(cb, defaultPrivacyLevel) {
|
|
104
90
|
var handler = function handler(event) {
|
|
105
91
|
var target = getEventTarget(event);
|
|
@@ -25,8 +25,8 @@ export function record(options) {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
var shadowRootsController = initShadowRootsController(options.configuration, {
|
|
28
|
-
mutationCb,
|
|
29
|
-
inputCb
|
|
28
|
+
mutationCb: mutationCb,
|
|
29
|
+
inputCb: inputCb
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
var takeFullSnapshot = function takeFullSnapshot(timestamp, serializationContext) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
import { assign, startsWith, isNodeShadowHost, isNodeShadowRoot } from '@cloudcare/browser-core';
|
|
2
4
|
import { STABLE_ATTRIBUTES } from '../../rumEventsCollection/actions/getSelectorsFromElement';
|
|
3
5
|
import { NodePrivacyLevel, PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_HIDDEN, CENSORED_STRING_MARK, CENSORED_IMG_MARK } from '../../../constants';
|
|
@@ -133,11 +135,10 @@ export function serializeElementNode(element, options) {
|
|
|
133
135
|
return {
|
|
134
136
|
type: NodeType.Element,
|
|
135
137
|
tagName: tagName,
|
|
136
|
-
attributes: {
|
|
138
|
+
attributes: _defineProperty({
|
|
137
139
|
rr_width: width + 'px',
|
|
138
|
-
rr_height: height + 'px'
|
|
139
|
-
|
|
140
|
-
},
|
|
140
|
+
rr_height: height + 'px'
|
|
141
|
+
}, PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_HIDDEN),
|
|
141
142
|
childNodes: [],
|
|
142
143
|
isSVG: isSVG
|
|
143
144
|
};
|
|
@@ -498,10 +499,11 @@ function getAttributesForPrivacyLevel(element, nodePrivacyLevel, options) {
|
|
|
498
499
|
case SerializationContextStatus.SUBSEQUENT_FULL_SNAPSHOT:
|
|
499
500
|
if (serializationContext.elementsScrollPositions.has(element)) {
|
|
500
501
|
;
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
502
|
+
|
|
503
|
+
var _serializationContext = serializationContext.elementsScrollPositions.get(element);
|
|
504
|
+
|
|
505
|
+
scrollTop = _serializationContext.scrollTop;
|
|
506
|
+
scrollLeft = _serializationContext.scrollLeft;
|
|
505
507
|
}
|
|
506
508
|
|
|
507
509
|
break;
|
|
@@ -29,7 +29,7 @@ export var initShadowRootsController = function initShadowRootsController(config
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
entry.stop();
|
|
32
|
-
controllerByShadowRoot
|
|
32
|
+
controllerByShadowRoot["delete"](shadowRoot);
|
|
33
33
|
},
|
|
34
34
|
stop: function stop() {
|
|
35
35
|
controllerByShadowRoot.forEach(function (event) {
|
|
@@ -50,13 +50,13 @@ function deleteOldestStats() {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if (statsPerView.keys) {
|
|
53
|
-
statsPerView
|
|
53
|
+
statsPerView["delete"](statsPerView.keys().next().value);
|
|
54
54
|
} else {
|
|
55
55
|
// IE11 doesn't support map.keys
|
|
56
56
|
var isFirst = true;
|
|
57
57
|
statsPerView.forEach(function (_value, key) {
|
|
58
58
|
if (isFirst) {
|
|
59
|
-
statsPerView
|
|
59
|
+
statsPerView["delete"](key);
|
|
60
60
|
isFirst = false;
|
|
61
61
|
}
|
|
62
62
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
2
|
+
|
|
1
3
|
import { objectEntries, each } from '@cloudcare/browser-core';
|
|
2
4
|
export function buildReplayPayload(data, metadata, rawSegmentBytesCount) {
|
|
3
5
|
var formData = new FormData();
|
|
@@ -22,7 +24,7 @@ export function toFormEntries(input, onEntry, prefix) {
|
|
|
22
24
|
var value = item[1];
|
|
23
25
|
var key = item[0];
|
|
24
26
|
|
|
25
|
-
if (
|
|
27
|
+
if (_typeof(value) === 'object' && value !== null) {
|
|
26
28
|
toFormEntries(value, onEntry, '' + prefix + key + '_');
|
|
27
29
|
} else {
|
|
28
30
|
onEntry('' + prefix + key, String(value));
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { assign } from '@cloudcare/browser-core';
|
|
1
|
+
import { assign, addEventListener, concatBuffers } from '@cloudcare/browser-core';
|
|
2
2
|
import { RecordType } from '../../../types';
|
|
3
3
|
import * as replayStats from '../replayStats';
|
|
4
|
+
var STREAM_ID = 1;
|
|
4
5
|
var nextId = 0;
|
|
5
6
|
export function Segment(worker, context, creationReason, initialRecord, onWrote, onFlushed) {
|
|
6
7
|
this.worker = worker;
|
|
8
|
+
this.pendingWriteCount = 0;
|
|
7
9
|
this.id = nextId++;
|
|
8
10
|
var viewId = context.view.id;
|
|
9
11
|
this.metadata = assign({
|
|
@@ -17,24 +19,32 @@ export function Segment(worker, context, creationReason, initialRecord, onWrote,
|
|
|
17
19
|
}, context);
|
|
18
20
|
replayStats.addSegment(viewId);
|
|
19
21
|
replayStats.addRecord(viewId);
|
|
22
|
+
var rawBytesCount = 0;
|
|
23
|
+
var compressedBytesCount = 0;
|
|
24
|
+
var compressedData = [];
|
|
20
25
|
|
|
21
26
|
var _this = this;
|
|
22
27
|
|
|
23
|
-
var
|
|
28
|
+
var wokerListener = addEventListener(worker, 'message', function (params) {
|
|
24
29
|
var data = params.data;
|
|
25
30
|
|
|
26
|
-
if (data.type
|
|
31
|
+
if (data.type !== 'wrote') {
|
|
27
32
|
return;
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
if (data.id === _this.id) {
|
|
36
|
+
_this.pendingWriteCount -= 1;
|
|
31
37
|
replayStats.addWroteData(viewId, data.additionalBytesCount);
|
|
38
|
+
rawBytesCount += data.additionalBytesCount;
|
|
39
|
+
compressedBytesCount += data.result.length;
|
|
40
|
+
compressedData.push(data.result);
|
|
32
41
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
if (_this.flushReason && _this.pendingWriteCount === 0) {
|
|
43
|
+
compressedData.push(data.trailer);
|
|
44
|
+
onFlushed(concatBuffers(compressedData), rawBytesCount);
|
|
45
|
+
removeMessageListener();
|
|
36
46
|
} else {
|
|
37
|
-
onWrote(
|
|
47
|
+
onWrote(compressedBytesCount);
|
|
38
48
|
}
|
|
39
49
|
} else if (data.id > _this.id) {
|
|
40
50
|
// Messages should be received in the same order as they are sent, so if we receive a
|
|
@@ -45,16 +55,12 @@ export function Segment(worker, context, creationReason, initialRecord, onWrote,
|
|
|
45
55
|
// should already have been removed. But if something goes wrong and we didn't receive a
|
|
46
56
|
// "flush" response, remove the listener to avoid any leak, and send a monitor message to
|
|
47
57
|
// help investigate the issue.
|
|
48
|
-
|
|
58
|
+
removeMessageListener();
|
|
49
59
|
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
worker.addEventListener('message', listener);
|
|
53
|
-
this.worker.postMessage({
|
|
54
|
-
data: '{"records":[' + JSON.stringify(initialRecord),
|
|
55
|
-
id: this.id,
|
|
56
|
-
action: 'write'
|
|
57
60
|
});
|
|
61
|
+
var removeMessageListener = wokerListener.stop; // worker.addEventListener('message', listener)
|
|
62
|
+
|
|
63
|
+
this.write('{"records":[' + JSON.stringify(initialRecord));
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
Segment.prototype.addRecord = function (record) {
|
|
@@ -67,18 +73,24 @@ Segment.prototype.addRecord = function (record) {
|
|
|
67
73
|
this.metadata.has_full_snapshot = record.type === RecordType.FullSnapshot;
|
|
68
74
|
}
|
|
69
75
|
|
|
76
|
+
this.write(',' + JSON.stringify(record));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
Segment.prototype.flush = function (reason) {
|
|
80
|
+
this.write('],' + JSON.stringify(this.metadata).slice(1) + '\n');
|
|
70
81
|
this.worker.postMessage({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
action: 'write'
|
|
82
|
+
action: 'reset',
|
|
83
|
+
streamId: STREAM_ID
|
|
74
84
|
});
|
|
85
|
+
this.flushReason = reason;
|
|
75
86
|
};
|
|
76
87
|
|
|
77
|
-
Segment.prototype.
|
|
88
|
+
Segment.prototype.write = function (data) {
|
|
89
|
+
this.pendingWriteCount += 1;
|
|
78
90
|
this.worker.postMessage({
|
|
79
|
-
data:
|
|
91
|
+
data: data,
|
|
80
92
|
id: this.id,
|
|
81
|
-
|
|
93
|
+
streamId: STREAM_ID,
|
|
94
|
+
action: 'write'
|
|
82
95
|
});
|
|
83
|
-
this.flushReason = reason;
|
|
84
96
|
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { display, includes, each, addEventListener } from '@cloudcare/browser-core';
|
|
2
|
-
import {
|
|
2
|
+
import { workerString } from '@cloudcare/browser-worker/string';
|
|
3
|
+
var workerURL;
|
|
4
|
+
export function createDeflateWorker() {
|
|
5
|
+
// Lazily compute the worker URL to allow importing the SDK in NodeJS
|
|
6
|
+
if (!workerURL) {
|
|
7
|
+
workerURL = URL.createObjectURL(new Blob([workerString]));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return new Worker(workerURL);
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* In order to be sure that the worker is correctly working, we need a round trip of
|
|
5
14
|
* initialization messages, making the creation asynchronous.
|
|
@@ -69,9 +78,9 @@ export function doStartDeflateWorker(createDeflateWorkerImpl) {
|
|
|
69
78
|
var data = event.data;
|
|
70
79
|
|
|
71
80
|
if (data.type === 'errored') {
|
|
72
|
-
onError(data.error);
|
|
81
|
+
onError(data.error, data.streamId);
|
|
73
82
|
} else if (data.type === 'initialized') {
|
|
74
|
-
onInitialized(worker);
|
|
83
|
+
onInitialized(worker, data.version);
|
|
75
84
|
}
|
|
76
85
|
});
|
|
77
86
|
worker.postMessage({
|
|
@@ -83,23 +92,24 @@ export function doStartDeflateWorker(createDeflateWorkerImpl) {
|
|
|
83
92
|
}
|
|
84
93
|
}
|
|
85
94
|
|
|
86
|
-
function onInitialized(worker) {
|
|
95
|
+
function onInitialized(worker, version) {
|
|
87
96
|
if (state.status === DeflateWorkerStatus.Loading) {
|
|
88
97
|
each(state.callbacks, function (callback) {
|
|
89
98
|
callback(worker);
|
|
90
99
|
});
|
|
91
100
|
state = {
|
|
92
101
|
status: DeflateWorkerStatus.Initialized,
|
|
93
|
-
worker: worker
|
|
102
|
+
worker: worker,
|
|
103
|
+
version: version
|
|
94
104
|
};
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
function onError(error) {
|
|
108
|
+
function onError(error, streamId) {
|
|
99
109
|
if (state.status === DeflateWorkerStatus.Loading) {
|
|
100
110
|
display.error('Session Replay recording failed to start: an error occurred while creating the Worker:', error);
|
|
101
111
|
|
|
102
|
-
if (error instanceof Event || error instanceof Error &&
|
|
112
|
+
if (error instanceof Event || error instanceof Error && isMessageCspRelated(error.message)) {
|
|
103
113
|
display.error('Please make sure CSP is correctly configured !!!');
|
|
104
114
|
}
|
|
105
115
|
|
|
@@ -110,4 +120,9 @@ function onError(error) {
|
|
|
110
120
|
status: DeflateWorkerStatus.Error
|
|
111
121
|
};
|
|
112
122
|
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isMessageCspRelated(message) {
|
|
126
|
+
return includes(message, 'Content Security Policy') || // Related to `require-trusted-types-for` CSP: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-trusted-types-for
|
|
127
|
+
includes(message, "requires 'TrustedScriptURL'");
|
|
113
128
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cssEscape } from '@cloudcare/browser-core';
|
|
2
2
|
import { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './getActionNameFromElement';
|
|
3
3
|
/**
|
|
4
4
|
* Stable attributes are attributes that are commonly used to identify parts of a UI (ex:
|
|
@@ -25,7 +25,7 @@ export function doStartErrorCollection(lifeCycle, foregroundContexts) {
|
|
|
25
25
|
var error = providedError.error;
|
|
26
26
|
var stackTrace = error instanceof Error ? computeStackTrace(error) : undefined;
|
|
27
27
|
var rawError = computeRawError({
|
|
28
|
-
stackTrace,
|
|
28
|
+
stackTrace: stackTrace,
|
|
29
29
|
originalError: error,
|
|
30
30
|
handlingStack: providedError.handlingStack,
|
|
31
31
|
startClocks: providedError.startClocks,
|
|
@@ -97,9 +97,8 @@ function processResourceEntry(entry) {
|
|
|
97
97
|
function computePerformanceEntryMetrics(timing) {
|
|
98
98
|
return {
|
|
99
99
|
resource: extend2Lev({}, {
|
|
100
|
-
duration: computePerformanceResourceDuration(timing)
|
|
101
|
-
|
|
102
|
-
}, computePerformanceResourceDetails(timing))
|
|
100
|
+
duration: computePerformanceResourceDuration(timing)
|
|
101
|
+
}, computeSize(timing), computePerformanceResourceDetails(timing))
|
|
103
102
|
};
|
|
104
103
|
}
|
|
105
104
|
|
|
@@ -190,6 +190,11 @@ export function computePerformanceResourceDetails(entry) {
|
|
|
190
190
|
if (hasRedirection(entry)) {
|
|
191
191
|
details.redirect = msToNs(redirectEnd - redirectStart);
|
|
192
192
|
details.redirectTime = formatTiming(startTime, redirectStart, redirectEnd);
|
|
193
|
+
} // renderBlockstatus
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if (entry.renderBlockingStatus) {
|
|
197
|
+
details.renderBlockingStatus = entry.renderBlockingStatus;
|
|
193
198
|
}
|
|
194
199
|
|
|
195
200
|
return details;
|
|
@@ -262,7 +267,10 @@ function formatTiming(origin, start, end) {
|
|
|
262
267
|
export function computeSize(entry) {
|
|
263
268
|
// Make sure a request actually occurred
|
|
264
269
|
if (entry.startTime < entry.responseStart) {
|
|
265
|
-
return
|
|
270
|
+
return {
|
|
271
|
+
size: entry.decodedBodySize,
|
|
272
|
+
encodeSize: entry.encodedBodySize
|
|
273
|
+
};
|
|
266
274
|
}
|
|
267
275
|
|
|
268
276
|
return undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { addEventListeners, elapsed, extend, DOM_EVENT, find, findLast, LifeCycleEventType, ONE_MINUTE, setTimeout, relativeNow } from '@cloudcare/browser-core';
|
|
2
|
-
import { trackFirstHidden } from './trackFirstHidden';
|
|
2
|
+
import { trackFirstHidden } from './trackFirstHidden';
|
|
3
|
+
import { getSelectorFromElement } from '../actions/getSelectorsFromElement'; // Discard LCP and FCP timings above a certain delay to avoid incorrect data
|
|
3
4
|
// It happens in some cases like sleep mode or some browser implementations
|
|
4
5
|
|
|
5
6
|
export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE;
|
|
@@ -13,9 +14,15 @@ export var TIMING_MAXIMUM_DELAY = 10 * ONE_MINUTE;
|
|
|
13
14
|
export var KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE;
|
|
14
15
|
export function trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpdate) {
|
|
15
16
|
var timings = {};
|
|
17
|
+
var timingsElementSelector = {};
|
|
16
18
|
|
|
17
|
-
function setTimings(newTimings) {
|
|
19
|
+
function setTimings(newTimings, timingSelectors) {
|
|
18
20
|
timings = extend(timings, newTimings);
|
|
21
|
+
|
|
22
|
+
if (timingSelectors) {
|
|
23
|
+
timingsElementSelector = extend(timingsElementSelector, timingSelectors);
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
scheduleViewUpdate();
|
|
20
27
|
}
|
|
21
28
|
|
|
@@ -34,10 +41,12 @@ export function trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpd
|
|
|
34
41
|
|
|
35
42
|
var stopFCPTracking = _trackFirstContentfulPaintTiming.stop;
|
|
36
43
|
|
|
37
|
-
var _trackLargestContentfulPaintTiming = trackLargestContentfulPaintTiming(lifeCycle, window, function (largestContentfulPaint) {
|
|
44
|
+
var _trackLargestContentfulPaintTiming = trackLargestContentfulPaintTiming(lifeCycle, window, function (largestContentfulPaint, largestContentfulPaintElement) {
|
|
38
45
|
setTimings({
|
|
39
46
|
largestContentfulPaint: largestContentfulPaint
|
|
40
|
-
}
|
|
47
|
+
}, largestContentfulPaintElement ? {
|
|
48
|
+
largestContentfulPaint: getSelectorFromElement(largestContentfulPaintElement)
|
|
49
|
+
} : undefined);
|
|
41
50
|
});
|
|
42
51
|
|
|
43
52
|
var stopLCPTracking = _trackLargestContentfulPaintTiming.stop;
|
|
@@ -61,6 +70,7 @@ export function trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpd
|
|
|
61
70
|
return {
|
|
62
71
|
stop: stop,
|
|
63
72
|
timings: timings,
|
|
73
|
+
timingsElementSelector: timingsElementSelector,
|
|
64
74
|
scheduleStop: function scheduleStop() {
|
|
65
75
|
setTimeout(stop, KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY);
|
|
66
76
|
}
|
|
@@ -139,7 +149,7 @@ export function trackLargestContentfulPaintTiming(lifeCycle, emitter, callback)
|
|
|
139
149
|
});
|
|
140
150
|
|
|
141
151
|
if (lcpEntry) {
|
|
142
|
-
callback(lcpEntry.startTime);
|
|
152
|
+
callback(lcpEntry.startTime, lcpEntry.element);
|
|
143
153
|
}
|
|
144
154
|
});
|
|
145
155
|
var unsubscribeLifeCycle = subscribe.unsubscribe;
|
|
@@ -125,6 +125,7 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
|
|
|
125
125
|
|
|
126
126
|
var scheduleStopInitialViewTimingsTracking = _trackInitialViewTimings.scheduleStop;
|
|
127
127
|
var timings = _trackInitialViewTimings.timings;
|
|
128
|
+
var timingsElementSelector = _trackInitialViewTimings.timingsElementSelector;
|
|
128
129
|
|
|
129
130
|
var _trackViewEventCounts = trackViewEventCounts(lifeCycle, id, scheduleViewUpdate);
|
|
130
131
|
|
|
@@ -150,6 +151,7 @@ function newView(lifeCycle, domMutationObservable, configuration, initialLocatio
|
|
|
150
151
|
location: location,
|
|
151
152
|
startClocks: startClocks,
|
|
152
153
|
timings: timings,
|
|
154
|
+
timingsElementSelector: timingsElementSelector,
|
|
153
155
|
duration: elapsed(startClocks.timeStamp, currentEnd),
|
|
154
156
|
isActive: endClocks === undefined,
|
|
155
157
|
sessionIsActive: sessionIsActive,
|
|
@@ -86,6 +86,7 @@ function processViewUpdate(view, foregroundContexts, recorderApi) {
|
|
|
86
86
|
is_active: view.isActive,
|
|
87
87
|
name: view.name,
|
|
88
88
|
largest_contentful_paint: toServerDuration(view.timings.largestContentfulPaint),
|
|
89
|
+
largest_contentful_paint_element_selector: view.timingsElementSelector.largestContentfulPaint,
|
|
89
90
|
load_event: toServerDuration(view.timings.loadEvent),
|
|
90
91
|
loading_time: discardNegativeDuration(toServerDuration(view.loadingTime)),
|
|
91
92
|
loading_type: view.loadingType,
|
|
@@ -26,11 +26,10 @@ TraceIdentifier.prototype = {
|
|
|
26
26
|
/**
|
|
27
27
|
* Format used by OTel headers
|
|
28
28
|
*/
|
|
29
|
-
toPaddedHexadecimalString() {
|
|
29
|
+
toPaddedHexadecimalString: function toPaddedHexadecimalString() {
|
|
30
30
|
var traceId = this.toString(16);
|
|
31
31
|
return Array(17 - traceId.length).join('0') + traceId;
|
|
32
32
|
},
|
|
33
|
-
|
|
34
33
|
readInt32: function readInt32(offset) {
|
|
35
34
|
return this.buffer[offset] * 16777216 + (this.buffer[offset + 1] << 16) + (this.buffer[offset + 2] << 8) + this.buffer[offset + 3];
|
|
36
35
|
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/browser-rum",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.23",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@cloudcare/browser-core": "
|
|
7
|
+
"@cloudcare/browser-core": "^3.0.23",
|
|
8
|
+
"@cloudcare/browser-worker": "^3.0.23"
|
|
8
9
|
},
|
|
9
10
|
"scripts": {
|
|
10
11
|
"dev": "webpack serve --open --mode=development",
|
|
11
12
|
"build": "run-p build:cjs build:esm build:bundle",
|
|
12
13
|
"build:cjs": "rm -rf cjs && babel --config-file ./babel.cjs.json --out-dir cjs ./src && npm run replace-build-env cjs",
|
|
13
14
|
"build:esm": "rm -rf esm && babel --config-file ./babel.esm.json --out-dir esm ./src && npm run replace-build-env esm",
|
|
14
|
-
"build:bundle": "rm -rf bundle && webpack
|
|
15
|
-
"replace-build-env": "node scripts/replace-build-env.js",
|
|
16
|
-
"publish:oss": "npm run build && node ./scripts/publish-oss.js",
|
|
17
|
-
"publish:oss:test": "npm run build && node ./scripts/publish-oss.js test"
|
|
15
|
+
"build:bundle": "rm -rf bundle && webpack --mode=production",
|
|
16
|
+
"replace-build-env": "node ../../scripts/replace-build-env.js",
|
|
17
|
+
"publish:oss": "npm run build:bundle && node ./scripts/publish-oss.js",
|
|
18
|
+
"publish:oss:test": "npm run build:bundle && node ./scripts/publish-oss.js test"
|
|
18
19
|
},
|
|
19
20
|
"keywords": [
|
|
20
21
|
"dataflux",
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
"license": "MIT",
|
|
30
31
|
"homepage": "https://github.com/CloudCare/dataflux-rum-sdk-javascript/blob/master/packages/rum/README.md",
|
|
31
32
|
"description": "DataFlux RUM Web 端数据指标监控",
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "0c8164fe62fcb3dfeee505c9ca27da49cac54dc5"
|
|
33
34
|
}
|
package/src/boot/buildEnv.js
CHANGED
package/src/boot/recorderApi.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
assign,
|
|
3
|
+
addEventListener,
|
|
4
|
+
concatBuffers
|
|
5
|
+
} from '@cloudcare/browser-core'
|
|
2
6
|
import { RecordType } from '../../../types'
|
|
3
7
|
import * as replayStats from '../replayStats'
|
|
4
|
-
|
|
8
|
+
var STREAM_ID = 1
|
|
5
9
|
var nextId = 0
|
|
6
10
|
export function Segment(
|
|
7
11
|
worker,
|
|
@@ -12,6 +16,7 @@ export function Segment(
|
|
|
12
16
|
onFlushed
|
|
13
17
|
) {
|
|
14
18
|
this.worker = worker
|
|
19
|
+
this.pendingWriteCount = 0
|
|
15
20
|
this.id = nextId++
|
|
16
21
|
var viewId = context.view.id
|
|
17
22
|
|
|
@@ -29,19 +34,28 @@ export function Segment(
|
|
|
29
34
|
)
|
|
30
35
|
replayStats.addSegment(viewId)
|
|
31
36
|
replayStats.addRecord(viewId)
|
|
37
|
+
var rawBytesCount = 0
|
|
38
|
+
var compressedBytesCount = 0
|
|
39
|
+
var compressedData = []
|
|
32
40
|
var _this = this
|
|
33
|
-
var
|
|
41
|
+
var wokerListener = addEventListener(worker, 'message', function (params) {
|
|
34
42
|
var data = params.data
|
|
35
|
-
if (data.type
|
|
43
|
+
if (data.type !== 'wrote') {
|
|
36
44
|
return
|
|
37
45
|
}
|
|
46
|
+
|
|
38
47
|
if (data.id === _this.id) {
|
|
48
|
+
_this.pendingWriteCount -= 1
|
|
39
49
|
replayStats.addWroteData(viewId, data.additionalBytesCount)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
rawBytesCount += data.additionalBytesCount
|
|
51
|
+
compressedBytesCount += data.result.length
|
|
52
|
+
compressedData.push(data.result)
|
|
53
|
+
if (_this.flushReason && _this.pendingWriteCount === 0) {
|
|
54
|
+
compressedData.push(data.trailer)
|
|
55
|
+
onFlushed(concatBuffers(compressedData), rawBytesCount)
|
|
56
|
+
removeMessageListener()
|
|
43
57
|
} else {
|
|
44
|
-
onWrote(
|
|
58
|
+
onWrote(compressedBytesCount)
|
|
45
59
|
}
|
|
46
60
|
} else if (data.id > _this.id) {
|
|
47
61
|
// Messages should be received in the same order as they are sent, so if we receive a
|
|
@@ -52,15 +66,13 @@ export function Segment(
|
|
|
52
66
|
// should already have been removed. But if something goes wrong and we didn't receive a
|
|
53
67
|
// "flush" response, remove the listener to avoid any leak, and send a monitor message to
|
|
54
68
|
// help investigate the issue.
|
|
55
|
-
|
|
69
|
+
removeMessageListener()
|
|
56
70
|
}
|
|
57
|
-
}
|
|
58
|
-
worker.addEventListener('message', listener)
|
|
59
|
-
this.worker.postMessage({
|
|
60
|
-
data: '{"records":[' + JSON.stringify(initialRecord),
|
|
61
|
-
id: this.id,
|
|
62
|
-
action: 'write'
|
|
63
71
|
})
|
|
72
|
+
var removeMessageListener = wokerListener.stop
|
|
73
|
+
// worker.addEventListener('message', listener)
|
|
74
|
+
|
|
75
|
+
this.write('{"records":[' + JSON.stringify(initialRecord))
|
|
64
76
|
}
|
|
65
77
|
Segment.prototype.addRecord = function (record) {
|
|
66
78
|
this.metadata.start = Math.min(this.metadata.start, record.timestamp)
|
|
@@ -70,17 +82,24 @@ Segment.prototype.addRecord = function (record) {
|
|
|
70
82
|
if (!this.metadata.has_full_snapshot) {
|
|
71
83
|
this.metadata.has_full_snapshot = record.type === RecordType.FullSnapshot
|
|
72
84
|
}
|
|
85
|
+
this.write(',' + JSON.stringify(record))
|
|
86
|
+
}
|
|
87
|
+
Segment.prototype.flush = function (reason) {
|
|
88
|
+
this.write('],' + JSON.stringify(this.metadata).slice(1) + '\n')
|
|
89
|
+
|
|
73
90
|
this.worker.postMessage({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
action: 'write'
|
|
91
|
+
action: 'reset',
|
|
92
|
+
streamId: STREAM_ID
|
|
77
93
|
})
|
|
94
|
+
this.flushReason = reason
|
|
78
95
|
}
|
|
79
|
-
|
|
96
|
+
|
|
97
|
+
Segment.prototype.write = function (data) {
|
|
98
|
+
this.pendingWriteCount += 1
|
|
80
99
|
this.worker.postMessage({
|
|
81
|
-
data:
|
|
100
|
+
data: data,
|
|
82
101
|
id: this.id,
|
|
83
|
-
|
|
102
|
+
streamId: STREAM_ID,
|
|
103
|
+
action: 'write'
|
|
84
104
|
})
|
|
85
|
-
this.flushReason = reason
|
|
86
105
|
}
|