@cloudcare/browser-rum 3.3.24 → 3.3.26

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 (209) hide show
  1. package/README.md +33 -0
  2. package/README.zh.md +30 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/disabledRumPublicApi.js +5 -0
  6. package/cjs/boot/disabledRumPublicApi.js.map +1 -1
  7. package/cjs/boot/initCallbacks.js +25 -0
  8. package/cjs/boot/initCallbacks.js.map +1 -0
  9. package/cjs/boot/perStartRum.js +99 -50
  10. package/cjs/boot/perStartRum.js.map +1 -1
  11. package/cjs/boot/recorderApi.js +36 -1
  12. package/cjs/boot/recorderApi.js.map +1 -1
  13. package/cjs/boot/rum.js +8 -9
  14. package/cjs/boot/rum.js.map +1 -1
  15. package/cjs/boot/rumPublicApi.js +6 -7
  16. package/cjs/boot/rumPublicApi.js.map +1 -1
  17. package/cjs/boot/startRecording.js +2 -0
  18. package/cjs/boot/startRecording.js.map +1 -1
  19. package/cjs/domain/configuration.js +15 -2
  20. package/cjs/domain/configuration.js.map +1 -1
  21. package/cjs/domain/contexts/urlContexts.js +32 -21
  22. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  23. package/cjs/domain/contexts/viewContexts.js +1 -1
  24. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  25. package/cjs/domain/deflate/deflateWorker.js +39 -27
  26. package/cjs/domain/deflate/deflateWorker.js.map +1 -1
  27. package/cjs/domain/privacy.js +79 -107
  28. package/cjs/domain/privacy.js.map +1 -1
  29. package/cjs/domain/replay/record/canvasCommandCapture.js +87 -179
  30. package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -1
  31. package/cjs/domain/replay/record/canvasCommandObserver.js +10 -6
  32. package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -1
  33. package/cjs/domain/replay/record/canvasCommandObserverStub.js +24 -0
  34. package/cjs/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  35. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +3 -2
  36. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  37. package/cjs/domain/replay/record/canvasContext.js +15 -0
  38. package/cjs/domain/replay/record/canvasContext.js.map +1 -1
  39. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  40. package/cjs/domain/replay/record/canvasObserver.js +3 -0
  41. package/cjs/domain/replay/record/canvasObserver.js.map +1 -1
  42. package/cjs/domain/replay/record/canvasWebGLPluginHost.js +5 -1
  43. package/cjs/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  44. package/cjs/domain/replay/record/mutationObserver.js +3 -12
  45. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  46. package/cjs/domain/replay/record/observers.js +3 -7
  47. package/cjs/domain/replay/record/observers.js.map +1 -1
  48. package/cjs/domain/replay/record/record.js +15 -2
  49. package/cjs/domain/replay/record/record.js.map +1 -1
  50. package/cjs/domain/replay/record/serializationUtils.js +8 -23
  51. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  52. package/cjs/domain/replay/record/serialize.js +19 -33
  53. package/cjs/domain/replay/record/serialize.js.map +1 -1
  54. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +21 -6
  55. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  56. package/cjs/domain/replay/segmentCollection/segmentCollection.js +91 -143
  57. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  58. package/cjs/domain/replayCanvasSupported.js +8 -0
  59. package/cjs/domain/replayCanvasSupported.js.map +1 -0
  60. package/cjs/domain/requestCollection.js +38 -39
  61. package/cjs/domain/requestCollection.js.map +1 -1
  62. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  63. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  64. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js +143 -0
  65. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  66. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  67. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  68. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +91 -66
  69. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  70. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js +11 -9
  71. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  72. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +35 -50
  73. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  74. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +7 -1
  75. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  76. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  77. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  78. package/cjs/domain/rumEventsCollection/view/trackViews.js +3 -0
  79. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  80. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -1
  81. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  82. package/cjs/domain/tracing/skywalkingTracer.js +4 -50
  83. package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
  84. package/cjs/domain/tracing/tracer.js +26 -3
  85. package/cjs/domain/tracing/tracer.js.map +1 -1
  86. package/esm/boot/buildEnv.js +1 -1
  87. package/esm/boot/disabledRumPublicApi.js +1 -1
  88. package/esm/boot/disabledRumPublicApi.js.map +1 -1
  89. package/esm/boot/initCallbacks.js +2 -0
  90. package/esm/boot/initCallbacks.js.map +1 -0
  91. package/esm/boot/perStartRum.js +1 -1
  92. package/esm/boot/perStartRum.js.map +1 -1
  93. package/esm/boot/recorderApi.js +1 -1
  94. package/esm/boot/recorderApi.js.map +1 -1
  95. package/esm/boot/rum.js +1 -1
  96. package/esm/boot/rum.js.map +1 -1
  97. package/esm/boot/rumPublicApi.js +1 -1
  98. package/esm/boot/rumPublicApi.js.map +1 -1
  99. package/esm/boot/startRecording.js +1 -1
  100. package/esm/boot/startRecording.js.map +1 -1
  101. package/esm/domain/configuration.js +1 -1
  102. package/esm/domain/configuration.js.map +1 -1
  103. package/esm/domain/contexts/urlContexts.js +1 -1
  104. package/esm/domain/contexts/urlContexts.js.map +1 -1
  105. package/esm/domain/contexts/viewContexts.js +1 -1
  106. package/esm/domain/contexts/viewContexts.js.map +1 -1
  107. package/esm/domain/deflate/deflateWorker.js +1 -1
  108. package/esm/domain/deflate/deflateWorker.js.map +1 -1
  109. package/esm/domain/privacy.js +1 -1
  110. package/esm/domain/privacy.js.map +1 -1
  111. package/esm/domain/replay/record/canvasCommandCapture.js +1 -1
  112. package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
  113. package/esm/domain/replay/record/canvasCommandObserver.js +1 -1
  114. package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
  115. package/esm/domain/replay/record/canvasCommandObserverStub.js +2 -0
  116. package/esm/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  117. package/esm/domain/replay/record/canvasCommandSerializeArgs.js +1 -1
  118. package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  119. package/esm/domain/replay/record/canvasContext.js +1 -1
  120. package/esm/domain/replay/record/canvasContext.js.map +1 -1
  121. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  122. package/esm/domain/replay/record/canvasObserver.js +1 -1
  123. package/esm/domain/replay/record/canvasObserver.js.map +1 -1
  124. package/esm/domain/replay/record/canvasWebGLPluginHost.js +1 -1
  125. package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  126. package/esm/domain/replay/record/mutationObserver.js +1 -1
  127. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  128. package/esm/domain/replay/record/observers.js +1 -1
  129. package/esm/domain/replay/record/observers.js.map +1 -1
  130. package/esm/domain/replay/record/record.js +1 -1
  131. package/esm/domain/replay/record/record.js.map +1 -1
  132. package/esm/domain/replay/record/serializationUtils.js +1 -1
  133. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  134. package/esm/domain/replay/record/serialize.js +1 -1
  135. package/esm/domain/replay/record/serialize.js.map +1 -1
  136. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
  137. package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  138. package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
  139. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  140. package/esm/domain/replayCanvasSupported.js +2 -0
  141. package/esm/domain/replayCanvasSupported.js.map +1 -0
  142. package/esm/domain/requestCollection.js +1 -1
  143. package/esm/domain/requestCollection.js.map +1 -1
  144. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  145. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  146. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js +2 -0
  147. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  148. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +1 -1
  149. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  150. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
  151. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  152. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js +1 -1
  153. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  154. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +1 -1
  155. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  156. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +1 -1
  157. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  158. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  159. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  160. package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
  161. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  162. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -1
  163. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  164. package/esm/domain/tracing/skywalkingTracer.js +1 -1
  165. package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
  166. package/esm/domain/tracing/tracer.js +1 -1
  167. package/esm/domain/tracing/tracer.js.map +1 -1
  168. package/package.json +7 -7
  169. package/src/boot/disabledRumPublicApi.js +5 -0
  170. package/src/boot/initCallbacks.js +16 -0
  171. package/src/boot/perStartRum.js +102 -59
  172. package/src/boot/recorderApi.js +51 -2
  173. package/src/boot/rum.js +12 -18
  174. package/src/boot/rumPublicApi.js +6 -8
  175. package/src/boot/startRecording.js +2 -0
  176. package/src/domain/configuration.js +13 -2
  177. package/src/domain/contexts/urlContexts.js +34 -27
  178. package/src/domain/contexts/viewContexts.js +2 -2
  179. package/src/domain/deflate/deflateWorker.js +35 -21
  180. package/src/domain/privacy.js +93 -157
  181. package/src/domain/replay/record/canvasCommandCapture.js +102 -239
  182. package/src/domain/replay/record/canvasCommandObserver.js +11 -18
  183. package/src/domain/replay/record/canvasCommandObserverStub.js +11 -0
  184. package/src/domain/replay/record/canvasCommandSerializeArgs.js +2 -2
  185. package/src/domain/replay/record/canvasContext.js +18 -0
  186. package/src/domain/replay/record/canvasObserver.js +5 -1
  187. package/src/domain/replay/record/canvasWebGLPluginHost.js +4 -1
  188. package/src/domain/replay/record/mutationObserver.js +6 -22
  189. package/src/domain/replay/record/observers.js +4 -8
  190. package/src/domain/replay/record/record.js +20 -5
  191. package/src/domain/replay/record/serializationUtils.js +10 -33
  192. package/src/domain/replay/record/serialize.js +30 -38
  193. package/src/domain/replay/segmentCollection/buildReplayPayload.js +24 -14
  194. package/src/domain/replay/segmentCollection/segmentCollection.js +97 -227
  195. package/src/domain/replayCanvasSupported.js +1 -0
  196. package/src/domain/requestCollection.js +39 -51
  197. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +8 -2
  198. package/src/domain/rumEventsCollection/resource/fetchTimingRegistry.js +138 -0
  199. package/src/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  200. package/src/domain/rumEventsCollection/resource/resourceCollection.js +103 -88
  201. package/src/domain/rumEventsCollection/resource/resourceTrackerManager.js +10 -10
  202. package/src/domain/rumEventsCollection/resource/resourceUtils.js +41 -69
  203. package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +8 -2
  204. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  205. package/src/domain/rumEventsCollection/view/trackViews.js +3 -0
  206. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -3
  207. package/src/domain/tracing/skywalkingTracer.js +14 -91
  208. package/src/domain/tracing/tracer.js +28 -4
  209. package/types/index.d.ts +9 -0
