@cloudcare/browser-rum 3.1.8 → 3.1.11

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.
Files changed (60) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +5 -0
  4. package/cjs/boot/recorderApi.js.map +1 -1
  5. package/cjs/domain/configuration.js.map +1 -1
  6. package/cjs/domain/contexts/urlContexts.js +4 -4
  7. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  8. package/cjs/domain/contexts/viewContexts.js +2 -2
  9. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  10. package/cjs/domain/replay/deflate/deflateWorker.js +1 -1
  11. package/cjs/domain/replay/record/mutationObserver.js +11 -11
  12. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  13. package/cjs/domain/replay/record/observers.js +18 -5
  14. package/cjs/domain/replay/record/observers.js.map +1 -1
  15. package/cjs/domain/replay/record/privacy.js +9 -3
  16. package/cjs/domain/replay/record/privacy.js.map +1 -1
  17. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +3 -1
  18. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  19. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +1 -1
  20. package/cjs/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  21. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +6 -1
  22. package/cjs/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  23. package/cjs/domain/rumEventsCollection/view/trackViews.js +7 -2
  24. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  25. package/esm/boot/buildEnv.js +1 -1
  26. package/esm/boot/recorderApi.js +6 -1
  27. package/esm/boot/recorderApi.js.map +1 -1
  28. package/esm/domain/configuration.js.map +1 -1
  29. package/esm/domain/contexts/urlContexts.js +4 -4
  30. package/esm/domain/contexts/urlContexts.js.map +1 -1
  31. package/esm/domain/contexts/viewContexts.js +2 -2
  32. package/esm/domain/contexts/viewContexts.js.map +1 -1
  33. package/esm/domain/replay/deflate/deflateWorker.js +1 -1
  34. package/esm/domain/replay/record/mutationObserver.js +11 -11
  35. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  36. package/esm/domain/replay/record/observers.js +18 -5
  37. package/esm/domain/replay/record/observers.js.map +1 -1
  38. package/esm/domain/replay/record/privacy.js +9 -3
  39. package/esm/domain/replay/record/privacy.js.map +1 -1
  40. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +3 -1
  41. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  42. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +1 -1
  43. package/esm/domain/rumEventsCollection/view/trackInteractionToNextPaint.js.map +1 -1
  44. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +6 -1
  45. package/esm/domain/rumEventsCollection/view/trackLargestContentfulPaint.js.map +1 -1
  46. package/esm/domain/rumEventsCollection/view/trackViews.js +7 -2
  47. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  48. package/package.json +7 -5
  49. package/src/boot/recorderApi.js +13 -2
  50. package/src/domain/configuration.js +1 -0
  51. package/src/domain/contexts/urlContexts.js +4 -6
  52. package/src/domain/contexts/viewContexts.js +12 -8
  53. package/src/domain/replay/record/mutationObserver.js +27 -11
  54. package/src/domain/replay/record/observers.js +22 -13
  55. package/src/domain/replay/record/privacy.js +12 -3
  56. package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -1
  57. package/src/domain/rumEventsCollection/view/trackInteractionToNextPaint.js +4 -1
  58. package/src/domain/rumEventsCollection/view/trackLargestContentfulPaint.js +6 -1
  59. package/src/domain/rumEventsCollection/view/trackViews.js +7 -3
  60. package/types/index.d.ts +55 -0
@@ -73,6 +73,7 @@ function processMutations(
73
73
  configuration,
74
74
  shadowRootsController
75
75
  ) {
76
+ var nodePrivacyLevelCache = new Map()
76
77
  mutations
77
78
  .filter(function (mutation) {
78
79
  return mutation.type === 'childList'
@@ -96,7 +97,8 @@ function processMutations(
96
97
  nodeAndAncestorsHaveSerializedNode(mutation.target) &&
97
98
  getNodePrivacyLevel(
98
99
  mutation.target,
99
- configuration.defaultPrivacyLevel
100
+ configuration.defaultPrivacyLevel,
101
+ nodePrivacyLevelCache
100
102
  ) !== NodePrivacyLevel.HIDDEN
101
103
  )
102
104
  })
@@ -105,7 +107,8 @@ function processMutations(
105
107
  return mutation.type === 'childList'
106
108
  }),
107
109
  configuration,
108
- shadowRootsController
110
+ shadowRootsController,
111
+ nodePrivacyLevelCache
109
112
  )
110
113
  var adds = _processChildListMutations.adds
