@cloudcare/browser-rum 3.3.13 → 3.3.15

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 (96) hide show
  1. package/README.md +48 -0
  2. package/README.zh.md +35 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/perStartRum.js +3 -0
  6. package/cjs/boot/perStartRum.js.map +1 -1
  7. package/cjs/boot/recorderApi.js +72 -56
  8. package/cjs/boot/recorderApi.js.map +1 -1
  9. package/cjs/boot/rumPublicApi.js +35 -3
  10. package/cjs/boot/rumPublicApi.js.map +1 -1
  11. package/cjs/boot/startRecording.js +5 -2
  12. package/cjs/boot/startRecording.js.map +1 -1
  13. package/cjs/domain/assembly.js +7 -1
  14. package/cjs/domain/assembly.js.map +1 -1
  15. package/cjs/domain/configuration.js +63 -0
  16. package/cjs/domain/configuration.js.map +1 -1
  17. package/cjs/domain/deflate/deflateWorker.js +1 -1
  18. package/cjs/domain/privacy.js +278 -0
  19. package/cjs/domain/privacy.js.map +1 -0
  20. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  21. package/cjs/domain/replay/record/privacy.js +11 -272
  22. package/cjs/domain/replay/record/privacy.js.map +1 -1
  23. package/cjs/domain/replay/record/record.js +10 -1
  24. package/cjs/domain/replay/record/record.js.map +1 -1
  25. package/cjs/domain/requestCollection.js +3 -1
  26. package/cjs/domain/requestCollection.js.map +1 -1
  27. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js +81 -19
  28. package/cjs/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  29. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  30. package/cjs/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  31. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
  32. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  33. package/cjs/domain/rumEventsCollection/view/trackViews.js +16 -5
  34. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  35. package/cjs/domain/rumSessionManager.js +2 -2
  36. package/cjs/domain/rumSessionManager.js.map +1 -1
  37. package/cjs/domain/tracing/tracer.js +5 -1
  38. package/cjs/domain/tracing/tracer.js.map +1 -1
  39. package/cjs/domain/visitorId/index.js +379 -0
  40. package/cjs/domain/visitorId/index.js.map +1 -0
  41. package/esm/boot/buildEnv.js +1 -1
  42. package/esm/boot/perStartRum.js +3 -0
  43. package/esm/boot/perStartRum.js.map +1 -1
  44. package/esm/boot/recorderApi.js +72 -56
  45. package/esm/boot/recorderApi.js.map +1 -1
  46. package/esm/boot/rumPublicApi.js +36 -4
  47. package/esm/boot/rumPublicApi.js.map +1 -1
  48. package/esm/boot/startRecording.js +5 -2
  49. package/esm/boot/startRecording.js.map +1 -1
  50. package/esm/domain/assembly.js +7 -1
  51. package/esm/domain/assembly.js.map +1 -1
  52. package/esm/domain/configuration.js +63 -1
  53. package/esm/domain/configuration.js.map +1 -1
  54. package/esm/domain/deflate/deflateWorker.js +1 -1
  55. package/esm/domain/privacy.js +266 -0
  56. package/esm/domain/privacy.js.map +1 -0
  57. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  58. package/esm/domain/replay/record/privacy.js +1 -266
  59. package/esm/domain/replay/record/privacy.js.map +1 -1
  60. package/esm/domain/replay/record/record.js +10 -1
  61. package/esm/domain/replay/record/record.js.map +1 -1
  62. package/esm/domain/requestCollection.js +4 -2
  63. package/esm/domain/requestCollection.js.map +1 -1
  64. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js +80 -18
  65. package/esm/domain/rumEventsCollection/actions/getActionNameFromElement.js.map +1 -1
  66. package/esm/domain/rumEventsCollection/actions/trackClickActions.js +11 -4
  67. package/esm/domain/rumEventsCollection/actions/trackClickActions.js.map +1 -1
  68. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +5 -0
  69. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  70. package/esm/domain/rumEventsCollection/view/trackViews.js +17 -6
  71. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  72. package/esm/domain/rumSessionManager.js +2 -2
  73. package/esm/domain/rumSessionManager.js.map +1 -1
  74. package/esm/domain/tracing/tracer.js +6 -2
  75. package/esm/domain/tracing/tracer.js.map +1 -1
  76. package/esm/domain/visitorId/index.js +368 -0
  77. package/esm/domain/visitorId/index.js.map +1 -0
  78. package/package.json +4 -4
  79. package/src/boot/perStartRum.js +4 -0
  80. package/src/boot/recorderApi.js +73 -59
  81. package/src/boot/rumPublicApi.js +38 -4
  82. package/src/boot/startRecording.js +11 -2
  83. package/src/domain/assembly.js +13 -1
  84. package/src/domain/configuration.js +158 -0
  85. package/src/domain/privacy.js +356 -0
  86. package/src/domain/replay/record/privacy.js +1 -356
  87. package/src/domain/replay/record/record.js +10 -1
  88. package/src/domain/requestCollection.js +4 -1
  89. package/src/domain/rumEventsCollection/actions/getActionNameFromElement.js +148 -21
  90. package/src/domain/rumEventsCollection/actions/trackClickActions.js +19 -5
  91. package/src/domain/rumEventsCollection/resource/resourceCollection.js +3 -0
  92. package/src/domain/rumEventsCollection/view/trackViews.js +33 -6
  93. package/src/domain/rumSessionManager.js +2 -2
  94. package/src/domain/tracing/tracer.js +15 -2
  95. package/src/domain/visitorId/index.js +522 -0
  96. package/types/index.d.ts +2 -0
