@cloudcare/browser-rum 2.2.15 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/dataflux-rum.js +1 -1
- package/cjs/boot/buildEnv.js +1 -1
- package/cjs/boot/recorderApi.js +161 -0
- package/cjs/boot/rum.entry.js +6 -1
- package/cjs/boot/rum.js +15 -5
- package/cjs/boot/rumPublicApi.js +8 -4
- package/cjs/boot/startRecording.js +55 -0
- package/cjs/constants.js +52 -0
- package/cjs/domain/assembly.js +1 -7
- package/cjs/domain/configuration.js +3 -2
- package/cjs/domain/contexts/foregroundContexts.js +138 -0
- package/cjs/domain/contexts/internalContext.js +1 -1
- package/cjs/domain/contexts/urlContexts.js +9 -2
- package/cjs/domain/domMutationCollection.js +4 -5
- package/cjs/domain/initViewportObservable.js +52 -0
- package/cjs/domain/locationChangeObservable.js +12 -26
- package/cjs/domain/performanceCollection.js +2 -13
- package/cjs/domain/replay/record/elementsScrollPositions.js +27 -0
- package/cjs/domain/replay/record/index.js +41 -0
- package/cjs/domain/replay/record/mutationBatch.js +58 -0
- package/cjs/domain/replay/record/mutationObserver.js +388 -0
- package/cjs/domain/replay/record/observers.js +470 -0
- package/cjs/domain/replay/record/privacy.js +256 -0
- package/cjs/domain/replay/record/record.js +174 -0
- package/cjs/domain/replay/record/serializationUtils.js +137 -0
- package/cjs/domain/replay/record/serialize.js +488 -0
- package/cjs/domain/replay/record/shadowRootsController.js +61 -0
- package/cjs/domain/replay/record/utils.js +53 -0
- package/cjs/domain/replay/record/viewports.js +104 -0
- package/cjs/domain/replay/replayStats.js +83 -0
- package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +43 -0
- package/cjs/domain/replay/segmentCollection/deflateWorker.js +4400 -0
- package/cjs/domain/replay/segmentCollection/index.js +33 -0
- package/cjs/domain/replay/segmentCollection/segment.js +101 -0
- package/cjs/domain/replay/segmentCollection/segmentCollection.js +179 -0
- package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +127 -0
- package/cjs/domain/requestCollection.js +35 -17
- package/cjs/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/cjs/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +8 -6
- package/cjs/domain/rumEventsCollection/actions/getSelectorsFromElement.js +111 -75
- package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +94 -54
- package/cjs/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +45 -0
- package/cjs/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/cjs/domain/rumEventsCollection/view/trackViews.js +21 -18
- package/cjs/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/cjs/domain/rumSessionManager.js +6 -3
- package/cjs/domain/tracing/getDocumentTraceId.js +2 -10
- package/cjs/domain/trackEventCounts.js +10 -2
- package/cjs/domain/waitPageActivityEnd.js +5 -1
- package/cjs/transport/startRumBatch.js +5 -7
- package/cjs/types/index.js +18 -0
- package/cjs/types/sessionReplayConstants.js +56 -0
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/recorderApi.js +149 -0
- package/esm/boot/rum.entry.js +4 -1
- package/esm/boot/rum.js +15 -6
- package/esm/boot/rumPublicApi.js +8 -4
- package/esm/boot/startRecording.js +44 -0
- package/esm/constants.js +31 -0
- package/esm/domain/assembly.js +1 -7
- package/esm/domain/configuration.js +4 -3
- package/esm/domain/contexts/foregroundContexts.js +122 -0
- package/esm/domain/contexts/internalContext.js +1 -1
- package/esm/domain/contexts/urlContexts.js +10 -3
- package/esm/domain/domMutationCollection.js +5 -6
- package/esm/domain/initViewportObservable.js +39 -0
- package/esm/domain/locationChangeObservable.js +13 -27
- package/esm/domain/performanceCollection.js +1 -12
- package/esm/domain/replay/record/elementsScrollPositions.js +20 -0
- package/esm/domain/replay/record/index.js +3 -0
- package/esm/domain/replay/record/mutationBatch.js +35 -0
- package/esm/domain/replay/record/mutationObserver.js +336 -0
- package/esm/domain/replay/record/observers.js +454 -0
- package/esm/domain/replay/record/privacy.js +233 -0
- package/esm/domain/replay/record/record.js +158 -0
- package/esm/domain/replay/record/serializationUtils.js +107 -0
- package/esm/domain/replay/record/serialize.js +461 -0
- package/esm/domain/replay/record/shadowRootsController.js +49 -0
- package/esm/domain/replay/record/utils.js +38 -0
- package/esm/domain/replay/record/viewports.js +87 -0
- package/esm/domain/replay/replayStats.js +64 -0
- package/esm/domain/replay/segmentCollection/buildReplayPayload.js +31 -0
- package/esm/domain/replay/segmentCollection/deflateWorker.js +4393 -0
- package/esm/domain/replay/segmentCollection/index.js +3 -0
- package/esm/domain/replay/segmentCollection/segment.js +84 -0
- package/esm/domain/replay/segmentCollection/segmentCollection.js +158 -0
- package/esm/domain/replay/segmentCollection/startDeflateWorker.js +114 -0
- package/esm/domain/requestCollection.js +36 -18
- package/esm/domain/rumEventsCollection/actions/actionCollection.js +12 -4
- package/esm/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/esm/domain/rumEventsCollection/actions/computeFrustration.js +6 -5
- package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +6 -6
- package/esm/domain/rumEventsCollection/actions/getSelectorsFromElement.js +105 -74
- package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +22 -28
- package/esm/domain/rumEventsCollection/actions/trackClickActions.js +99 -59
- package/esm/domain/rumEventsCollection/error/errorCollection.js +13 -5
- package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +33 -0
- package/esm/domain/rumEventsCollection/view/trackViewMetrics.js +1 -18
- package/esm/domain/rumEventsCollection/view/trackViews.js +21 -19
- package/esm/domain/rumEventsCollection/view/viewCollection.js +12 -9
- package/esm/domain/rumSessionManager.js +6 -3
- package/esm/domain/tracing/getDocumentTraceId.js +1 -9
- package/esm/domain/trackEventCounts.js +10 -2
- package/esm/domain/waitPageActivityEnd.js +5 -1
- package/esm/transport/startRumBatch.js +5 -7
- package/esm/types/index.js +1 -0
- package/esm/types/sessionReplayConstants.js +45 -0
- package/package.json +3 -3
- package/src/boot/recorderApi.js +166 -0
- package/src/boot/rum.entry.js +4 -1
- package/src/boot/rum.js +38 -10
- package/src/boot/rumPublicApi.js +13 -3
- package/src/boot/startRecording.js +77 -0
- package/src/constants.js +37 -0
- package/src/domain/assembly.js +1 -6
- package/src/domain/configuration.js +10 -2
- package/src/domain/contexts/foregroundContexts.js +140 -0
- package/src/domain/contexts/internalContext.js +10 -4
- package/src/domain/contexts/urlContexts.js +29 -15
- package/src/domain/domMutationCollection.js +14 -6
- package/src/domain/initViewportObservable.js +46 -0
- package/src/domain/locationChangeObservable.js +17 -25
- package/src/domain/performanceCollection.js +42 -42
- package/src/domain/replay/record/elementsScrollPositions.js +22 -0
- package/src/domain/replay/record/index.js +7 -0
- package/src/domain/replay/record/mutationBatch.js +38 -0
- package/src/domain/replay/record/mutationObserver.js +403 -0
- package/src/domain/replay/record/observers.js +565 -0
- package/src/domain/replay/record/privacy.js +304 -0
- package/src/domain/replay/record/record.js +158 -0
- package/src/domain/replay/record/serializationUtils.js +134 -0
- package/src/domain/replay/record/serialize.js +497 -0
- package/src/domain/replay/record/shadowRootsController.js +58 -0
- package/src/domain/replay/record/utils.js +44 -0
- package/src/domain/replay/record/viewports.js +89 -0
- package/src/domain/replay/replayStats.js +67 -0
- package/src/domain/replay/segmentCollection/buildReplayPayload.js +34 -0
- package/src/domain/replay/segmentCollection/deflateWorker.js +4584 -0
- package/src/domain/replay/segmentCollection/index.js +6 -0
- package/src/domain/replay/segmentCollection/segment.js +86 -0
- package/src/domain/replay/segmentCollection/segmentCollection.js +205 -0
- package/src/domain/replay/segmentCollection/startDeflateWorker.js +102 -0
- package/src/domain/requestCollection.js +64 -28
- package/src/domain/rumEventsCollection/actions/actionCollection.js +11 -4
- package/src/domain/rumEventsCollection/actions/clickChain.js +3 -3
- package/src/domain/rumEventsCollection/actions/computeFrustration.js +7 -4
- package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +9 -6
- package/src/domain/rumEventsCollection/actions/getSelectorsFromElement.js +130 -108
- package/src/domain/rumEventsCollection/actions/listenActionEvents.js +26 -27
- package/src/domain/rumEventsCollection/actions/trackClickActions.js +162 -92
- package/src/domain/rumEventsCollection/error/errorCollection.js +11 -5
- package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +38 -0
- package/src/domain/rumEventsCollection/view/trackViewMetrics.js +1 -19
- package/src/domain/rumEventsCollection/view/trackViews.js +98 -68
- package/src/domain/rumEventsCollection/view/viewCollection.js +15 -7
- package/src/domain/rumSessionManager.js +33 -19
- package/src/domain/tracing/getDocumentTraceId.js +6 -9
- package/src/domain/trackEventCounts.js +10 -4
- package/src/domain/waitPageActivityEnd.js +4 -1
- package/src/transport/startRumBatch.js +29 -24
- package/src/types/index.js +1 -0
- package/src/types/sessionReplayConstants.js +49 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getRecordIdForEvent = getRecordIdForEvent;
|
|
7
|
+
exports.initFrustrationObserver = initFrustrationObserver;
|
|
8
|
+
exports.initInputObserver = initInputObserver;
|
|
9
|
+
exports.initMouseInteractionObserver = initMouseInteractionObserver;
|
|
10
|
+
exports.initMoveObserver = initMoveObserver;
|
|
11
|
+
exports.initMutationObserver = initMutationObserver;
|
|
12
|
+
exports.initObservers = initObservers;
|
|
13
|
+
exports.initStyleSheetObserver = initStyleSheetObserver;
|
|
14
|
+
|
|
15
|
+
var _browserCore = require("@cloudcare/browser-core");
|
|
16
|
+
|
|
17
|
+
var _initViewportObservable = require("../../initViewportObservable");
|
|
18
|
+
|
|
19
|
+
var _constants = require("../../../constants");
|
|
20
|
+
|
|
21
|
+
var _types = require("../../../types");
|
|
22
|
+
|
|
23
|
+
var _privacy = require("./privacy");
|
|
24
|
+
|
|
25
|
+
var _serializationUtils = require("./serializationUtils");
|
|
26
|
+
|
|
27
|
+
var _utils = require("./utils");
|
|
28
|
+
|
|
29
|
+
var _mutationObserver = require("./mutationObserver");
|
|
30
|
+
|
|
31
|
+
var _viewports = require("./viewports");
|
|
32
|
+
|
|
33
|
+
var _eventTypeToMouseInte;
|
|
34
|
+
|
|
35
|
+
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; }
|
|
36
|
+
|
|
37
|
+
var MOUSE_MOVE_OBSERVER_THRESHOLD = 50;
|
|
38
|
+
var SCROLL_OBSERVER_THRESHOLD = 100;
|
|
39
|
+
var VISUAL_VIEWPORT_OBSERVER_THRESHOLD = 200;
|
|
40
|
+
var recordIds = new WeakMap();
|
|
41
|
+
var nextId = 1;
|
|
42
|
+
|
|
43
|
+
function getRecordIdForEvent(event) {
|
|
44
|
+
if (!recordIds.has(event)) {
|
|
45
|
+
recordIds.set(event, nextId++);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return recordIds.get(event);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function initObservers(o) {
|
|
52
|
+
var mutationHandler = initMutationObserver(o.mutationCb, o.configuration, o.shadowRootsController);
|
|
53
|
+
var mousemoveHandler = initMoveObserver(o.mousemoveCb);
|
|
54
|
+
var mouseInteractionHandler = initMouseInteractionObserver(o.mouseInteractionCb, o.configuration.defaultPrivacyLevel);
|
|
55
|
+
var scrollHandler = initScrollObserver(o.scrollCb, o.configuration.defaultPrivacyLevel, o.elementsScrollPositions);
|
|
56
|
+
var viewportResizeHandler = initViewportResizeObserver(o.viewportResizeCb);
|
|
57
|
+
var inputHandler = initInputObserver(o.inputCb, o.configuration.defaultPrivacyLevel);
|
|
58
|
+
var mediaInteractionHandler = initMediaInteractionObserver(o.mediaInteractionCb, o.configuration.defaultPrivacyLevel);
|
|
59
|
+
var styleSheetObserver = initStyleSheetObserver(o.styleSheetCb);
|
|
60
|
+
var focusHandler = initFocusObserver(o.focusCb);
|
|
61
|
+
var visualViewportResizeHandler = initVisualViewportResizeObserver(o.visualViewportResizeCb);
|
|
62
|
+
var frustrationHandler = initFrustrationObserver(o.lifeCycle, o.frustrationCb);
|
|
63
|
+
return {
|
|
64
|
+
flush: function flush() {
|
|
65
|
+
mutationHandler.flush();
|
|
66
|
+
},
|
|
67
|
+
stop: function stop() {
|
|
68
|
+
mutationHandler.stop();
|
|
69
|
+
mousemoveHandler();
|
|
70
|
+
mouseInteractionHandler();
|
|
71
|
+
scrollHandler();
|
|
72
|
+
viewportResizeHandler();
|
|
73
|
+
inputHandler();
|
|
74
|
+
mediaInteractionHandler();
|
|
75
|
+
styleSheetObserver();
|
|
76
|
+
focusHandler();
|
|
77
|
+
visualViewportResizeHandler();
|
|
78
|
+
frustrationHandler();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function initMutationObserver(cb, configuration, shadowRootsController) {
|
|
84
|
+
return (0, _mutationObserver.startMutationObserver)(cb, configuration, shadowRootsController, document);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function initMoveObserver(cb) {
|
|
88
|
+
var _updatePosition = (0, _browserCore.throttle)(function (event) {
|
|
89
|
+
var target = getEventTarget(event);
|
|
90
|
+
|
|
91
|
+
if ((0, _serializationUtils.hasSerializedNode)(target)) {
|
|
92
|
+
var coordinates = tryToComputeCoordinates(event);
|
|
93
|
+
|
|
94
|
+
if (!coordinates) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var position = {
|
|
99
|
+
id: (0, _serializationUtils.getSerializedNodeId)(target),
|
|
100
|
+
timeOffset: 0,
|
|
101
|
+
x: coordinates.x,
|
|
102
|
+
y: coordinates.y
|
|
103
|
+
};
|
|
104
|
+
cb([position], (0, _utils.isTouchEvent)(event) ? _types.IncrementalSource.TouchMove : _types.IncrementalSource.MouseMove);
|
|
105
|
+
}
|
|
106
|
+
}, MOUSE_MOVE_OBSERVER_THRESHOLD, {
|
|
107
|
+
trailing: false
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return (0, _browserCore.addEventListeners)(document, [_browserCore.DOM_EVENT.MOUSE_MOVE, _browserCore.DOM_EVENT.TOUCH_MOVE], _updatePosition.throttled, {
|
|
111
|
+
capture: true,
|
|
112
|
+
passive: true
|
|
113
|
+
}).stop;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var eventTypeToMouseInteraction = (_eventTypeToMouseInte = {}, _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.POINTER_UP, _types.MouseInteractionType.MouseUp), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.MOUSE_DOWN, _types.MouseInteractionType.MouseDown), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.CLICK, _types.MouseInteractionType.Click), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.CONTEXT_MENU, _types.MouseInteractionType.ContextMenu), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.DBL_CLICK, _types.MouseInteractionType.DblClick), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.FOCUS, _types.MouseInteractionType.Focus), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.BLUR, _types.MouseInteractionType.Blur), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.TOUCH_START, _types.MouseInteractionType.TouchStart), _defineProperty(_eventTypeToMouseInte, _browserCore.DOM_EVENT.TOUCH_END, _types.MouseInteractionType.TouchEnd), _eventTypeToMouseInte);
|
|
117
|
+
|
|
118
|
+
function initMouseInteractionObserver(cb, defaultPrivacyLevel) {
|
|
119
|
+
var handler = function handler(event) {
|
|
120
|
+
var target = getEventTarget(event);
|
|
121
|
+
|
|
122
|
+
if ((0, _privacy.getNodePrivacyLevel)(target, defaultPrivacyLevel) === _constants.NodePrivacyLevel.HIDDEN || !(0, _serializationUtils.hasSerializedNode)(target)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
var id = (0, _serializationUtils.getSerializedNodeId)(target);
|
|
127
|
+
var type = eventTypeToMouseInteraction[event.type];
|
|
128
|
+
var interaction;
|
|
129
|
+
|
|
130
|
+
if (type !== _types.MouseInteractionType.Blur && type !== _types.MouseInteractionType.Focus) {
|
|
131
|
+
var coordinates = tryToComputeCoordinates(event);
|
|
132
|
+
|
|
133
|
+
if (!coordinates) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interaction = {
|
|
138
|
+
id: id,
|
|
139
|
+
type: type,
|
|
140
|
+
x: coordinates.x,
|
|
141
|
+
y: coordinates.y
|
|
142
|
+
};
|
|
143
|
+
} else {
|
|
144
|
+
interaction = {
|
|
145
|
+
id: id,
|
|
146
|
+
type: type
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
var record = (0, _browserCore.assign)({
|
|
151
|
+
id: getRecordIdForEvent(event)
|
|
152
|
+
}, (0, _utils.assembleIncrementalSnapshot)(_types.IncrementalSource.MouseInteraction, interaction));
|
|
153
|
+
cb(record);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return (0, _browserCore.addEventListeners)(document, Object.keys(eventTypeToMouseInteraction), handler, {
|
|
157
|
+
capture: true,
|
|
158
|
+
passive: true
|
|
159
|
+
}).stop;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function tryToComputeCoordinates(event) {
|
|
163
|
+
var _event = (0, _utils.isTouchEvent)(event) ? event.changedTouches[0] : event;
|
|
164
|
+
|
|
165
|
+
var x = _event.clientX;
|
|
166
|
+
var y = _event.clientY;
|
|
167
|
+
|
|
168
|
+
if (window.visualViewport) {
|
|
169
|
+
var _convertMouseEventToLayoutCoordinates = (0, _viewports.convertMouseEventToLayoutCoordinates)(x, y);
|
|
170
|
+
|
|
171
|
+
x = _convertMouseEventToLayoutCoordinates.visualViewportX;
|
|
172
|
+
y = _convertMouseEventToLayoutCoordinates.visualViewportY;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
x: x,
|
|
181
|
+
y: y
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function initScrollObserver(cb, defaultPrivacyLevel, elementsScrollPositions) {
|
|
186
|
+
var _updatePosition = (0, _browserCore.throttle)(function (event) {
|
|
187
|
+
var target = getEventTarget(event);
|
|
188
|
+
|
|
189
|
+
if (!target || (0, _privacy.getNodePrivacyLevel)(target, defaultPrivacyLevel) === _constants.NodePrivacyLevel.HIDDEN || !(0, _serializationUtils.hasSerializedNode)(target)) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
var id = (0, _serializationUtils.getSerializedNodeId)(target);
|
|
194
|
+
var scrollPositions = target === document ? {
|
|
195
|
+
scrollTop: (0, _viewports.getScrollY)(),
|
|
196
|
+
scrollLeft: (0, _viewports.getScrollX)()
|
|
197
|
+
} : {
|
|
198
|
+
scrollTop: Math.round(target.scrollTop),
|
|
199
|
+
scrollLeft: Math.round(target.scrollLeft)
|
|
200
|
+
};
|
|
201
|
+
elementsScrollPositions.set(target, scrollPositions);
|
|
202
|
+
cb({
|
|
203
|
+
id: id,
|
|
204
|
+
x: scrollPositions.scrollLeft,
|
|
205
|
+
y: scrollPositions.scrollTop
|
|
206
|
+
});
|
|
207
|
+
}, SCROLL_OBSERVER_THRESHOLD);
|
|
208
|
+
|
|
209
|
+
return (0, _browserCore.addEventListener)(document, _browserCore.DOM_EVENT.SCROLL, _updatePosition.throttled, {
|
|
210
|
+
capture: true,
|
|
211
|
+
passive: true
|
|
212
|
+
}).stop;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function initViewportResizeObserver(cb) {
|
|
216
|
+
return (0, _initViewportObservable.initViewportObservable)().subscribe(cb).unsubscribe;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function initInputObserver(cb, defaultPrivacyLevel, options) {
|
|
220
|
+
var domEvents = options && options.domEvents || [_browserCore.DOM_EVENT.INPUT, _browserCore.DOM_EVENT.CHANGE];
|
|
221
|
+
var target = options && options.target || document;
|
|
222
|
+
var lastInputStateMap = new WeakMap();
|
|
223
|
+
|
|
224
|
+
function onElementChange(target) {
|
|
225
|
+
var nodePrivacyLevel = (0, _privacy.getNodePrivacyLevel)(target, defaultPrivacyLevel);
|
|
226
|
+
|
|
227
|
+
if (nodePrivacyLevel === _constants.NodePrivacyLevel.HIDDEN) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
var type = target.type;
|
|
232
|
+
var inputState;
|
|
233
|
+
|
|
234
|
+
if (type === 'radio' || type === 'checkbox') {
|
|
235
|
+
if ((0, _privacy.shouldMaskNode)(target, nodePrivacyLevel)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
inputState = {
|
|
240
|
+
isChecked: target.checked
|
|
241
|
+
};
|
|
242
|
+
} else {
|
|
243
|
+
var value = (0, _serializationUtils.getElementInputValue)(target, nodePrivacyLevel);
|
|
244
|
+
|
|
245
|
+
if (value === undefined) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
inputState = {
|
|
250
|
+
text: value
|
|
251
|
+
};
|
|
252
|
+
} // Can be multiple changes on the same node within the same batched mutation observation.
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
cbWithDedup(target, inputState); // If a radio was checked, other radios with the same name attribute will be unchecked.
|
|
256
|
+
|
|
257
|
+
var name = target.name;
|
|
258
|
+
|
|
259
|
+
if (type === 'radio' && name && target.checked) {
|
|
260
|
+
(0, _utils.forEach)(document.querySelectorAll("input[type=\"radio\"][name=\"".concat(name, "\"]")), function (el) {
|
|
261
|
+
if (el !== target) {
|
|
262
|
+
// TODO: Consider the privacy implications for various differing input privacy levels
|
|
263
|
+
cbWithDedup(el, {
|
|
264
|
+
isChecked: false
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* There can be multiple changes on the same node within the same batched mutation observation.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
function cbWithDedup(target, inputState) {
|
|
276
|
+
if (!(0, _serializationUtils.hasSerializedNode)(target)) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
var lastInputState = lastInputStateMap.get(target);
|
|
281
|
+
|
|
282
|
+
if (!lastInputState || lastInputState.text !== inputState.text || lastInputState.isChecked !== inputState.isChecked) {
|
|
283
|
+
lastInputStateMap.set(target, inputState);
|
|
284
|
+
cb((0, _browserCore.assign)({
|
|
285
|
+
id: (0, _serializationUtils.getSerializedNodeId)(target)
|
|
286
|
+
}, inputState));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
var _addEventListeners = (0, _browserCore.addEventListeners)(target, domEvents, function (event) {
|
|
291
|
+
var target = getEventTarget(event);
|
|
292
|
+
|
|
293
|
+
if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) {
|
|
294
|
+
onElementChange(target);
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
capture: true,
|
|
298
|
+
passive: true
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
var instrumentationStoppers = [(0, _browserCore.instrumentSetter)(HTMLInputElement.prototype, 'value', onElementChange), (0, _browserCore.instrumentSetter)(HTMLInputElement.prototype, 'checked', onElementChange), (0, _browserCore.instrumentSetter)(HTMLSelectElement.prototype, 'value', onElementChange), (0, _browserCore.instrumentSetter)(HTMLTextAreaElement.prototype, 'value', onElementChange), (0, _browserCore.instrumentSetter)(HTMLSelectElement.prototype, 'selectedIndex', onElementChange)];
|
|
302
|
+
return function () {
|
|
303
|
+
instrumentationStoppers.forEach(function (stopper) {
|
|
304
|
+
stopper.stop();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
_addEventListeners.stop();
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function initStyleSheetObserver(cb) {
|
|
312
|
+
function checkStyleSheetAndCallback(styleSheet, callback) {
|
|
313
|
+
if (styleSheet && (0, _serializationUtils.hasSerializedNode)(styleSheet.ownerNode)) {
|
|
314
|
+
callback((0, _serializationUtils.getSerializedNodeId)(styleSheet.ownerNode));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
var instrumentationStoppers = [(0, _browserCore.instrumentMethodAndCallOriginal)(CSSStyleSheet.prototype, 'insertRule', {
|
|
319
|
+
before: function before(rule, index) {
|
|
320
|
+
checkStyleSheetAndCallback(this, function (id) {
|
|
321
|
+
return cb({
|
|
322
|
+
id: id,
|
|
323
|
+
adds: [{
|
|
324
|
+
rule: rule,
|
|
325
|
+
index: index
|
|
326
|
+
}]
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}), (0, _browserCore.instrumentMethodAndCallOriginal)(CSSStyleSheet.prototype, 'deleteRule', {
|
|
331
|
+
before: function before(index) {
|
|
332
|
+
checkStyleSheetAndCallback(this, function (id) {
|
|
333
|
+
return cb({
|
|
334
|
+
id: id,
|
|
335
|
+
removes: [{
|
|
336
|
+
index: index
|
|
337
|
+
}]
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
})];
|
|
342
|
+
|
|
343
|
+
if (typeof CSSGroupingRule !== 'undefined') {
|
|
344
|
+
instrumentGroupingCSSRuleClass(CSSGroupingRule);
|
|
345
|
+
} else {
|
|
346
|
+
instrumentGroupingCSSRuleClass(CSSMediaRule);
|
|
347
|
+
instrumentGroupingCSSRuleClass(CSSSupportsRule);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function instrumentGroupingCSSRuleClass(cls) {
|
|
351
|
+
instrumentationStoppers.push((0, _browserCore.instrumentMethodAndCallOriginal)(cls.prototype, 'insertRule', {
|
|
352
|
+
before: function before(rule, index) {
|
|
353
|
+
var _this = this;
|
|
354
|
+
|
|
355
|
+
checkStyleSheetAndCallback(this.parentStyleSheet, function (id) {
|
|
356
|
+
var path = (0, _utils.getPathToNestedCSSRule)(_this);
|
|
357
|
+
|
|
358
|
+
if (path) {
|
|
359
|
+
path.push(index || 0);
|
|
360
|
+
cb({
|
|
361
|
+
id: id,
|
|
362
|
+
adds: [{
|
|
363
|
+
rule: rule,
|
|
364
|
+
index: path
|
|
365
|
+
}]
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}), (0, _browserCore.instrumentMethodAndCallOriginal)(cls.prototype, 'deleteRule', {
|
|
371
|
+
before: function before(index) {
|
|
372
|
+
var _this = this;
|
|
373
|
+
|
|
374
|
+
checkStyleSheetAndCallback(this.parentStyleSheet, function (id) {
|
|
375
|
+
var path = (0, _utils.getPathToNestedCSSRule)(_this);
|
|
376
|
+
|
|
377
|
+
if (path) {
|
|
378
|
+
path.push(index);
|
|
379
|
+
cb({
|
|
380
|
+
id: id,
|
|
381
|
+
removes: [{
|
|
382
|
+
index: path
|
|
383
|
+
}]
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return function () {
|
|
392
|
+
instrumentationStoppers.forEach(function (stopper) {
|
|
393
|
+
stopper.stop();
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function initMediaInteractionObserver(mediaInteractionCb, defaultPrivacyLevel) {
|
|
399
|
+
var handler = function handler(event) {
|
|
400
|
+
var target = getEventTarget(event);
|
|
401
|
+
|
|
402
|
+
if (!target || (0, _privacy.getNodePrivacyLevel)(target, defaultPrivacyLevel) === _constants.NodePrivacyLevel.HIDDEN || !(0, _serializationUtils.hasSerializedNode)(target)) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
mediaInteractionCb({
|
|
407
|
+
id: (0, _serializationUtils.getSerializedNodeId)(target),
|
|
408
|
+
type: event.type === _browserCore.DOM_EVENT.PLAY ? _types.MediaInteractionType.Play : _types.MediaInteractionType.Pause
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
return (0, _browserCore.addEventListeners)(document, [_browserCore.DOM_EVENT.PLAY, _browserCore.DOM_EVENT.PAUSE], handler, {
|
|
413
|
+
capture: true,
|
|
414
|
+
passive: true
|
|
415
|
+
}).stop;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function initFocusObserver(focusCb) {
|
|
419
|
+
return (0, _browserCore.addEventListeners)(window, [_browserCore.DOM_EVENT.FOCUS, _browserCore.DOM_EVENT.BLUR], function () {
|
|
420
|
+
focusCb({
|
|
421
|
+
has_focus: document.hasFocus()
|
|
422
|
+
});
|
|
423
|
+
}).stop;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function initVisualViewportResizeObserver(cb) {
|
|
427
|
+
if (!window.visualViewport) {
|
|
428
|
+
return _browserCore.noop;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
var _updateDimension = (0, _browserCore.throttle)(function () {
|
|
432
|
+
cb((0, _viewports.getVisualViewport)());
|
|
433
|
+
}, VISUAL_VIEWPORT_OBSERVER_THRESHOLD, {
|
|
434
|
+
trailing: false
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
var removeListener = (0, _browserCore.addEventListeners)(window.visualViewport, [_browserCore.DOM_EVENT.RESIZE, _browserCore.DOM_EVENT.SCROLL], _updateDimension.throttled, {
|
|
438
|
+
capture: true,
|
|
439
|
+
passive: true
|
|
440
|
+
}).stop;
|
|
441
|
+
var cancelThrottle = _updateDimension.cancel;
|
|
442
|
+
return function stop() {
|
|
443
|
+
removeListener();
|
|
444
|
+
cancelThrottle();
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function initFrustrationObserver(lifeCycle, frustrationCb) {
|
|
449
|
+
return lifeCycle.subscribe(_browserCore.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (data) {
|
|
450
|
+
if (data.rawRumEvent.type === _browserCore.RumEventType.ACTION && data.rawRumEvent.action.type === _browserCore.ActionType.CLICK && data.rawRumEvent.action.frustration && data.rawRumEvent.action.frustration.type && data.rawRumEvent.action.frustration.type.length && 'events' in data.domainContext && data.domainContext.events && data.domainContext.events.length) {// frustrationCb({
|
|
451
|
+
// timestamp: data.rawRumEvent.date,
|
|
452
|
+
// type: RecordType.FrustrationRecord,
|
|
453
|
+
// data: {
|
|
454
|
+
// frustrationTypes: data.rawRumEvent.action.frustration.type,
|
|
455
|
+
// recordIds: data.domainContext.events.map(function (e) {
|
|
456
|
+
// return getRecordIdForEvent(e)
|
|
457
|
+
// })
|
|
458
|
+
// }
|
|
459
|
+
// })
|
|
460
|
+
}
|
|
461
|
+
}).unsubscribe;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function getEventTarget(event) {
|
|
465
|
+
if (event.composed === true && (0, _browserCore.isNodeShadowHost)(event.target)) {
|
|
466
|
+
return event.composedPath()[0];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return event.target;
|
|
470
|
+
}
|