111
114
  var removes = _processChildListMutations.removes
@@ -123,7 +126,8 @@ function processMutations(
123
126
  mutation.type === 'characterData' && !hasBeenSerialized(mutation.target)
124
127
  )
125
128
  }),
126
- configuration
129
+ configuration,
130
+ nodePrivacyLevelCache
127
131
  )
128
132
 
129
133
  var attributes = processAttributesMutations(
@@ -132,7 +136,8 @@ function processMutations(
132
136
  mutation.type === 'attributes' && !hasBeenSerialized(mutation.target)
133
137
  )
134
138
  }),
135
- configuration
139
+ configuration,
140
+ nodePrivacyLevelCache
136
141
  )
137
142
  if (!texts.length && !attributes.length && !removes.length && !adds.length) {
138
143
  return
@@ -148,7 +153,8 @@ function processMutations(
148
153
  function processChildListMutations(
149
154
  mutations,
150
155
  configuration,
151
- shadowRootsController
156
+ shadowRootsController,
157
+ nodePrivacyLevelCache
152
158
  ) {
153
159
  // First, we iterate over mutations to collect:
154
160
  //
@@ -200,7 +206,8 @@ function processChildListMutations(
200
206
 
201
207
  var parentNodePrivacyLevel = getNodePrivacyLevel(
202
208
  node.parentNode,
203
- configuration.defaultPrivacyLevel
209
+ configuration.defaultPrivacyLevel,
210
+ nodePrivacyLevelCache
204
211
  )
205
212
  if (
206
213
  parentNodePrivacyLevel === NodePrivacyLevel.HIDDEN ||
@@ -267,7 +274,11 @@ function processChildListMutations(
267
274
  }
268
275
  }
269
276
 
270
- function processCharacterDataMutations(mutations, configuration) {
277
+ function processCharacterDataMutations(
278
+ mutations,
279
+ configuration,
280
+ nodePrivacyLevelCache
281
+ ) {
271
282
  var textMutations = []
272
283
 
273
284
  // Deduplicate mutations based on their target node
@@ -289,7 +300,8 @@ function processCharacterDataMutations(mutations, configuration) {
289
300
 
290
301
  var parentNodePrivacyLevel = getNodePrivacyLevel(
291
302
  getParentNode(mutation.target),
292
- configuration.defaultPrivacyLevel
303
+ configuration.defaultPrivacyLevel,
304
+ nodePrivacyLevelCache
293
305
  )
294
306
  if (
295
307
  parentNodePrivacyLevel === NodePrivacyLevel.HIDDEN ||
@@ -300,7 +312,6 @@ function processCharacterDataMutations(mutations, configuration) {
300
312
 
301
313
  textMutations.push({
302
314
  id: getSerializedNodeId(mutation.target),
303
- // TODO: pass a valid "ignoreWhiteSpace" argument
304
315
  value: isNullUndefinedDefaultValue(
305
316
  getTextContent(mutation.target, false, parentNodePrivacyLevel, null)
306
317
  )
@@ -310,7 +321,11 @@ function processCharacterDataMutations(mutations, configuration) {
310
321
  return textMutations
311
322
  }
312
323
 
313
- function processAttributesMutations(mutations, configuration) {
324
+ function processAttributesMutations(
325
+ mutations,
326
+ configuration,
327
+ nodePrivacyLevelCache
328
+ ) {
314
329
  var attributeMutations = []
315
330
 
316
331
  // Deduplicate mutations based on their target node and changed attribute
@@ -337,7 +352,8 @@ function processAttributesMutations(mutations, configuration) {
337
352
  }
338
353
  var privacyLevel = getNodePrivacyLevel(
339
354
  mutation.target,
340
- configuration.defaultPrivacyLevel
355
+ configuration.defaultPrivacyLevel,
356
+ nodePrivacyLevelCache
341
357
  )
342
358
  var attributeValue = serializeAttribute(
343
359
  mutation.target,
@@ -145,16 +145,23 @@ export function initMoveObserver(cb) {
145
145
  trailing: false
146
146
  }
147
147
  )
148
+ var cancelThrottle = _updatePosition.cancel
149
+ var updatePosition = _updatePosition.throttled
148
150
 
149
- return addEventListeners(
151
+ var _listener = addEventListeners(
150
152
  document,
151
153
  [DOM_EVENT.MOUSE_MOVE, DOM_EVENT.TOUCH_MOVE],
152
- _updatePosition.throttled,
154
+ updatePosition,
153
155
  {
154
156
  capture: true,
155
157
  passive: true
156
158
  }
157
- ).stop
159
+ )
160
+ var removeListener = _listener.stop
161
+ return function () {
162
+ removeListener()
163
+ cancelThrottle()
164
+ }
158
165
  }
159
166
 
160
167
  var eventTypeToMouseInteraction = {
@@ -269,15 +276,18 @@ function initScrollObserver(cb, defaultPrivacyLevel, elementsScrollPositions) {
269
276
  y: scrollPositions.scrollTop
270
277
  })
271
278
  }, SCROLL_OBSERVER_THRESHOLD)
272
- return addEventListener(
273
- document,
274
- DOM_EVENT.SCROLL,
275
- _updatePosition.throttled,
276
- {
277
- capture: true,
278
- passive: true
279
- }
280
- ).stop
279
+ var cancelThrottle = _updatePosition.cancel
280
+ var updatePosition = _updatePosition.throttled
281
+
282
+ var _listener = addEventListener(document, DOM_EVENT.SCROLL, updatePosition, {
283
+ capture: true,
284
+ passive: true
285
+ })
286
+ var removeListener = _listener.stop
287
+ return function () {
288
+ removeListener()
289
+ cancelThrottle()
290
+ }
281
291
  }
282
292
 
283
293
  function initViewportResizeObserver(cb) {
@@ -374,7 +384,6 @@ export function initInputObserver(cb, defaultPrivacyLevel, target) {
374
384
  ),
375
385
  function (el) {
376
386
  if (el !== target) {
377
- // TODO: Consider the privacy implications for various differing input privacy levels
378
387
  cbWithDedup(el, { isChecked: false })
379
388
  }
380
389
  }
@@ -29,13 +29,23 @@ var TEXT_MASKING_CHAR = 'x'
29
29
  *
30
30
  * derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel)
31
31
  */
32
- export function getNodePrivacyLevel(node, defaultPrivacyLevel) {
32
+ export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache) {
33
+ if (cache && cache.has(node)) {
34
+ return cache.get(node)
35
+ }
33
36
  var parentNode = getParentNode(node)
34
37
  var parentNodePrivacyLevel = parentNode
35
38
  ? getNodePrivacyLevel(parentNode, defaultPrivacyLevel)
36
39
  : defaultPrivacyLevel
37
40
  var selfNodePrivacyLevel = getNodeSelfPrivacyLevel(node)
38
- return reducePrivacyLevel(selfNodePrivacyLevel, parentNodePrivacyLevel)
41
+ var nodePrivacyLevel = reducePrivacyLevel(
42
+ selfNodePrivacyLevel,
43
+ parentNodePrivacyLevel
44
+ )
45
+ if (cache) {
46
+ cache.set(node, nodePrivacyLevel)
47
+ }
48
+ return nodePrivacyLevel
39
49
  }
40
50
 
41
51
  /**
@@ -245,7 +255,6 @@ export function getTextContent(
245
255
  }
246
256
 
247
257
  /**
248
- * TODO: Preserve CSS element order, and record the presence of the tag, just don't render
249
258
  * We don't need this logic on the recorder side.
250
259
  * For security related meta's, customer can mask themmanually given they
251
260
  * are easy to identify in the HEAD tag.
@@ -168,7 +168,9 @@ function processResourceEntry(
168
168
  var entryMetrics = computePerformanceEntryMetrics(entry)
169
169
  var urlObj = urlParse(entry.name).getParse()
170
170
  var statusCode = ''
171
- if (is304(entry)) {
171
+ if (entry.responseStatus !== 0) {
172
+ statusCode = entry.responseStatus
173
+ } else if (is304(entry)) {
172
174
  statusCode = 304
173
175
  } else if (isCacheHit(entry)) {
174
176
  statusCode = 200
@@ -67,7 +67,10 @@ export function trackInteractionToNextPaint(
67
67
  }
68
68
 
69
69
  var newInteraction = longestInteractions.estimateP98Duration()
70
- if (newInteraction) {
70
+ if (
71
+ newInteraction &&
72
+ newInteraction.duration !== interactionToNextPaint
73
+ ) {
71
74
  interactionToNextPaint = newInteraction.duration
72
75
  if (interactionToNextPaint > 10 * ONE_MINUTE && !telemetryCollected) {
73
76
  telemetryCollected = true
@@ -35,6 +35,7 @@ export function trackLargestContentfulPaint(
35
35
  { capture: true, once: true }
36
36
  )
37
37
  var stopEventListener = _addEventListeners.stop
38
+ var biggestLcpSize = 0
38
39
  var subscribe = lifeCycle.subscribe(
39
40
  LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED,
40
41
  function (entries) {
@@ -43,7 +44,10 @@ export function trackLargestContentfulPaint(
43
44
  entry.entryType === 'largest-contentful-paint' &&
44
45
  entry.startTime < firstInteractionTimestamp &&
45
46
  entry.startTime < firstHidden.geTimeStamp() &&
46
- entry.startTime < LCP_MAXIMUM_DELAY
47
+ entry.startTime < LCP_MAXIMUM_DELAY &&
48
+ // Ensure to get the LCP entry with the biggest size, see
49
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=1516655
50
+ entry.size > biggestLcpSize
47
51
  )
48
52
  })
49
53
  if (lcpEntry) {
@@ -58,6 +62,7 @@ export function trackLargestContentfulPaint(
58
62
  value: lcpEntry.startTime,
59
63
  targetSelector: lcpTargetSelector
60
64
  })
65
+ biggestLcpSize = lcpEntry.size
61
66
  }
62
67
  }
63
68
  )
@@ -159,14 +159,15 @@ function newView(
159
159
  service = viewOptions.service
160
160
  version = viewOptions.version
161
161
  }
162
-
163
- lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, {
162
+ var viewCreatedEvent = {
164
163
  id: id,
165
164
  name: name,
166
165
  startClocks: startClocks,
167
166
  service: service,
168
167
  version: version
169
- })
168
+ }
169
+ lifeCycle.notify(LifeCycleEventType.BEFORE_VIEW_CREATED, viewCreatedEvent)
170
+ lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, viewCreatedEvent)
170
171
 
171
172
  // Update the view every time the measures are changing
172
173
  var _scheduleViewUpdate = throttle(
@@ -264,6 +265,9 @@ function newView(
264
265
  true
265
266
  )
266
267
  lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: endClocks })
268
+ lifeCycle.notify(LifeCycleEventType.AFTER_VIEW_ENDED, {
269
+ endClocks: endClocks
270
+ })
267
271
  clearInterval(keepAliveIntervalId)
268
272
  setViewEnd(endClocks.relative)
269
273
  stopCommonViewMetricsTracking()
@@ -0,0 +1,55 @@
1
+ import type {
2
+ RumInitConfiguration,
3
+ InitConfiguration,
4
+ Context,
5
+ User
6
+ } from '@cloudcare/browser-core'
7
+ export interface InternalContext {
8
+ application: {
9
+ id: string
10
+ }
11
+ session: {
12
+ id: string | undefined
13
+ }
14
+ view?: {
15
+ id: string
16
+ url: string
17
+ referrer: string
18
+ name?: string
19
+ host: string
20
+ path: string
21
+ urlQuery: string
22
+ pathGroup: string
23
+ }
24
+ userAction?: {
25
+ id: string
26
+ ids: string[]
27
+ }
28
+ }
29
+ export declare const datafluxRum: {
30
+ init: (initConfiguration: RumInitConfiguration) => void
31
+ setGlobalContextProperty: (key: any, value: any) => void
32
+ addRumGlobalContext: (key: any, value: any) => void
33
+ removeGlobalContextProperty: (key: any) => void
34
+ removeRumGlobalContext: (key: any) => void
35
+ getGlobalContext: () => Context
36
+ setGlobalContext: (context: any) => void
37
+ clearGlobalContext: () => void
38
+ getInternalContext: (
39
+ startTime?: number | undefined
40
+ ) => InternalContext | undefined
41
+ getInitConfiguration: () => InitConfiguration | undefined
42
+ addAction: (name: string, context?: object | undefined) => void
43
+ addError: (error: unknown, context?: object | undefined) => void
44
+ addTiming: (name: string, time?: number | undefined) => void
45
+ setUser: (newUser: User) => void
46
+ getUser: () => Context
47
+ setUserProperty: (key: any, property: any) => void
48
+ removeUserProperty: (key: any) => void
49
+ clearUser: () => void
50
+ stopSession: () => void
51
+ startSessionReplayRecording: () => void
52
+ stopSessionReplayRecording: () => void
53
+ } & {
54
+ onReady(callback: () => void): void
55
+ }