@@ -1,3 +1,4 @@
1
+ import { replayCanvasSupported } from './replayCanvasSupported'
1
2
  import {
2
3
  assign,
3
4
  display,
@@ -23,6 +24,16 @@ import { isTracingOption } from '../domain/tracing/tracer'
23
24
  import { validatePlugins } from './plugins'
24
25
  import { DEFAULT_VISITOR_ID_TTL_HOURS } from './visitorId'
25
26
 
27
+ // The WebGL addon can install capture hooks in onInit, before configuration
28
+ // validation. Give plugins the capabilities of the selected bundle up front.
29
+ export function prepareReplayCanvasConfiguration(initConfiguration) {
30
+ if (!replayCanvasSupported && initConfiguration.replayCanvasEnabled) {
31
+ display.warn('Use dataflux-rum.js for Canvas replay.')
32
+ return assign({}, initConfiguration, { replayCanvasEnabled: false })
33
+ }
34
+ return initConfiguration
35
+ }
36
+
26
37
  var REPLAY_CANVAS_QUALITY_PRESETS = {
27
38
  low: {
28
39
  quality: 0.25,
@@ -350,8 +361,8 @@ export function validateAndBuildRumConfiguration(initConfiguration) {
350
361
  enableLongAnimationFrame: !!initConfiguration.enableLongAnimationFrame,
351
362
  trackViewsManually: !!initConfiguration.trackViewsManually,
352
363
  plugins: initConfiguration.plugins || [],
353
- sessionReplayWebGL: initConfiguration.sessionReplayWebGL,
354
- replayCanvasEnabled: !!initConfiguration.replayCanvasEnabled,
364
+ sessionReplayWebGL: replayCanvasSupported ? initConfiguration.sessionReplayWebGL : undefined,
365
+ replayCanvasEnabled: replayCanvasSupported && !!initConfiguration.replayCanvasEnabled,
355
366
  replayCanvasMode: replayCanvasMode,
356
367
  replayCanvasSampling: replayCanvasSampling,
357
368
  replayCanvasQuality: isNullUndefinedDefaultValue(
@@ -7,11 +7,16 @@ import {
7
7
  replaceNumberCharByPath,
8
8
  getQueryParamsFromUrl,
9
9
  getURLSearchParams,
10
- isHashAnAnchor,
11
10
  getPathFromHash,
12
11
  buildUrl
13
12
  } from '@cloudcare/browser-core'
14
13
 
14
+ function withoutDocumentQuery(href) {
15
+ var url = buildUrl(href)
16
+ url.search = ''
17
+ return url
18
+ }
19
+
15
20
  /**
16
21
  * We want to attach to an event:
17
22
  * - the url corresponding to its start
@@ -29,28 +34,27 @@ export function startUrlContexts(
29
34
  expireDelay: URL_CONTEXT_TIME_OUT_DELAY
30
35
  })
31
36
 
37
+ var excludeHashRouteOuterQuery
32
38
  var previousViewUrl
33
39
 
34
40
  lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, function (data) {
35
- var viewUrl = location.href
41
+ excludeHashRouteOuterQuery = data.excludeHashRouteOuterQuery
36
42
  var viewLocation = location
37
43
  if (data.url) {
38
44
  try {
39
45
  viewLocation = buildUrl(data.url, location.href)
40
- viewUrl = viewLocation.href
41
46
  } catch (error) {
42
47
  // Fall back to the browser location for invalid framework URLs.
43
48
  }
44
49
  }
45
- urlContextHistory.add(
46
- buildUrlContext({
47
- url: viewUrl,
48
- location: viewLocation,
49
- referrer: !previousViewUrl ? document.referrer : previousViewUrl
50
- }),
51
- data.startClocks.relative
52
- )
53
- previousViewUrl = viewUrl
50
+ var referrer = previousViewUrl || document.referrer
51
+ if (!previousViewUrl && referrer && excludeHashRouteOuterQuery) {
52
+ // Browsers omit the source fragment, so its routing mode is unknown.
53
+ referrer = withoutDocumentQuery(referrer).href
54
+ }
55
+ var context = buildUrlContext(viewLocation, referrer)
56
+ urlContextHistory.add(context, data.startClocks.relative)
57
+ previousViewUrl = context.url
54
58
  })
55
59
  lifeCycle.subscribe(LifeCycleEventType.AFTER_VIEW_ENDED, function (data) {
56
60
  urlContextHistory.closeActive(data.endClocks.relative)
@@ -63,33 +67,33 @@ export function startUrlContexts(
63
67
  var changeTime = relativeNow()
64
68
  urlContextHistory.closeActive(changeTime)
65
69
  urlContextHistory.add(
66
- buildUrlContext(
67
- {
68
- url: data.newLocation.href,
69
- location: data.newLocation,
70
- referrer: current.referrer
71
- },
72
- true
73
- ),
70
+ buildUrlContext(data.newLocation, current.referrer),
74
71
  changeTime
75
72
  )
76
73
  }
77
74
  })
78
75
 
79
- function buildUrlContext(data, isLocationChange = false) {
80
- var pathname = data.location.pathname
76
+ function getViewLocation(viewLocation) {
77
+ return excludeHashRouteOuterQuery && viewLocation.hash?.indexOf('#/') === 0
78
+ ? withoutDocumentQuery(viewLocation.href)
79
+ : viewLocation
80
+ }
81
+
82
+ function buildUrlContext(viewLocation, referrer) {
83
+ viewLocation = getViewLocation(viewLocation)
84
+ var pathname = viewLocation.pathname
81
85
  var path = pathname
82
- var hash = data.location.hash
86
+ var hash = viewLocation.hash
83
87
  if (hash && hash.indexOf('#/') === 0) {
84
88
  path = '/' + getPathFromHash(hash)
85
89
  }
86
90
  return {
87
- url: data.url,
88
- referrer: data.referrer,
89
- host: data.location.host,
91
+ url: viewLocation.href,
92
+ referrer,
93
+ host: viewLocation.host,
90
94
  path: path,
91
95
  pathGroup: replaceNumberCharByPath(path),
92
- urlQuery: getLocationQuery(data.location),
96
+ urlQuery: getLocationQuery(viewLocation),
93
97
  pathname: pathname
94
98
  }
95
99
  }
@@ -109,6 +113,9 @@ export function startUrlContexts(
109
113
  }
110
114
 
111
115
  return {
116
+ $rGetDocumentUrl: function () {
117
+ return getViewLocation(location).href
118
+ },
112
119
  findUrl: function (startTime) {
113
120
  return urlContextHistory.find(startTime)
114
121
  },
@@ -2,7 +2,7 @@ import {
2
2
  SESSION_TIME_OUT_DELAY,
3
3
  createValueHistory,
4
4
  LifeCycleEventType,
5
- urlParse
5
+ getUrlParts
6
6
  } from '@cloudcare/browser-core'
7
7
 
8
8
  export var VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY
@@ -39,7 +39,7 @@ export function startViewContexts(lifeCycle) {
39
39
  context: view.context,
40
40
  id: view.id,
41
41
  name: view.name,
42
- path: urlParse(view.url || location.href).getParse().Path,
42
+ path: getUrlParts(view.url || location.href).Path,
43
43
  startClocks: view.startClocks
44
44
  }
45
45
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  display,
3
+ monitor,
3
4
  includes,
4
5
  setTimeout,
5
6
  clearTimeout,
@@ -10,6 +11,7 @@ import {
10
11
 
11
12
  export var INITIALIZATION_TIME_OUT_DELAY = 10 * ONE_SECOND
12
13
  var workerObjectUrls = new WeakMap()
14
+ const logWorkerError = monitor((...args) => display.error(...args))
13
15
 
14
16
  export function createDeflateWorker(configuration) {
15
17
  if (configuration.workerUrl) {
@@ -56,7 +58,8 @@ export function createDeflateWorkerController() {
56
58
  configuration,
57
59
  source,
58
60
  onInitializationFailure,
59
- createDeflateWorkerImpl
61
+ createDeflateWorkerImpl,
62
+ onInitializationSuccess
60
63
  ) {
61
64
  if (!__BUILD_ENV__REPLAY_DEBUG_ENABLED__) {
62
65
  createDeflateWorkerImpl = createDeflateWorker
@@ -69,11 +72,17 @@ export function createDeflateWorkerController() {
69
72
  switch (state.status) {
70
73
  case DeflateWorkerStatus.Loading:
71
74
  state.initializationFailureCallbacks.push(onInitializationFailure)
75
+ if (onInitializationSuccess) {
76
+ state.initializationSuccessCallbacks.push(onInitializationSuccess)
77
+ }
72
78
  return state.worker
73
79
  case DeflateWorkerStatus.Initialized:
80
+ if (onInitializationSuccess) {
81
+ onInitializationSuccess()
82
+ }
74
83
  return state.worker
75
84
  case DeflateWorkerStatus.Error:
76
- onInitializationFailure()
85
+ onInitializationFailure(state.message)
77
86
  return undefined
78
87
  }
79
88
  }
@@ -133,7 +142,8 @@ export function createDeflateWorkerController() {
133
142
  worker: worker,
134
143
  stop: stop,
135
144
  initializationTimeoutId: undefined,
136
- initializationFailureCallbacks: []
145
+ initializationFailureCallbacks: [],
146
+ initializationSuccessCallbacks: []
137
147
  }
138
148
 
139
149
  errorListener = addEventListener(worker, 'error', function (error) {
@@ -163,21 +173,26 @@ export function createDeflateWorkerController() {
163
173
 
164
174
  function onTimeout(source) {
165
175
  if (state.status === DeflateWorkerStatus.Loading) {
166
- const loadingState = state
167
- display.error(
176
+ logWorkerError(
168
177
  source +
169
178
  ' failed to start: a timeout occurred while initializing the Worker'
170
179
  )
171
- loadingState.stop()
172
- state = { status: DeflateWorkerStatus.Error }
173
- loadingState.initializationFailureCallbacks.forEach(function (callback) {
174
- callback()
175
- })
180
+ failWorker('Compression Worker handshake timed out after 10 seconds.')
181
+ }
182
+ }
183
+
184
+ function failWorker(message) {
185
+ const loading = state
186
+ state = { status: DeflateWorkerStatus.Error, message }
187
+ if (loading.status === DeflateWorkerStatus.Loading) {
188
+ loading.stop()
189
+ loading.initializationFailureCallbacks.forEach(callback => callback(message))
176
190
  }
177
191
  }
178
192
 
179
193
  function onInitialized(version) {
180
194
  if (state.status === DeflateWorkerStatus.Loading) {
195
+ var callbacks = state.initializationSuccessCallbacks
181
196
  clearTimeout(state.initializationTimeoutId)
182
197
  revokeDeflateWorkerObjectUrl(state.worker)
183
198
  state = {
@@ -186,13 +201,14 @@ export function createDeflateWorkerController() {
186
201
  version: version,
187
202
  stop: state.stop
188
203
  }
204
+ callbacks.forEach(function (callback) { callback() })
189
205
  }
190
206
  }
191
207
 
192
208
  function onError(configuration, source, error, streamId) {
209
+ const detail = typeof error === 'string' ? error : error?.message
193
210
  if (state.status === DeflateWorkerStatus.Loading) {
194
- const loadingState = state
195
- display.error(
211
+ logWorkerError(
196
212
  source +
197
213
  ' failed to start: an error occurred while creating the Worker:',
198
214
  error
@@ -209,15 +225,11 @@ export function createDeflateWorkerController() {
209
225
  } else {
210
226
  baseMessage = 'Please make sure CSP is correctly configured.'
211
227
  }
212
- display.error(baseMessage)
228
+ logWorkerError(baseMessage)
213
229
  } else {
214
230
  addTelemetryError(error)
215
231
  }
216
- loadingState.stop()
217
- state = { status: DeflateWorkerStatus.Error }
218
- loadingState.initializationFailureCallbacks.forEach(function (callback) {
219
- callback()
220
- })
232
+ failWorker(detail || 'The compression Worker reported an error during its handshake.')
221
233
  } else {
222
234
  addTelemetryError(error, {
223
235
  worker_version:
@@ -225,7 +237,7 @@ export function createDeflateWorkerController() {
225
237
  stream_id: streamId
226
238
  })
227
239
  if (state.status === DeflateWorkerStatus.Nil) {
228
- state = { status: DeflateWorkerStatus.Error }
240
+ failWorker(detail || 'Unable to create the compression Worker.')
229
241
  }
230
242
  }
231
243
  }
@@ -246,13 +258,15 @@ export function startDeflateWorker(
246
258
  configuration,
247
259
  source,
248
260
  onInitializationFailure,
249
- createDeflateWorkerImpl
261
+ createDeflateWorkerImpl,
262
+ onInitializationSuccess
250
263
  ) {
251
264
  return sharedDeflateWorkerController.start(
252
265
  configuration,
253
266
  source,
254
267
  onInitializationFailure,
255
- createDeflateWorkerImpl
268
+ createDeflateWorkerImpl,
269
+ onInitializationSuccess
256
270
  )
257
271
  }
258
272
 
@@ -7,14 +7,6 @@ import {
7
7
  import {
8
8
  NodePrivacyLevel,
9
9
  PRIVACY_ATTR_NAME,
10
- PRIVACY_ATTR_VALUE_ALLOW,
11
- PRIVACY_ATTR_VALUE_MASK,
12
- PRIVACY_ATTR_VALUE_MASK_USER_INPUT,
13
- PRIVACY_ATTR_VALUE_HIDDEN,
14
- PRIVACY_CLASS_ALLOW,
15
- PRIVACY_CLASS_MASK,
16
- PRIVACY_CLASS_MASK_USER_INPUT,
17
- PRIVACY_CLASS_HIDDEN,
18
10
  FORM_PRIVATE_TAG_NAMES,
19
11
  CENSORED_STRING_MARK
20
12
  } from '../constants'
@@ -30,7 +22,7 @@ export var MAX_PRIVACY_ANCESTOR_DEPTH = 1000
30
22
  *
31
23
  * derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel)
32
24
  */
33
- export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache) {
25
+ export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache, selector) {
34
26
  if (cache && cache.has(node)) {
35
27
  return cache.get(node)
36
28
  }
@@ -39,19 +31,26 @@ export function getNodePrivacyLevel(node, defaultPrivacyLevel, cache) {
39
31
  // JavaScript stack. If the watermark is crossed, fail closed: hiding the
40
32
  // branch is safer than spending unbounded time resolving its privacy chain.
41
33
  var unresolvedNodes = []
42
- var currentNode = node
43
34
  var inheritedPrivacyLevel
44
- while (currentNode) {
35
+ var depth = 0
36
+ var match
37
+ for (var currentNode = node; currentNode; currentNode = getParentNode(currentNode)) {
45
38
  if (cache && cache.has(currentNode)) {
46
39
  inheritedPrivacyLevel = cache.get(currentNode)
47
40
  break
48
41
  }
49
- if (unresolvedNodes.length >= MAX_PRIVACY_ANCESTOR_DEPTH) {
42
+ if (depth++ >= MAX_PRIVACY_ANCESTOR_DEPTH) {
50
43
  inheritedPrivacyLevel = NodePrivacyLevel.HIDDEN
51
44
  break
52
45
  }
46
+ // Canvas draws only need the elements that can change privacy. Keep counting
47
+ // skipped ancestors and restart native matching when crossing a shadow root.
48
+ if (selector && typeof currentNode.closest === 'function') {
49
+ if (match === undefined) match = currentNode.closest(selector)
50
+ if (currentNode !== match) continue
51
+ }
53
52
  unresolvedNodes.push(currentNode)
54
- currentNode = getParentNode(currentNode)
53
+ match = undefined
55
54
  }
56
55
  if (inheritedPrivacyLevel === undefined) {
57
56
  inheritedPrivacyLevel = defaultPrivacyLevel
@@ -92,6 +91,9 @@ export function reducePrivacyLevel(childPrivacyLevel, parentNodePrivacyLevel) {
92
91
  }
93
92
  }
94
93
 
94
+ // Explicit privacy attributes and their class aliases use the same level names.
95
+ var overridablePrivacyLevels = [NodePrivacyLevel.MASK, NodePrivacyLevel.MASK_USER_INPUT, NodePrivacyLevel.ALLOW]
96
+
95
97
  /**
96
98
  * Determines the node's own privacy level without checking for ancestors.
97
99
  */
@@ -103,58 +105,34 @@ export function getNodeSelfPrivacyLevel(node) {
103
105
 
104
106
  var privAttr = node.getAttribute(PRIVACY_ATTR_NAME)
105
107
 
108
+ function matchesPrivacyLevel(level) {
109
+ return privAttr === level || node.classList.contains('gc-privacy-' + level)
110
+ }
111
+
106
112
  // Overrules for replay purpose
107
113
  if (node.tagName === 'BASE') {
108
114
  return NodePrivacyLevel.ALLOW
109
115
  }
110
116
 
117
+ if (matchesPrivacyLevel(NodePrivacyLevel.HIDDEN)) {
118
+ return NodePrivacyLevel.HIDDEN
119
+ }
120
+
111
121
  // Overrules to enforce end-user protection
112
- if (node.tagName === 'INPUT') {
113
- var inputElement = node
114
- if (
115
- inputElement.type === 'password' ||
116
- inputElement.type === 'email' ||
117
- inputElement.type === 'tel'
118
- ) {
119
- return NodePrivacyLevel.MASK
120
- }
121
- if (inputElement.type === 'hidden') {
122
+ if (node.localName === 'input') {
123
+ if (/^(password|email|tel|hidden)$/.test(node.type)) {
122
124
  return NodePrivacyLevel.MASK
123
125
  }
124
- var autocomplete = inputElement.getAttribute('autocomplete')
126
+ var autocomplete = node.getAttribute('autocomplete')
125
127
  // Handle input[autocomplete=cc-number/cc-csc/cc-exp/cc-exp-month/cc-exp-year]
126
- if (autocomplete && autocomplete.indexOf('cc-') === 0) {
128
+ if (autocomplete && /(?:^|[\t\n\f\r ])cc-/i.test(autocomplete)) {
127
129
  return NodePrivacyLevel.MASK
128
130
  }
129
131
  }
130
132
 
131
- // Check HTML privacy attributes and classes
132
- if (
133
- privAttr === PRIVACY_ATTR_VALUE_HIDDEN ||
134
- node.classList.contains(PRIVACY_CLASS_HIDDEN)
135
- ) {
136
- return NodePrivacyLevel.HIDDEN
137
- }
138
-
139
- if (
140
- privAttr === PRIVACY_ATTR_VALUE_MASK ||
141
- node.classList.contains(PRIVACY_CLASS_MASK)
142
- ) {
143
- return NodePrivacyLevel.MASK
144
- }
145
-
146
- if (
147
- privAttr === PRIVACY_ATTR_VALUE_MASK_USER_INPUT ||
148
- node.classList.contains(PRIVACY_CLASS_MASK_USER_INPUT)
149
- ) {
150
- return NodePrivacyLevel.MASK_USER_INPUT
151
- }
152
-
153
- if (
154
- privAttr === PRIVACY_ATTR_VALUE_ALLOW ||
155
- node.classList.contains(PRIVACY_CLASS_ALLOW)
156
- ) {
157
- return NodePrivacyLevel.ALLOW
133
+ for (var i = 0; i < overridablePrivacyLevels.length; i++) {
134
+ var level = overridablePrivacyLevels[i]
135
+ if (matchesPrivacyLevel(level)) return level
158
136
  }
159
137
 
160
138
  if (shouldIgnoreElement(node)) {
@@ -168,7 +146,7 @@ export function getNodeSelfPrivacyLevel(node) {
168
146
  * In the `mask` case, it is trivial: we should mask the element.
169
147
  *
170
148
  * In the `mask-user-input` case, we should mask the element only if it is a "form" element or the
171
- * direct parent is a form element for text nodes).
149
+ * text belongs to an editable region).
172
150
  *
173
151
  * Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a
174
152
  * node if it is ignored or hidden? it doesn't matter since it won't be serialized).
@@ -184,30 +162,26 @@ export function shouldMaskNode(configuration, node, privacyLevel) {
184
162
  case NodePrivacyLevel.HIDDEN:
185
163
  case NodePrivacyLevel.IGNORE:
186
164
  return true
187
- case NodePrivacyLevel.MASK_USER_INPUT:
188
- return isTextNode(node)
189
- ? isFormElement(node.parentNode)
190
- : isFormElement(node)
165
+ case NodePrivacyLevel.MASK_USER_INPUT: {
166
+ var element = isTextNode(node) ? node.parentElement : node
167
+ return !!(element && (element.isContentEditable || isFormElement(element)))
168
+ }
191
169
  default:
192
170
  return false
193
171
  }
194
172
  }
195
173
 
174
+ export function getElementTagName(node) {
175
+ // Named form controls can shadow the form's tagName property.
176
+ return typeof node.tagName === 'string' ? node.tagName : 'FORM'
177
+ }
178
+
196
179
  function isFormElement(node) {
197
- if (!node || node.nodeType !== node.ELEMENT_NODE) {
198
- return false
180
+ var tagName = getElementTagName(node).toUpperCase()
181
+ if (tagName === 'INPUT') {
182
+ return !/^(button|color|reset|submit)$/.test(node.type)
199
183
  }
200
- var element = node
201
- if (element.tagName === 'INPUT') {
202
- switch (element.type) {
203
- case 'button':
204
- case 'color':
205
- case 'reset':
206
- case 'submit':
207
- return false
208
- }
209
- }
210
- return !!FORM_PRIVATE_TAG_NAMES[element.tagName]
184
+ return !!FORM_PRIVATE_TAG_NAMES[tagName]
211
185
  }
212
186
 
213
187
  /**
@@ -224,64 +198,56 @@ export function getTextContent(
224
198
  ignoreWhiteSpace,
225
199
  parentNodePrivacyLevel
226
200
  ) {
227
- // The parent node may not be a html element which has a tagName attribute.
228
- // So just let it be undefined which is ok in this use case.
229
- var parentTagName = textNode.parentElement && textNode.parentElement.tagName
230
- var textContent = textNode.textContent || ''
231
-
232
- if (ignoreWhiteSpace && !textContent.trim()) {
233
- return
201
+ var parent = textNode.parentElement
202
+ var tagName = parent && parent.localName
203
+ var text = textNode.textContent || ''
204
+ if (ignoreWhiteSpace && !text.trim()) return
205
+ if (tagName === 'script' || parentNodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
206
+ return CENSORED_STRING_MARK
234
207
  }
235
-
236
- var nodePrivacyLevel = parentNodePrivacyLevel
237
-
238
- // var isStyle = parentTagName === 'STYLE' ? true : undefined
239
- var isScript = parentTagName === 'SCRIPT'
240
-
241
- if (isScript) {
242
- // For perf reasons, we don't record script (heuristic)
243
- textContent = CENSORED_STRING_MARK
244
- } else if (nodePrivacyLevel === NodePrivacyLevel.HIDDEN) {
245
- // Should never occur, but just in case, we set to CENSORED_MARK.
246
- textContent = CENSORED_STRING_MARK
247
- } else if (shouldMaskNode(configuration, textNode, nodePrivacyLevel)) {
248
- if (
249
- // Scrambling the child list breaks text nodes for DATALIST/SELECT/OPTGROUP
250
- parentTagName === 'DATALIST' ||
251
- parentTagName === 'SELECT' ||
252
- parentTagName === 'OPTGROUP'
253
- ) {
254
- if (!textContent.trim()) {
255
- return
256
- }
257
- } else if (parentTagName === 'OPTION') {
258
- // <Option> has low entropy in charset + text length, so use `CENSORED_STRING_MARK` when masked
259
- textContent = CENSORED_STRING_MARK
260
- } else {
261
- textContent = censorText(textContent)
208
+ // Option and textarea text can itself be the control's value.
209
+ var control = parent && closestTextControl(parent)
210
+ if (control) {
211
+ var controlPrivacyLevel = control === parent
212
+ ? parentNodePrivacyLevel
213
+ : getNodePrivacyLevel(control, configuration.defaultPrivacyLevel || parentNodePrivacyLevel)
214
+ if (shouldMaskNode(configuration, control, controlPrivacyLevel)) {
215
+ return control.localName === 'option' ? CENSORED_STRING_MARK : censorText(text)
262
216
  }
263
217
  }
264
- // else if (isStyle && textContent) {
265
- // try {
266
- // // try to read style sheet
267
- // if (textNode.nextSibling || textNode.previousSibling) {
268
- // // This is not the only child of the stylesheet.
269
- // // We can't read all of the sheet's .cssRules and expect them
270
- // // to _only_ include the current rule(s) added by the text node.
271
- // // So we'll be conservative and keep textContent as-is.
272
- // } else if (
273
- // textNode.parentNode &&
274
- // textNode.parentNode.sheet &&
275
- // textNode.parentNode.sheet.cssRules
276
- // ) {
277
- // textContent = getCssRulesString(textNode.parentNode.sheet)
278
- // }
279
- // } catch (err) {}
280
- // textContent = switchToAbsoluteUrl(textContent, getHref())
281
- // }
282
- return textContent
218
+ if (!shouldMaskNode(configuration, textNode, parentNodePrivacyLevel)) {
219
+ return text
220
+ }
221
+ switch (tagName) {
222
+ case 'datalist':
223
+ case 'select':
224
+ case 'optgroup':
225
+ return text.trim() ? text : undefined
226
+ case 'option':
227
+ return CENSORED_STRING_MARK
228
+ default:
229
+ return censorText(text)
230
+ }
231
+ }
232
+
233
+ function closestTextControl(element) {
234
+ if (Element.prototype.closest) {
235
+ return Element.prototype.closest.call(element, 'option,textarea')
236
+ }
237
+ while (element && element.localName !== 'option' && element.localName !== 'textarea') {
238
+ element = element.parentElement
239
+ }
240
+ return element
283
241
  }
284
242
 
243
+ var ignoredMetaNames = [
244
+ 'msapplication-tileimage', 'msapplication-tilecolor', 'application-name',
245
+ 'keywords', 'description', 'pinterest', 'robots', 'googlebot', 'bingbot',
246
+ 'author', 'generator', 'framework', 'publisher', 'progid',
247
+ 'google-site-verification', 'yandex-verification', 'csrf-token',
248
+ 'p:domain_verify', 'verify-v1', 'verification', 'shopify-checkout-api-token'
249
+ ]
250
+
285
251
  /**
286
252
  * We don't need this logic on the recorder side.
287
253
  * For security related meta's, customer can mask themmanually given they
@@ -307,44 +273,14 @@ export function shouldIgnoreElement(element) {
307
273
  if (element.nodeName === 'META') {
308
274
  var nameAttribute = getLowerCaseAttribute('name')
309
275
  var relAttribute = getLowerCaseAttribute('rel')
310
- var propertyAttribute = getLowerCaseAttribute('property')
311
276
  return (
312
- // Favicons
313
- /^msapplication-tile(image|color)$/.test(nameAttribute) ||
314
- nameAttribute === 'application-name' ||
277
+ ignoredMetaNames.indexOf(nameAttribute) !== -1 ||
278
+ /^(og|twitter):/.test(nameAttribute) ||
279
+ /^(og|twitter|fb|article|product):/.test(getLowerCaseAttribute('property')) ||
315
280
  relAttribute === 'icon' ||
316
281
  relAttribute === 'apple-touch-icon' ||
317
282
  relAttribute === 'shortcut icon' ||
318
- // Description
319
- nameAttribute === 'keywords' ||
320
- nameAttribute === 'description' ||
321
- // Social
322
- /^(og|twitter|fb):/.test(propertyAttribute) ||
323
- /^(og|twitter):/.test(nameAttribute) ||
324
- nameAttribute === 'pinterest' ||
325
- // Robots
326
- nameAttribute === 'robots' ||
327
- nameAttribute === 'googlebot' ||
328
- nameAttribute === 'bingbot' ||
329
- // Http headers. Ex: X-UA-Compatible, Content-Type, Content-Language, cache-control,
330
- // X-Translated-By
331
- element.hasAttribute('http-equiv') ||
332
- // Authorship
333
- nameAttribute === 'author' ||
334
- nameAttribute === 'generator' ||
335
- nameAttribute === 'framework' ||
336
- nameAttribute === 'publisher' ||
337
- nameAttribute === 'progid' ||
338
- /^article:/.test(propertyAttribute) ||
339
- /^product:/.test(propertyAttribute) ||
340
- // Verification
341
- nameAttribute === 'google-site-verification' ||
342
- nameAttribute === 'yandex-verification' ||
343
- nameAttribute === 'csrf-token' ||
344
- nameAttribute === 'p:domain_verify' ||
345
- nameAttribute === 'verify-v1' ||
346
- nameAttribute === 'verification' ||
347
- nameAttribute === 'shopify-checkout-api-token'
283
+ element.hasAttribute('http-equiv')
348
284
  )
349
285
  }
350
286