@@ -575,8 +575,17 @@ export function record(options) {
575
575
  lastReplayTimeAnchorTimestamp = timestamp
576
576
  return true
577
577
  }
578
+ function emitPeriodicReplayTimeAnchor() {
579
+ // Keep the explicit page-exit anchor as the hidden boundary, but do not let
580
+ // the background timer extend the replay timeline while the Session is no
581
+ // longer renewed by visible-page activity.
582
+ if (document.visibilityState !== 'visible') {
583
+ return
584
+ }
585
+ emitReplayTimeAnchor()
586
+ }
578
587
  var replayTimeAnchorIntervalId = setInterval(
579
- emitReplayTimeAnchor,
588
+ emitPeriodicReplayTimeAnchor,
580
589
  SESSION_REPLAY_TIME_ANCHOR_INTERVAL
581
590
  )
582
591
  registerInitializationCleanup(function () {
@@ -2,6 +2,7 @@ import {
2
2
  RequestType,
3
3
  initFetchObservable,
4
4
  initXhrObservable,
5
+ isRequest,
5
6
  LifeCycleEventType,
6
7
  tryToClone,
7
8
  readBytesFromStream,
@@ -51,6 +52,7 @@ export function trackXhr(lifeCycle, configuration, tracer) {
51
52
  status: context.status,
52
53
  traceId: context.traceId,
53
54
  traceSampled: context.traceSampled,
55
+ visitorId: context.visitorId,
54
56
  type: RequestType.XHR,
55
57
  url: context.url,
56
58
  xhr: context.xhr,
@@ -99,9 +101,10 @@ export function trackFetch(lifeCycle, configuration, tracer) {
99
101
  status: context.status,
100
102
  traceId: context.traceId,
101
103
  traceSampled: context.traceSampled,
104
+ visitorId: context.visitorId,
102
105
  requestHeaderContexts:
103
106
  context.init?.headers ||
104
- (context.input instanceof Request
107
+ (isRequest(context.input)
105
108
  ? context.input.headers
106
109
  : undefined),
107
110
  type: RequestType.FETCH,
@@ -7,20 +7,44 @@ import {
7
7
  getParentElement,
8
8
  isNodeShadowRoot
9
9
  } from '@cloudcare/browser-core'
10
+ import {
11
+ getNodePrivacyLevel,
12
+ shouldMaskNode
13
+ } from '../../privacy'
10
14
 
11
15
  export var DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE =
12
16
  'data-guance-action-name'
17
+ export var ACTION_NAME_PLACEHOLDER = 'Masked Element'
13
18
 
14
19
  export function getActionNameFromElement(
15
20
  element,
16
- userProgrammaticAttribute,
17
- shouldIgnoreTextualFallback
21
+ configuration,
22
+ shouldIgnoreTextualFallback,
23
+ nodePrivacyLevel
18
24
  ) {
25
+ configuration = configuration || {}
26
+ var userProgrammaticAttribute = configuration.actionNameAttribute
27
+ var nodePrivacyLevelCache = new Map()
28
+ var explicitActionName = getExplicitActionName(
29
+ element,
30
+ userProgrammaticAttribute
31
+ )
32
+
33
+ if (explicitActionName) {
34
+ return explicitActionName
35
+ }
36
+ if (
37
+ configuration.enablePrivacyForActionName &&
38
+ shouldMaskNode(configuration, element, nodePrivacyLevel)
39
+ ) {
40
+ return ACTION_NAME_PLACEHOLDER
41
+ }
42
+
19
43
  return (
20
- getExplicitActionName(element, userProgrammaticAttribute) ||
21
44
  getActionNameFromElementForStrategies(
22
45
  element,
23
- userProgrammaticAttribute,
46
+ configuration,
47
+ nodePrivacyLevelCache,
24
48
  shouldIgnoreTextualFallback
25
49
  ? shadowDomPriorityStrategies
26
50
  : priorityStrategies
@@ -28,7 +52,8 @@ export function getActionNameFromElement(
28
52
  (!shouldIgnoreTextualFallback &&
29
53
  getActionNameFromElementForStrategies(
30
54
  element,
31
- userProgrammaticAttribute,
55
+ configuration,
56
+ nodePrivacyLevelCache,
32
57
  fallbackStrategies
33
58
  )) ||
34
59
  ''
@@ -74,12 +99,16 @@ function getActionNameFromElementProgrammatically(
74
99
 
75
100
  var priorityStrategies = [
76
101
  // associated LABEL text
77
- function (element, userProgrammaticAttribute) {
102
+ function (element, configuration, nodePrivacyLevelCache) {
78
103
  // IE does not support element.labels, so we fallback to a CSS selector based on the element id
79
104
  // instead
80
105
  if (supportsLabelProperty()) {
81
106
  if ('labels' in element && element.labels && element.labels.length > 0) {
82
- return getTextualContent(element.labels[0], userProgrammaticAttribute)
107
+ return getTextualContent(
108
+ element.labels[0],
109
+ configuration,
110
+ nodePrivacyLevelCache
111
+ )
83
112
  }
84
113
  } else if (element.id) {
85
114
  var label =
@@ -87,7 +116,9 @@ var priorityStrategies = [
87
116
  find(element.ownerDocument.querySelectorAll('label'), function (label) {
88
117
  return label.htmlFor === element.id
89
118
  })
90
- return label && getTextualContent(label, userProgrammaticAttribute)
119
+ return (
120
+ label && getTextualContent(label, configuration, nodePrivacyLevelCache)
121
+ )
91
122
  }
92
123
  },
93
124
  // INPUT button (and associated) value
@@ -101,20 +132,20 @@ var priorityStrategies = [
101
132
  }
102
133
  },
103
134
  // BUTTON, LABEL or button-like element text
104
- function (element, userProgrammaticAttribute) {
135
+ function (element, configuration, nodePrivacyLevelCache) {
105
136
  if (
106
137
  element.nodeName === 'BUTTON' ||
107
138
  element.nodeName === 'LABEL' ||
108
139
  element.getAttribute('role') === 'button'
109
140
  ) {
110
- return getTextualContent(element, userProgrammaticAttribute)
141
+ return getTextualContent(element, configuration, nodePrivacyLevelCache)
111
142
  }
112
143
  },
113
144
  function (element) {
114
145
  return element.getAttribute('aria-label')
115
146
  },
116
147
  // associated element text designated by the aria-labelledby attribute
117
- function (element, userProgrammaticAttribute) {
148
+ function (element, configuration, nodePrivacyLevelCache) {
118
149
  var labelledByAttribute = element.getAttribute('aria-labelledby')
119
150
  if (labelledByAttribute) {
120
151
  labelledByAttribute = labelledByAttribute.split(/\s+/)
@@ -125,7 +156,7 @@ var priorityStrategies = [
125
156
  return Boolean(label)
126
157
  })
127
158
  labelledByAttribute = map(labelledByAttribute, function (ele) {
128
- return getTextualContent(ele, userProgrammaticAttribute)
159
+ return getTextualContent(ele, configuration, nodePrivacyLevelCache)
129
160
  })
130
161
  return labelledByAttribute.join(' ')
131
162
  }
@@ -143,24 +174,28 @@ var priorityStrategies = [
143
174
  return element.getAttribute('placeholder')
144
175
  },
145
176
  // SELECT first OPTION text
146
- function (element, userProgrammaticAttribute) {
177
+ function (element, configuration, nodePrivacyLevelCache) {
147
178
  if ('options' in element && element.options.length > 0) {
148
- return getTextualContent(element.options[0], userProgrammaticAttribute)
179
+ return getTextualContent(
180
+ element.options[0],
181
+ configuration,
182
+ nodePrivacyLevelCache
183
+ )
149
184
  }
150
185
  }
151
186
  ]
152
187
 
153
188
  var shadowDomPriorityStrategies = priorityStrategies.concat([
154
- function (element, userProgrammaticAttribute) {
189
+ function (element, configuration, nodePrivacyLevelCache) {
155
190
  if (element.nodeName === 'A' && element.hasAttribute('href')) {
156
- return getTextualContent(element, userProgrammaticAttribute)
191
+ return getTextualContent(element, configuration, nodePrivacyLevelCache)
157
192
  }
158
193
  }
159
194
  ])
160
195
 
161
196
  var fallbackStrategies = [
162
- function (element, userProgrammaticAttribute) {
163
- return getTextualContent(element, userProgrammaticAttribute)
197
+ function (element, configuration, nodePrivacyLevelCache) {
198
+ return getTextualContent(element, configuration, nodePrivacyLevelCache)
164
199
  }
165
200
  ]
166
201
 
@@ -171,7 +206,8 @@ var fallbackStrategies = [
171
206
  var MAX_PARENTS_TO_CONSIDER = 10
172
207
  function getActionNameFromElementForStrategies(
173
208
  targetElement,
174
- userProgrammaticAttribute,
209
+ configuration,
210
+ nodePrivacyLevelCache,
175
211
  strategies
176
212
  ) {
177
213
  var element = targetElement
@@ -183,9 +219,19 @@ function getActionNameFromElementForStrategies(
183
219
  element.nodeName !== 'HTML' &&
184
220
  element.nodeName !== 'HEAD'
185
221
  ) {
222
+ if (configuration.enablePrivacyForActionName) {
223
+ var privacyLevel = getNodePrivacyLevel(
224
+ element,
225
+ configuration.defaultPrivacyLevel,
226
+ nodePrivacyLevelCache
227
+ )
228
+ if (shouldMaskNode(configuration, element, privacyLevel)) {
229
+ return ACTION_NAME_PLACEHOLDER
230
+ }
231
+ }
186
232
  for (var i = 0; i < strategies.length; i++) {
187
233
  var strategy = strategies[i]
188
- var name = strategy(element, userProgrammaticAttribute)
234
+ var name = strategy(element, configuration, nodePrivacyLevelCache)
189
235
  if (typeof name === 'string') {
190
236
  var trimmedName = name.trim()
191
237
  if (trimmedName) {
@@ -231,11 +277,31 @@ function getElementById(refElement, id) {
231
277
  : null
232
278
  }
233
279
 
234
- function getTextualContent(element, userProgrammaticAttribute) {
280
+ function getTextualContent(element, configuration, nodePrivacyLevelCache) {
235
281
  if (element.isContentEditable) {
236
282
  return
237
283
  }
238
284
 
285
+ if (configuration.enablePrivacyForActionName) {
286
+ var privacyLevel = getNodePrivacyLevel(
287
+ element,
288
+ configuration.defaultPrivacyLevel,
289
+ nodePrivacyLevelCache
290
+ )
291
+ if (shouldMaskNode(configuration, element, privacyLevel)) {
292
+ return
293
+ }
294
+ return getPrivacyAwareTextualContent(
295
+ element,
296
+ configuration,
297
+ nodePrivacyLevelCache
298
+ )
299
+ }
300
+
301
+ return getLegacyTextualContent(element, configuration.actionNameAttribute)
302
+ }
303
+
304
+ function getLegacyTextualContent(element, userProgrammaticAttribute) {
239
305
  if ('innerText' in element) {
240
306
  var text = element.innerText
241
307
 
@@ -273,6 +339,67 @@ function getTextualContent(element, userProgrammaticAttribute) {
273
339
  return element.textContent
274
340
  }
275
341
 
342
+ function getPrivacyAwareTextualContent(
343
+ element,
344
+ configuration,
345
+ nodePrivacyLevelCache
346
+ ) {
347
+ var ownerDocument = element.ownerDocument || document
348
+ var ownerWindow = ownerDocument.defaultView || window
349
+ var nodeFilter = ownerWindow.NodeFilter || NodeFilter
350
+ var walker = ownerDocument.createTreeWalker(
351
+ element,
352
+ nodeFilter.SHOW_ELEMENT | nodeFilter.SHOW_TEXT,
353
+ function (node) {
354
+ var privacyLevel = getNodePrivacyLevel(
355
+ node,
356
+ configuration.defaultPrivacyLevel,
357
+ nodePrivacyLevelCache
358
+ )
359
+ if (shouldMaskNode(configuration, node, privacyLevel)) {
360
+ return nodeFilter.FILTER_REJECT
361
+ }
362
+ if (node.nodeType === node.ELEMENT_NODE) {
363
+ if (
364
+ node.hasAttribute(DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE) ||
365
+ (configuration.actionNameAttribute &&
366
+ node.hasAttribute(configuration.actionNameAttribute))
367
+ ) {
368
+ return nodeFilter.FILTER_REJECT
369
+ }
370
+ var style = ownerWindow.getComputedStyle(node)
371
+ if (
372
+ style.visibility !== 'visible' ||
373
+ style.display === 'none' ||
374
+ (style.contentVisibility && style.contentVisibility !== 'visible')
375
+ ) {
376
+ return nodeFilter.FILTER_REJECT
377
+ }
378
+ }
379
+ return nodeFilter.FILTER_ACCEPT
380
+ }
381
+ )
382
+ var text = ''
383
+ while (walker.nextNode()) {
384
+ var node = walker.currentNode
385
+ if (node.nodeType === node.ELEMENT_NODE) {
386
+ var style = ownerWindow.getComputedStyle(node)
387
+ if (
388
+ node.nodeName === 'BR' ||
389
+ node.nodeName === 'P' ||
390
+ ['block', 'flex', 'grid', 'list-item', 'table', 'table-caption'].indexOf(
391
+ style.display
392
+ ) !== -1
393
+ ) {
394
+ text += ' '
395
+ }
396
+ } else {
397
+ text += node.textContent || ''
398
+ }
399
+ }
400
+ return normalizeWhitespace(text).trim()
401
+ }
402
+
276
403
  /**
277
404
  * Returns true if element.innerText excludes the text from inline SCRIPT and STYLE element. This
278
405
  * should be the case everywhere except on Internet Explorer 10 and 11 (see [1])
@@ -30,6 +30,8 @@ import { getSelectorFromElement } from './getSelectorsFromElement'
30
30
  // import { getSelectorsFromElement } from './getSelectorsFromElement'
31
31
  import { listenActionEvents } from './listenActionEvents'
32
32
  import { computeFrustration } from './computeFrustration'
33
+ import { NodePrivacyLevel } from '../../../constants'
34
+ import { getNodePrivacyLevel } from '../../privacy'
33
35
  import {
34
36
  CLICK_ACTION_MAX_DURATION,
35
37
  updateInteractionSelector
@@ -119,9 +121,17 @@ function processPointerDown(
119
121
  domMutationObservable,
120
122
  pointerDownEvent
121
123
  ) {
124
+ var target = getEventTarget(pointerDownEvent)
125
+ var nodePrivacyLevel = configuration.enablePrivacyForActionName
126
+ ? getNodePrivacyLevel(target, configuration.defaultPrivacyLevel)
127
+ : NodePrivacyLevel.ALLOW
128
+ if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
129
+ return
130
+ }
122
131
  var clickActionBase = computeClickActionBase(
123
132
  pointerDownEvent,
124
- configuration.actionNameAttribute
133
+ configuration,
134
+ nodePrivacyLevel
125
135
  )
126
136
 
127
137
  var hadActivityOnPointerDown = false
@@ -214,10 +224,13 @@ function startClickAction(
214
224
  })
215
225
  }
216
226
 
217
- function computeClickActionBase(event, actionNameAttribute) {
227
+ function computeClickActionBase(event, configuration, nodePrivacyLevel) {
218
228
  var target = getEventTarget(event)
219
229
  var rect = target.getBoundingClientRect()
220
- var selector = getSelectorFromElement(target, actionNameAttribute)
230
+ var selector = getSelectorFromElement(
231
+ target,
232
+ configuration.actionNameAttribute
233
+ )
221
234
  if (selector) {
222
235
  updateInteractionSelector(event.timeStamp, selector)
223
236
  }
@@ -234,8 +247,9 @@ function computeClickActionBase(event, actionNameAttribute) {
234
247
  },
235
248
  name: getActionNameFromElement(
236
249
  target,
237
- actionNameAttribute,
238
- target !== event.target
250
+ configuration,
251
+ target !== event.target,
252
+ nodePrivacyLevel
239
253
  )
240
254
  }
241
255
  }
@@ -243,6 +243,9 @@ function processRequest(request, pageStateHistory, requestResourceEntryMatcher)
243
243
  tracingInfo,
244
244
  correspondingTimingOverrides
245
245
  )
246
+ if (request.visitorId) {
247
+ resourceEvent.context = { visitor_id: request.visitorId }
248
+ }
246
249
  return {
247
250
  startTime: startClocks.relative,
248
251
  rawRumEvent: resourceEvent,
@@ -11,6 +11,7 @@ import {
11
11
  ViewLoadingType,
12
12
  LifeCycleEventType,
13
13
  PageExitReason,
14
+ SESSION_TIME_OUT_DELAY,
14
15
  isHashAnAnchor,
15
16
  getPathFromHash,
16
17
  noop,
@@ -43,6 +44,9 @@ export function trackViews(
43
44
  recorderApi
44
45
  ) {
45
46
  var eventBridgeAvailable = canUseEventBridge()
47
+ var maxViewDuration = eventBridgeAvailable
48
+ ? Infinity
49
+ : SESSION_TIME_OUT_DELAY
46
50
  var isWebViewActive =
47
51
  !eventBridgeAvailable ||
48
52
  (document.visibilityState !== 'hidden' && document.hasFocus())
@@ -64,7 +68,8 @@ export function trackViews(
64
68
  viewOptions,
65
69
  canMatchSoftNavigation,
66
70
  fallbackNavigationType,
67
- recorderApi
71
+ recorderApi,
72
+ maxViewDuration
68
73
  )
69
74
  activeViews.add(newlyCreatedView)
70
75
  newlyCreatedView.stopObservable.subscribe(function () {
@@ -136,9 +141,26 @@ export function trackViews(
136
141
  }
137
142
  lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, renewCurrentView)
138
143
 
139
- lifeCycle.subscribe(LifeCycleEventType.SESSION_EXPIRED, function () {
140
- currentView.end({ sessionIsActive: false })
141
- })
144
+ lifeCycle.subscribe(
145
+ LifeCycleEventType.SESSION_EXPIRED,
146
+ function (sessionExpirationTime) {
147
+ var sessionExpirationClocks
148
+ if (
149
+ typeof sessionExpirationTime === 'number' &&
150
+ sessionExpirationTime >= currentView.startClocks.timeStamp
151
+ ) {
152
+ const origin = clocksOrigin()
153
+ sessionExpirationClocks = {
154
+ relative: elapsed(origin.timeStamp, sessionExpirationTime),
155
+ timeStamp: sessionExpirationTime
156
+ }
157
+ }
158
+ currentView.end({
159
+ sessionIsActive: false,
160
+ endClocks: sessionExpirationClocks
161
+ })
162
+ }
163
+ )
142
164
 
143
165
  if (eventBridgeAvailable) {
144
166
  function updateWebViewLifecycle(event) {
@@ -235,7 +257,8 @@ function newView(
235
257
  viewOptions,
236
258
  canMatchSoftNavigation,
237
259
  fallbackNavigationType,
238
- recorderApi
260
+ recorderApi,
261
+ maxViewDuration
239
262
  ) {
240
263
  // Setup initial values
241
264
  if (startClocks === undefined) {
@@ -411,7 +434,10 @@ function newView(
411
434
  startClocks: startClocks,
412
435
  commonViewMetrics: getCommonViewMetrics(),
413
436
  initialViewMetrics: initialViewMetrics,
414
- duration: elapsed(startClocks.timeStamp, currentEnd),
437
+ duration: Math.min(
438
+ elapsed(startClocks.timeStamp, currentEnd),
439
+ maxViewDuration
440
+ ),
415
441
  isActive: endClocks === undefined,
416
442
  sessionIsActive: sessionIsActive,
417
443
  eventCounts: eventCounts
@@ -422,6 +448,7 @@ function newView(
422
448
  service: service,
423
449
  version: version,
424
450
  contextManager: contextManager,
451
+ startClocks: startClocks,
425
452
  stopObservable: stopObservable,
426
453
  end: function (options) {
427
454
  if (endClocks) {
@@ -43,8 +43,8 @@ export function startRumSessionManager(configuration, lifeCycle) {
43
43
  }
44
44
  )
45
45
 
46
- sessionManager.expireObservable.subscribe(function () {
47
- lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED)
46
+ sessionManager.expireObservable.subscribe(function (sessionExpirationTime) {
47
+ lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED, sessionExpirationTime)
48
48
  })
49
49
 
50
50
  sessionManager.renewObservable.subscribe(function () {
@@ -10,7 +10,9 @@ import {
10
10
  find,
11
11
  isMatchOption,
12
12
  matchList,
13
- isString
13
+ isString,
14
+ isRequest,
15
+ display
14
16
  } from '@cloudcare/browser-core'
15
17
  import { DDtraceTracer } from './ddtraceTracer'
16
18
  import { SkyWalkingTracer } from './skywalkingTracer'
@@ -45,7 +47,7 @@ export function startTracer(configuration, sessionManager) {
45
47
  sessionManager,
46
48
  function (tracingHeaders) {
47
49
  if (
48
- context.input instanceof Request &&
50
+ isRequest(context.input) &&
49
51
  (!context.init || !context.init.headers)
50
52
  ) {
51
53
  context.input = new Request(context.input)
@@ -160,6 +162,17 @@ export function injectHeadersIfTracingAllowed(
160
162
  if (getType(result) === 'object') {
161
163
  each(result, function (value, key) {
162
164
  if (getType(value) === 'string') {
165
+ if (
166
+ context.visitorId &&
167
+ configuration.visitorId &&
168
+ configuration.visitorId.enabled &&
169
+ key.toLowerCase() === configuration.visitorId.header
170
+ ) {
171
+ display.warn(
172
+ 'injectTraceHeader cannot overwrite the SDK-managed Visitor ID header.'
173
+ )
174
+ return
175
+ }
163
176
  headers[key] = value
164
177
  }
165
178
  })