@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,565 @@
|
|
|
1
|
+
import {
|
|
2
|
+
instrumentSetter,
|
|
3
|
+
instrumentMethodAndCallOriginal,
|
|
4
|
+
assign,
|
|
5
|
+
throttle,
|
|
6
|
+
DOM_EVENT,
|
|
7
|
+
addEventListeners,
|
|
8
|
+
addEventListener,
|
|
9
|
+
noop,
|
|
10
|
+
LifeCycleEventType,
|
|
11
|
+
RumEventType,
|
|
12
|
+
ActionType,
|
|
13
|
+
isNodeShadowHost
|
|
14
|
+
} from '@cloudcare/browser-core'
|
|
15
|
+
import { initViewportObservable } from '../../initViewportObservable'
|
|
16
|
+
import { NodePrivacyLevel } from '../../../constants'
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
RecordType,
|
|
20
|
+
IncrementalSource,
|
|
21
|
+
MediaInteractionType,
|
|
22
|
+
MouseInteractionType
|
|
23
|
+
} from '../../../types'
|
|
24
|
+
import { getNodePrivacyLevel, shouldMaskNode } from './privacy'
|
|
25
|
+
import {
|
|
26
|
+
getElementInputValue,
|
|
27
|
+
getSerializedNodeId,
|
|
28
|
+
hasSerializedNode
|
|
29
|
+
} from './serializationUtils'
|
|
30
|
+
import {
|
|
31
|
+
assembleIncrementalSnapshot,
|
|
32
|
+
forEach,
|
|
33
|
+
getPathToNestedCSSRule,
|
|
34
|
+
isTouchEvent
|
|
35
|
+
} from './utils'
|
|
36
|
+
import { startMutationObserver } from './mutationObserver'
|
|
37
|
+
import {
|
|
38
|
+
getVisualViewport,
|
|
39
|
+
getScrollX,
|
|
40
|
+
getScrollY,
|
|
41
|
+
convertMouseEventToLayoutCoordinates
|
|
42
|
+
} from './viewports'
|
|
43
|
+
|
|
44
|
+
var MOUSE_MOVE_OBSERVER_THRESHOLD = 50
|
|
45
|
+
var SCROLL_OBSERVER_THRESHOLD = 100
|
|
46
|
+
var VISUAL_VIEWPORT_OBSERVER_THRESHOLD = 200
|
|
47
|
+
|
|
48
|
+
var recordIds = new WeakMap()
|
|
49
|
+
let nextId = 1
|
|
50
|
+
|
|
51
|
+
export function getRecordIdForEvent(event) {
|
|
52
|
+
if (!recordIds.has(event)) {
|
|
53
|
+
recordIds.set(event, nextId++)
|
|
54
|
+
}
|
|
55
|
+
return recordIds.get(event)
|
|
56
|
+
}
|
|
57
|
+
export function initObservers(o) {
|
|
58
|
+
var mutationHandler = initMutationObserver(
|
|
59
|
+
o.mutationCb,
|
|
60
|
+
o.configuration,
|
|
61
|
+
o.shadowRootsController
|
|
62
|
+
)
|
|
63
|
+
var mousemoveHandler = initMoveObserver(o.mousemoveCb)
|
|
64
|
+
var mouseInteractionHandler = initMouseInteractionObserver(
|
|
65
|
+
o.mouseInteractionCb,
|
|
66
|
+
o.configuration.defaultPrivacyLevel
|
|
67
|
+
)
|
|
68
|
+
var scrollHandler = initScrollObserver(
|
|
69
|
+
o.scrollCb,
|
|
70
|
+
o.configuration.defaultPrivacyLevel,
|
|
71
|
+
o.elementsScrollPositions
|
|
72
|
+
)
|
|
73
|
+
var viewportResizeHandler = initViewportResizeObserver(o.viewportResizeCb)
|
|
74
|
+
var inputHandler = initInputObserver(
|
|
75
|
+
o.inputCb,
|
|
76
|
+
o.configuration.defaultPrivacyLevel
|
|
77
|
+
)
|
|
78
|
+
var mediaInteractionHandler = initMediaInteractionObserver(
|
|
79
|
+
o.mediaInteractionCb,
|
|
80
|
+
o.configuration.defaultPrivacyLevel
|
|
81
|
+
)
|
|
82
|
+
var styleSheetObserver = initStyleSheetObserver(o.styleSheetCb)
|
|
83
|
+
var focusHandler = initFocusObserver(o.focusCb)
|
|
84
|
+
var visualViewportResizeHandler = initVisualViewportResizeObserver(
|
|
85
|
+
o.visualViewportResizeCb
|
|
86
|
+
)
|
|
87
|
+
var frustrationHandler = initFrustrationObserver(o.lifeCycle, o.frustrationCb)
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
flush: function () {
|
|
91
|
+
mutationHandler.flush()
|
|
92
|
+
},
|
|
93
|
+
stop: function () {
|
|
94
|
+
mutationHandler.stop()
|
|
95
|
+
mousemoveHandler()
|
|
96
|
+
mouseInteractionHandler()
|
|
97
|
+
scrollHandler()
|
|
98
|
+
viewportResizeHandler()
|
|
99
|
+
inputHandler()
|
|
100
|
+
mediaInteractionHandler()
|
|
101
|
+
styleSheetObserver()
|
|
102
|
+
focusHandler()
|
|
103
|
+
visualViewportResizeHandler()
|
|
104
|
+
frustrationHandler()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function initMutationObserver(cb, configuration, shadowRootsController) {
|
|
110
|
+
return startMutationObserver(
|
|
111
|
+
cb,
|
|
112
|
+
configuration,
|
|
113
|
+
shadowRootsController,
|
|
114
|
+
document
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function initMoveObserver(cb) {
|
|
119
|
+
var _updatePosition = throttle(
|
|
120
|
+
function (event) {
|
|
121
|
+
var target = getEventTarget(event)
|
|
122
|
+
if (hasSerializedNode(target)) {
|
|
123
|
+
var coordinates = tryToComputeCoordinates(event)
|
|
124
|
+
if (!coordinates) {
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
var position = {
|
|
128
|
+
id: getSerializedNodeId(target),
|
|
129
|
+
timeOffset: 0,
|
|
130
|
+
x: coordinates.x,
|
|
131
|
+
y: coordinates.y
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
cb(
|
|
135
|
+
[position],
|
|
136
|
+
isTouchEvent(event)
|
|
137
|
+
? IncrementalSource.TouchMove
|
|
138
|
+
: IncrementalSource.MouseMove
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
MOUSE_MOVE_OBSERVER_THRESHOLD,
|
|
143
|
+
{
|
|
144
|
+
trailing: false
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
return addEventListeners(
|
|
149
|
+
document,
|
|
150
|
+
[DOM_EVENT.MOUSE_MOVE, DOM_EVENT.TOUCH_MOVE],
|
|
151
|
+
_updatePosition.throttled,
|
|
152
|
+
{
|
|
153
|
+
capture: true,
|
|
154
|
+
passive: true
|
|
155
|
+
}
|
|
156
|
+
).stop
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
var eventTypeToMouseInteraction = {
|
|
160
|
+
// Listen for pointerup DOM events instead of mouseup for MouseInteraction/MouseUp records. This
|
|
161
|
+
// allows to reference such records from Frustration records.
|
|
162
|
+
//
|
|
163
|
+
// In the context of supporting Mobile Session Replay, we introduced `PointerInteraction` records
|
|
164
|
+
// used by the Mobile SDKs in place of `MouseInteraction`. In the future, we should replace
|
|
165
|
+
// `MouseInteraction` by `PointerInteraction` in the Browser SDK so we have an uniform way to
|
|
166
|
+
// convey such interaction. This would cleanly solve the issue since we would have
|
|
167
|
+
// `PointerInteraction/Up` records that we could reference from `Frustration` records.
|
|
168
|
+
[DOM_EVENT.POINTER_UP]: MouseInteractionType.MouseUp,
|
|
169
|
+
|
|
170
|
+
[DOM_EVENT.MOUSE_DOWN]: MouseInteractionType.MouseDown,
|
|
171
|
+
[DOM_EVENT.CLICK]: MouseInteractionType.Click,
|
|
172
|
+
[DOM_EVENT.CONTEXT_MENU]: MouseInteractionType.ContextMenu,
|
|
173
|
+
[DOM_EVENT.DBL_CLICK]: MouseInteractionType.DblClick,
|
|
174
|
+
[DOM_EVENT.FOCUS]: MouseInteractionType.Focus,
|
|
175
|
+
[DOM_EVENT.BLUR]: MouseInteractionType.Blur,
|
|
176
|
+
[DOM_EVENT.TOUCH_START]: MouseInteractionType.TouchStart,
|
|
177
|
+
[DOM_EVENT.TOUCH_END]: MouseInteractionType.TouchEnd
|
|
178
|
+
}
|
|
179
|
+
export function initMouseInteractionObserver(cb, defaultPrivacyLevel) {
|
|
180
|
+
var handler = function (event) {
|
|
181
|
+
var target = getEventTarget(event)
|
|
182
|
+
if (
|
|
183
|
+
getNodePrivacyLevel(target, defaultPrivacyLevel) ===
|
|
184
|
+
NodePrivacyLevel.HIDDEN ||
|
|
185
|
+
!hasSerializedNode(target)
|
|
186
|
+
) {
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
var id = getSerializedNodeId(target)
|
|
190
|
+
var type = eventTypeToMouseInteraction[event.type]
|
|
191
|
+
|
|
192
|
+
var interaction
|
|
193
|
+
if (
|
|
194
|
+
type !== MouseInteractionType.Blur &&
|
|
195
|
+
type !== MouseInteractionType.Focus
|
|
196
|
+
) {
|
|
197
|
+
var coordinates = tryToComputeCoordinates(event)
|
|
198
|
+
if (!coordinates) {
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
interaction = { id: id, type: type, x: coordinates.x, y: coordinates.y }
|
|
202
|
+
} else {
|
|
203
|
+
interaction = { id: id, type: type }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
var record = assign(
|
|
207
|
+
{ id: getRecordIdForEvent(event) },
|
|
208
|
+
assembleIncrementalSnapshot(
|
|
209
|
+
IncrementalSource.MouseInteraction,
|
|
210
|
+
interaction
|
|
211
|
+
)
|
|
212
|
+
)
|
|
213
|
+
cb(record)
|
|
214
|
+
}
|
|
215
|
+
return addEventListeners(
|
|
216
|
+
document,
|
|
217
|
+
Object.keys(eventTypeToMouseInteraction),
|
|
218
|
+
handler,
|
|
219
|
+
{
|
|
220
|
+
capture: true,
|
|
221
|
+
passive: true
|
|
222
|
+
}
|
|
223
|
+
).stop
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function tryToComputeCoordinates(event) {
|
|
227
|
+
var _event = isTouchEvent(event) ? event.changedTouches[0] : event
|
|
228
|
+
var x = _event.clientX
|
|
229
|
+
var y = _event.clientY
|
|
230
|
+
if (window.visualViewport) {
|
|
231
|
+
var _convertMouseEventToLayoutCoordinates =
|
|
232
|
+
convertMouseEventToLayoutCoordinates(x, y)
|
|
233
|
+
x = _convertMouseEventToLayoutCoordinates.visualViewportX
|
|
234
|
+
y = _convertMouseEventToLayoutCoordinates.visualViewportY
|
|
235
|
+
}
|
|
236
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
237
|
+
return undefined
|
|
238
|
+
}
|
|
239
|
+
return { x: x, y: y }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function initScrollObserver(cb, defaultPrivacyLevel, elementsScrollPositions) {
|
|
243
|
+
var _updatePosition = throttle(function (event) {
|
|
244
|
+
var target = getEventTarget(event)
|
|
245
|
+
if (
|
|
246
|
+
!target ||
|
|
247
|
+
getNodePrivacyLevel(target, defaultPrivacyLevel) ===
|
|
248
|
+
NodePrivacyLevel.HIDDEN ||
|
|
249
|
+
!hasSerializedNode(target)
|
|
250
|
+
) {
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
var id = getSerializedNodeId(target)
|
|
254
|
+
var scrollPositions =
|
|
255
|
+
target === document
|
|
256
|
+
? {
|
|
257
|
+
scrollTop: getScrollY(),
|
|
258
|
+
scrollLeft: getScrollX()
|
|
259
|
+
}
|
|
260
|
+
: {
|
|
261
|
+
scrollTop: Math.round(target.scrollTop),
|
|
262
|
+
scrollLeft: Math.round(target.scrollLeft)
|
|
263
|
+
}
|
|
264
|
+
elementsScrollPositions.set(target, scrollPositions)
|
|
265
|
+
cb({
|
|
266
|
+
id: id,
|
|
267
|
+
x: scrollPositions.scrollLeft,
|
|
268
|
+
y: scrollPositions.scrollTop
|
|
269
|
+
})
|
|
270
|
+
}, SCROLL_OBSERVER_THRESHOLD)
|
|
271
|
+
return addEventListener(
|
|
272
|
+
document,
|
|
273
|
+
DOM_EVENT.SCROLL,
|
|
274
|
+
_updatePosition.throttled,
|
|
275
|
+
{
|
|
276
|
+
capture: true,
|
|
277
|
+
passive: true
|
|
278
|
+
}
|
|
279
|
+
).stop
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function initViewportResizeObserver(cb) {
|
|
283
|
+
return initViewportObservable().subscribe(cb).unsubscribe
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function initInputObserver(cb, defaultPrivacyLevel, options) {
|
|
287
|
+
var domEvents = (options && options.domEvents) || [
|
|
288
|
+
DOM_EVENT.INPUT,
|
|
289
|
+
DOM_EVENT.CHANGE
|
|
290
|
+
]
|
|
291
|
+
var target = (options && options.target) || document
|
|
292
|
+
var lastInputStateMap = new WeakMap()
|
|
293
|
+
|
|
294
|
+
function onElementChange(target) {
|
|
295
|
+
var nodePrivacyLevel = getNodePrivacyLevel(target, defaultPrivacyLevel)
|
|
296
|
+
if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
|
|
297
|
+
return
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
var type = target.type
|
|
301
|
+
|
|
302
|
+
let inputState
|
|
303
|
+
if (type === 'radio' || type === 'checkbox') {
|
|
304
|
+
if (shouldMaskNode(target, nodePrivacyLevel)) {
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
inputState = { isChecked: target.checked }
|
|
308
|
+
} else {
|
|
309
|
+
var value = getElementInputValue(target, nodePrivacyLevel)
|
|
310
|
+
if (value === undefined) {
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
inputState = { text: value }
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Can be multiple changes on the same node within the same batched mutation observation.
|
|
317
|
+
cbWithDedup(target, inputState)
|
|
318
|
+
|
|
319
|
+
// If a radio was checked, other radios with the same name attribute will be unchecked.
|
|
320
|
+
var name = target.name
|
|
321
|
+
if (type === 'radio' && name && target.checked) {
|
|
322
|
+
forEach(
|
|
323
|
+
document.querySelectorAll(`input[type="radio"][name="${name}"]`),
|
|
324
|
+
function (el) {
|
|
325
|
+
if (el !== target) {
|
|
326
|
+
// TODO: Consider the privacy implications for various differing input privacy levels
|
|
327
|
+
cbWithDedup(el, { isChecked: false })
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* There can be multiple changes on the same node within the same batched mutation observation.
|
|
336
|
+
*/
|
|
337
|
+
function cbWithDedup(target, inputState) {
|
|
338
|
+
if (!hasSerializedNode(target)) {
|
|
339
|
+
return
|
|
340
|
+
}
|
|
341
|
+
var lastInputState = lastInputStateMap.get(target)
|
|
342
|
+
if (
|
|
343
|
+
!lastInputState ||
|
|
344
|
+
lastInputState.text !== inputState.text ||
|
|
345
|
+
lastInputState.isChecked !== inputState.isChecked
|
|
346
|
+
) {
|
|
347
|
+
lastInputStateMap.set(target, inputState)
|
|
348
|
+
cb(
|
|
349
|
+
assign(
|
|
350
|
+
{
|
|
351
|
+
id: getSerializedNodeId(target)
|
|
352
|
+
},
|
|
353
|
+
inputState
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
var _addEventListeners = addEventListeners(
|
|
360
|
+
target,
|
|
361
|
+
domEvents,
|
|
362
|
+
function (event) {
|
|
363
|
+
var target = getEventTarget(event)
|
|
364
|
+
if (
|
|
365
|
+
target instanceof HTMLInputElement ||
|
|
366
|
+
target instanceof HTMLTextAreaElement ||
|
|
367
|
+
target instanceof HTMLSelectElement
|
|
368
|
+
) {
|
|
369
|
+
onElementChange(target)
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
capture: true,
|
|
374
|
+
passive: true
|
|
375
|
+
}
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
var instrumentationStoppers = [
|
|
379
|
+
instrumentSetter(HTMLInputElement.prototype, 'value', onElementChange),
|
|
380
|
+
instrumentSetter(HTMLInputElement.prototype, 'checked', onElementChange),
|
|
381
|
+
instrumentSetter(HTMLSelectElement.prototype, 'value', onElementChange),
|
|
382
|
+
instrumentSetter(HTMLTextAreaElement.prototype, 'value', onElementChange),
|
|
383
|
+
instrumentSetter(
|
|
384
|
+
HTMLSelectElement.prototype,
|
|
385
|
+
'selectedIndex',
|
|
386
|
+
onElementChange
|
|
387
|
+
)
|
|
388
|
+
]
|
|
389
|
+
|
|
390
|
+
return function () {
|
|
391
|
+
instrumentationStoppers.forEach(function (stopper) {
|
|
392
|
+
stopper.stop()
|
|
393
|
+
})
|
|
394
|
+
_addEventListeners.stop()
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export function initStyleSheetObserver(cb) {
|
|
399
|
+
function checkStyleSheetAndCallback(styleSheet, callback) {
|
|
400
|
+
if (styleSheet && hasSerializedNode(styleSheet.ownerNode)) {
|
|
401
|
+
callback(getSerializedNodeId(styleSheet.ownerNode))
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
var instrumentationStoppers = [
|
|
406
|
+
instrumentMethodAndCallOriginal(CSSStyleSheet.prototype, 'insertRule', {
|
|
407
|
+
before: function (rule, index) {
|
|
408
|
+
checkStyleSheetAndCallback(this, function (id) {
|
|
409
|
+
return cb({ id: id, adds: [{ rule: rule, index: index }] })
|
|
410
|
+
})
|
|
411
|
+
}
|
|
412
|
+
}),
|
|
413
|
+
instrumentMethodAndCallOriginal(CSSStyleSheet.prototype, 'deleteRule', {
|
|
414
|
+
before: function (index) {
|
|
415
|
+
checkStyleSheetAndCallback(this, function (id) {
|
|
416
|
+
return cb({ id: id, removes: [{ index: index }] })
|
|
417
|
+
})
|
|
418
|
+
}
|
|
419
|
+
})
|
|
420
|
+
]
|
|
421
|
+
|
|
422
|
+
if (typeof CSSGroupingRule !== 'undefined') {
|
|
423
|
+
instrumentGroupingCSSRuleClass(CSSGroupingRule)
|
|
424
|
+
} else {
|
|
425
|
+
instrumentGroupingCSSRuleClass(CSSMediaRule)
|
|
426
|
+
instrumentGroupingCSSRuleClass(CSSSupportsRule)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function instrumentGroupingCSSRuleClass(cls) {
|
|
430
|
+
instrumentationStoppers.push(
|
|
431
|
+
instrumentMethodAndCallOriginal(cls.prototype, 'insertRule', {
|
|
432
|
+
before: function (rule, index) {
|
|
433
|
+
var _this = this
|
|
434
|
+
checkStyleSheetAndCallback(this.parentStyleSheet, function (id) {
|
|
435
|
+
var path = getPathToNestedCSSRule(_this)
|
|
436
|
+
if (path) {
|
|
437
|
+
path.push(index || 0)
|
|
438
|
+
cb({ id: id, adds: [{ rule: rule, index: path }] })
|
|
439
|
+
}
|
|
440
|
+
})
|
|
441
|
+
}
|
|
442
|
+
}),
|
|
443
|
+
instrumentMethodAndCallOriginal(cls.prototype, 'deleteRule', {
|
|
444
|
+
before: function (index) {
|
|
445
|
+
var _this = this
|
|
446
|
+
checkStyleSheetAndCallback(this.parentStyleSheet, function (id) {
|
|
447
|
+
var path = getPathToNestedCSSRule(_this)
|
|
448
|
+
if (path) {
|
|
449
|
+
path.push(index)
|
|
450
|
+
cb({ id: id, removes: [{ index: path }] })
|
|
451
|
+
}
|
|
452
|
+
})
|
|
453
|
+
}
|
|
454
|
+
})
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return function () {
|
|
459
|
+
instrumentationStoppers.forEach(function (stopper) {
|
|
460
|
+
stopper.stop()
|
|
461
|
+
})
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function initMediaInteractionObserver(mediaInteractionCb, defaultPrivacyLevel) {
|
|
466
|
+
var handler = function (event) {
|
|
467
|
+
var target = getEventTarget(event)
|
|
468
|
+
if (
|
|
469
|
+
!target ||
|
|
470
|
+
getNodePrivacyLevel(target, defaultPrivacyLevel) ===
|
|
471
|
+
NodePrivacyLevel.HIDDEN ||
|
|
472
|
+
!hasSerializedNode(target)
|
|
473
|
+
) {
|
|
474
|
+
return
|
|
475
|
+
}
|
|
476
|
+
mediaInteractionCb({
|
|
477
|
+
id: getSerializedNodeId(target),
|
|
478
|
+
type:
|
|
479
|
+
event.type === DOM_EVENT.PLAY
|
|
480
|
+
? MediaInteractionType.Play
|
|
481
|
+
: MediaInteractionType.Pause
|
|
482
|
+
})
|
|
483
|
+
}
|
|
484
|
+
return addEventListeners(
|
|
485
|
+
document,
|
|
486
|
+
[DOM_EVENT.PLAY, DOM_EVENT.PAUSE],
|
|
487
|
+
handler,
|
|
488
|
+
{ capture: true, passive: true }
|
|
489
|
+
).stop
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function initFocusObserver(focusCb) {
|
|
493
|
+
return addEventListeners(
|
|
494
|
+
window,
|
|
495
|
+
[DOM_EVENT.FOCUS, DOM_EVENT.BLUR],
|
|
496
|
+
function () {
|
|
497
|
+
focusCb({ has_focus: document.hasFocus() })
|
|
498
|
+
}
|
|
499
|
+
).stop
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function initVisualViewportResizeObserver(cb) {
|
|
503
|
+
if (!window.visualViewport) {
|
|
504
|
+
return noop
|
|
505
|
+
}
|
|
506
|
+
var _updateDimension = throttle(
|
|
507
|
+
function () {
|
|
508
|
+
cb(getVisualViewport())
|
|
509
|
+
},
|
|
510
|
+
VISUAL_VIEWPORT_OBSERVER_THRESHOLD,
|
|
511
|
+
{
|
|
512
|
+
trailing: false
|
|
513
|
+
}
|
|
514
|
+
)
|
|
515
|
+
var removeListener = addEventListeners(
|
|
516
|
+
window.visualViewport,
|
|
517
|
+
[DOM_EVENT.RESIZE, DOM_EVENT.SCROLL],
|
|
518
|
+
_updateDimension.throttled,
|
|
519
|
+
{
|
|
520
|
+
capture: true,
|
|
521
|
+
passive: true
|
|
522
|
+
}
|
|
523
|
+
).stop
|
|
524
|
+
var cancelThrottle = _updateDimension.cancel
|
|
525
|
+
return function stop() {
|
|
526
|
+
removeListener()
|
|
527
|
+
cancelThrottle()
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export function initFrustrationObserver(lifeCycle, frustrationCb) {
|
|
532
|
+
return lifeCycle.subscribe(
|
|
533
|
+
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
|
|
534
|
+
function (data) {
|
|
535
|
+
if (
|
|
536
|
+
data.rawRumEvent.type === RumEventType.ACTION &&
|
|
537
|
+
data.rawRumEvent.action.type === ActionType.CLICK &&
|
|
538
|
+
data.rawRumEvent.action.frustration &&
|
|
539
|
+
data.rawRumEvent.action.frustration.type &&
|
|
540
|
+
data.rawRumEvent.action.frustration.type.length &&
|
|
541
|
+
'events' in data.domainContext &&
|
|
542
|
+
data.domainContext.events &&
|
|
543
|
+
data.domainContext.events.length
|
|
544
|
+
) {
|
|
545
|
+
// frustrationCb({
|
|
546
|
+
// timestamp: data.rawRumEvent.date,
|
|
547
|
+
// type: RecordType.FrustrationRecord,
|
|
548
|
+
// data: {
|
|
549
|
+
// frustrationTypes: data.rawRumEvent.action.frustration.type,
|
|
550
|
+
// recordIds: data.domainContext.events.map(function (e) {
|
|
551
|
+
// return getRecordIdForEvent(e)
|
|
552
|
+
// })
|
|
553
|
+
// }
|
|
554
|
+
// })
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
).unsubscribe
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function getEventTarget(event) {
|
|
561
|
+
if (event.composed === true && isNodeShadowHost(event.target)) {
|
|
562
|
+
return event.composedPath()[0]
|
|
563
|
+
}
|
|
564
|
+
return event.target
|
|
565
|
+
}
|