@newrelic/browser-agent 1.263.0 → 1.265.0

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 (478) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/cdn/experimental.js +3 -7
  4. package/dist/cjs/cdn/pro.js +2 -2
  5. package/dist/cjs/cdn/spa.js +2 -2
  6. package/dist/cjs/common/aggregate/aggregator.js +2 -3
  7. package/dist/cjs/common/config/{state/configurable.js → configurable.js} +1 -1
  8. package/dist/cjs/common/config/{state/info.js → info.js} +1 -1
  9. package/dist/cjs/common/config/{state/init.js → init.js} +11 -8
  10. package/dist/cjs/common/config/{state/loader-config.js → loader-config.js} +1 -1
  11. package/dist/cjs/common/config/{state/runtime.js → runtime.js} +16 -5
  12. package/dist/cjs/common/constants/agent-constants.js +8 -0
  13. package/dist/cjs/common/constants/env.cdn.js +1 -1
  14. package/dist/cjs/common/constants/env.npm.js +1 -1
  15. package/dist/cjs/common/constants/runtime.js +1 -3
  16. package/dist/cjs/common/context/shared-context.js +1 -2
  17. package/dist/cjs/common/dispatch/global-event.js +1 -2
  18. package/dist/cjs/common/drain/drain.js +12 -18
  19. package/dist/cjs/common/event-emitter/contextual-ee.js +3 -4
  20. package/dist/cjs/common/event-listener/event-listener-opts.js +2 -6
  21. package/dist/cjs/common/harvest/harvest-scheduler.js +1 -2
  22. package/dist/cjs/common/harvest/harvest.js +30 -57
  23. package/dist/cjs/common/serialize/bel-serializer.js +6 -11
  24. package/dist/cjs/common/session/session-entity.js +10 -13
  25. package/dist/cjs/common/timing/nav-timing.js +1 -3
  26. package/dist/cjs/common/timing/time-keeper.js +16 -6
  27. package/dist/cjs/common/url/encode.js +3 -7
  28. package/dist/cjs/common/util/console.js +2 -0
  29. package/dist/cjs/common/util/invoke.js +6 -16
  30. package/dist/cjs/common/util/obfuscate.js +97 -53
  31. package/dist/cjs/common/util/submit-data.js +17 -21
  32. package/dist/cjs/common/util/text.js +9 -0
  33. package/dist/cjs/common/util/traverse.js +1 -3
  34. package/dist/cjs/common/vitals/cumulative-layout-shift.js +5 -6
  35. package/dist/cjs/common/vitals/first-contentful-paint.js +4 -5
  36. package/dist/cjs/common/vitals/first-input-delay.js +4 -5
  37. package/dist/cjs/common/vitals/interaction-to-next-paint.js +5 -6
  38. package/dist/cjs/common/vitals/largest-contentful-paint.js +4 -5
  39. package/dist/cjs/common/vitals/time-to-first-byte.js +4 -5
  40. package/dist/cjs/common/vitals/vital-metric.js +5 -7
  41. package/dist/cjs/common/window/nreum.js +2 -1
  42. package/dist/cjs/common/window/page-visibility.js +1 -4
  43. package/dist/cjs/common/wrap/wrap-events.js +1 -4
  44. package/dist/cjs/common/wrap/wrap-promise.js +1 -4
  45. package/dist/cjs/common/wrap/wrap-websocket.js +74 -0
  46. package/dist/cjs/features/ajax/aggregate/chunk.js +4 -3
  47. package/dist/cjs/features/ajax/aggregate/gql.js +4 -5
  48. package/dist/cjs/features/ajax/aggregate/index.js +19 -22
  49. package/dist/cjs/features/ajax/constants.js +2 -3
  50. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +9 -8
  51. package/dist/cjs/features/ajax/instrument/index.js +14 -12
  52. package/dist/cjs/features/generic_events/aggregate/index.js +128 -0
  53. package/dist/cjs/features/generic_events/constants.js +10 -0
  54. package/dist/cjs/features/generic_events/index.js +12 -0
  55. package/dist/cjs/features/generic_events/instrument/index.js +27 -0
  56. package/dist/cjs/features/jserrors/aggregate/index.js +25 -44
  57. package/dist/cjs/features/jserrors/instrument/index.js +4 -4
  58. package/dist/cjs/features/logging/aggregate/index.js +33 -36
  59. package/dist/cjs/features/logging/constants.js +2 -3
  60. package/dist/cjs/features/logging/instrument/index.js +5 -6
  61. package/dist/cjs/features/logging/shared/log.js +1 -3
  62. package/dist/cjs/features/logging/shared/utils.js +2 -4
  63. package/dist/cjs/features/metrics/aggregate/index.js +34 -17
  64. package/dist/cjs/features/metrics/aggregate/websocket-detection.js +34 -0
  65. package/dist/cjs/features/metrics/constants.js +4 -2
  66. package/dist/cjs/features/metrics/instrument/index.js +12 -4
  67. package/dist/cjs/features/page_action/instrument/index.js +14 -10
  68. package/dist/cjs/features/page_view_event/aggregate/index.js +19 -39
  69. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +1 -1
  70. package/dist/cjs/features/page_view_event/instrument/index.js +4 -4
  71. package/dist/cjs/features/page_view_timing/aggregate/index.js +23 -39
  72. package/dist/cjs/features/page_view_timing/instrument/index.js +4 -4
  73. package/dist/cjs/features/session_replay/aggregate/index.js +35 -42
  74. package/dist/cjs/features/session_replay/constants.js +1 -5
  75. package/dist/cjs/features/session_replay/instrument/index.js +5 -9
  76. package/dist/cjs/features/session_replay/shared/recorder-events.js +25 -20
  77. package/dist/cjs/features/session_replay/shared/recorder.js +17 -13
  78. package/dist/cjs/features/session_replay/shared/stylesheet-evaluator.js +2 -2
  79. package/dist/cjs/features/session_replay/shared/utils.js +5 -4
  80. package/dist/cjs/features/session_trace/aggregate/index.js +25 -42
  81. package/dist/cjs/features/session_trace/aggregate/trace/storage.js +5 -3
  82. package/dist/cjs/features/session_trace/instrument/index.js +8 -7
  83. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +1 -1
  84. package/dist/cjs/features/soft_navigations/aggregate/index.js +22 -30
  85. package/dist/cjs/features/soft_navigations/aggregate/initial-page-load-interaction.js +2 -2
  86. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +4 -5
  87. package/dist/cjs/features/soft_navigations/instrument/index.js +14 -13
  88. package/dist/cjs/features/spa/aggregate/index.js +17 -28
  89. package/dist/cjs/features/spa/aggregate/interaction.js +7 -6
  90. package/dist/cjs/features/spa/aggregate/serializer.js +4 -5
  91. package/dist/cjs/features/spa/constants.js +2 -2
  92. package/dist/cjs/features/spa/instrument/index.js +20 -19
  93. package/dist/cjs/features/utils/agent-session.js +6 -4
  94. package/dist/cjs/features/utils/aggregate-base.js +17 -10
  95. package/dist/cjs/features/utils/event-buffer.js +132 -0
  96. package/dist/cjs/features/utils/feature-gates.js +2 -2
  97. package/dist/cjs/features/utils/instrument-base.js +7 -8
  98. package/dist/cjs/features/utils/lazy-feature-loader.js +12 -12
  99. package/dist/cjs/features/utils/nr1-debugger.js +1 -3
  100. package/dist/cjs/index.js +21 -0
  101. package/dist/cjs/loaders/agent-base.js +4 -12
  102. package/dist/cjs/loaders/agent.js +7 -2
  103. package/dist/cjs/loaders/api/api.js +23 -35
  104. package/dist/cjs/loaders/api/apiAsync.js +10 -13
  105. package/dist/cjs/loaders/browser-agent.js +4 -3
  106. package/dist/cjs/loaders/configure/configure.js +16 -15
  107. package/dist/cjs/loaders/features/enabled-features.js +2 -2
  108. package/dist/cjs/loaders/features/features.js +8 -4
  109. package/dist/cjs/loaders/micro-agent.js +16 -15
  110. package/dist/esm/cdn/experimental.js +2 -5
  111. package/dist/esm/cdn/pro.js +2 -2
  112. package/dist/esm/cdn/spa.js +2 -2
  113. package/dist/esm/common/aggregate/aggregator.js +2 -3
  114. package/dist/esm/common/config/{state/configurable.js → configurable.js} +1 -1
  115. package/dist/esm/common/config/{state/info.js → info.js} +1 -1
  116. package/dist/esm/common/config/{state/init.js → init.js} +11 -8
  117. package/dist/esm/common/config/{state/loader-config.js → loader-config.js} +1 -1
  118. package/dist/esm/common/config/{state/runtime.js → runtime.js} +17 -5
  119. package/dist/esm/common/constants/agent-constants.js +2 -0
  120. package/dist/esm/common/constants/env.cdn.js +1 -1
  121. package/dist/esm/common/constants/env.npm.js +1 -1
  122. package/dist/esm/common/constants/runtime.js +0 -2
  123. package/dist/esm/common/context/shared-context.js +1 -2
  124. package/dist/esm/common/dispatch/global-event.js +1 -2
  125. package/dist/esm/common/drain/drain.js +12 -18
  126. package/dist/esm/common/event-emitter/contextual-ee.js +2 -3
  127. package/dist/esm/common/event-listener/event-listener-opts.js +2 -6
  128. package/dist/esm/common/harvest/harvest-scheduler.js +1 -2
  129. package/dist/esm/common/harvest/harvest.js +24 -51
  130. package/dist/esm/common/serialize/bel-serializer.js +6 -11
  131. package/dist/esm/common/session/session-entity.js +10 -13
  132. package/dist/esm/common/timing/nav-timing.js +1 -3
  133. package/dist/esm/common/timing/time-keeper.js +15 -5
  134. package/dist/esm/common/url/encode.js +3 -7
  135. package/dist/esm/common/util/console.js +2 -0
  136. package/dist/esm/common/util/invoke.js +6 -16
  137. package/dist/esm/common/util/obfuscate.js +96 -49
  138. package/dist/esm/common/util/submit-data.js +17 -21
  139. package/dist/esm/common/util/text.js +3 -0
  140. package/dist/esm/common/util/traverse.js +1 -3
  141. package/dist/esm/common/vitals/cumulative-layout-shift.js +5 -6
  142. package/dist/esm/common/vitals/first-contentful-paint.js +4 -5
  143. package/dist/esm/common/vitals/first-input-delay.js +4 -5
  144. package/dist/esm/common/vitals/interaction-to-next-paint.js +5 -6
  145. package/dist/esm/common/vitals/largest-contentful-paint.js +4 -5
  146. package/dist/esm/common/vitals/time-to-first-byte.js +4 -5
  147. package/dist/esm/common/vitals/vital-metric.js +5 -7
  148. package/dist/esm/common/window/nreum.js +2 -1
  149. package/dist/esm/common/window/page-visibility.js +1 -4
  150. package/dist/esm/common/wrap/wrap-events.js +1 -4
  151. package/dist/esm/common/wrap/wrap-promise.js +1 -4
  152. package/dist/esm/common/wrap/wrap-websocket.js +67 -0
  153. package/dist/esm/features/ajax/aggregate/chunk.js +3 -2
  154. package/dist/esm/features/ajax/aggregate/gql.js +4 -5
  155. package/dist/esm/features/ajax/aggregate/index.js +16 -19
  156. package/dist/esm/features/ajax/constants.js +1 -2
  157. package/dist/esm/features/ajax/instrument/distributed-tracing.js +2 -1
  158. package/dist/esm/features/ajax/instrument/index.js +10 -8
  159. package/dist/esm/features/generic_events/aggregate/index.js +120 -0
  160. package/dist/esm/features/generic_events/constants.js +4 -0
  161. package/dist/esm/features/generic_events/index.js +1 -0
  162. package/dist/esm/features/generic_events/instrument/index.js +20 -0
  163. package/dist/esm/features/jserrors/aggregate/index.js +20 -39
  164. package/dist/esm/features/jserrors/instrument/index.js +3 -3
  165. package/dist/esm/features/logging/aggregate/index.js +31 -34
  166. package/dist/esm/features/logging/constants.js +1 -2
  167. package/dist/esm/features/logging/instrument/index.js +4 -5
  168. package/dist/esm/features/logging/shared/log.js +1 -3
  169. package/dist/esm/features/logging/shared/utils.js +2 -4
  170. package/dist/esm/features/metrics/aggregate/index.js +28 -11
  171. package/dist/esm/features/metrics/aggregate/websocket-detection.js +29 -0
  172. package/dist/esm/features/metrics/constants.js +3 -1
  173. package/dist/esm/features/metrics/instrument/index.js +12 -4
  174. package/dist/esm/features/page_action/instrument/index.js +14 -9
  175. package/dist/esm/features/page_view_event/aggregate/index.js +17 -37
  176. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +1 -1
  177. package/dist/esm/features/page_view_event/instrument/index.js +3 -3
  178. package/dist/esm/features/page_view_timing/aggregate/index.js +20 -36
  179. package/dist/esm/features/page_view_timing/instrument/index.js +3 -3
  180. package/dist/esm/features/session_replay/aggregate/index.js +25 -32
  181. package/dist/esm/features/session_replay/constants.js +0 -4
  182. package/dist/esm/features/session_replay/index.js +1 -7
  183. package/dist/esm/features/session_replay/instrument/index.js +5 -8
  184. package/dist/esm/features/session_replay/shared/recorder-events.js +25 -20
  185. package/dist/esm/features/session_replay/shared/recorder.js +14 -10
  186. package/dist/esm/features/session_replay/shared/stylesheet-evaluator.js +2 -2
  187. package/dist/esm/features/session_replay/shared/utils.js +3 -2
  188. package/dist/esm/features/session_trace/aggregate/index.js +20 -37
  189. package/dist/esm/features/session_trace/aggregate/trace/storage.js +5 -3
  190. package/dist/esm/features/session_trace/instrument/index.js +5 -4
  191. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +1 -1
  192. package/dist/esm/features/soft_navigations/aggregate/index.js +21 -29
  193. package/dist/esm/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  194. package/dist/esm/features/soft_navigations/aggregate/interaction.js +2 -3
  195. package/dist/esm/features/soft_navigations/instrument/index.js +11 -10
  196. package/dist/esm/features/spa/aggregate/index.js +11 -22
  197. package/dist/esm/features/spa/aggregate/interaction.js +6 -5
  198. package/dist/esm/features/spa/aggregate/serializer.js +2 -3
  199. package/dist/esm/features/spa/constants.js +2 -2
  200. package/dist/esm/features/spa/instrument/index.js +12 -11
  201. package/dist/esm/features/utils/agent-session.js +3 -1
  202. package/dist/esm/features/utils/aggregate-base.js +16 -9
  203. package/dist/esm/features/utils/event-buffer.js +126 -0
  204. package/dist/esm/features/utils/feature-gates.js +1 -1
  205. package/dist/esm/features/utils/instrument-base.js +6 -7
  206. package/dist/esm/features/utils/lazy-feature-loader.js +12 -12
  207. package/dist/esm/features/utils/nr1-debugger.js +1 -3
  208. package/dist/esm/index.js +3 -0
  209. package/dist/esm/loaders/agent-base.js +4 -12
  210. package/dist/esm/loaders/agent.js +7 -2
  211. package/dist/esm/loaders/api/api.js +18 -30
  212. package/dist/esm/loaders/api/apiAsync.js +3 -6
  213. package/dist/esm/loaders/browser-agent.js +3 -2
  214. package/dist/esm/loaders/configure/configure.js +9 -8
  215. package/dist/esm/loaders/features/enabled-features.js +1 -1
  216. package/dist/esm/loaders/features/features.js +8 -4
  217. package/dist/esm/loaders/micro-agent.js +11 -10
  218. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -1
  219. package/dist/types/common/config/configurable.d.ts.map +1 -0
  220. package/dist/types/common/config/info.d.ts.map +1 -0
  221. package/dist/types/common/config/init.d.ts.map +1 -0
  222. package/dist/types/common/config/loader-config.d.ts.map +1 -0
  223. package/dist/types/common/config/runtime.d.ts.map +1 -0
  224. package/dist/types/common/constants/agent-constants.d.ts +3 -0
  225. package/dist/types/common/constants/agent-constants.d.ts.map +1 -0
  226. package/dist/types/common/constants/runtime.d.ts +0 -1
  227. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  228. package/dist/types/common/harvest/harvest.d.ts +1 -7
  229. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  230. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -1
  231. package/dist/types/common/timing/time-keeper.d.ts +9 -2
  232. package/dist/types/common/timing/time-keeper.d.ts.map +1 -1
  233. package/dist/types/common/url/encode.d.ts.map +1 -1
  234. package/dist/types/common/util/console.d.ts.map +1 -1
  235. package/dist/types/common/util/obfuscate.d.ts +78 -6
  236. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  237. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  238. package/dist/types/common/util/text.d.ts +2 -0
  239. package/dist/types/common/util/text.d.ts.map +1 -0
  240. package/dist/types/common/window/nreum.d.ts.map +1 -1
  241. package/dist/types/common/wrap/wrap-websocket.d.ts +4 -0
  242. package/dist/types/common/wrap/wrap-websocket.d.ts.map +1 -0
  243. package/dist/types/features/ajax/aggregate/chunk.d.ts.map +1 -1
  244. package/dist/types/features/ajax/aggregate/index.d.ts +2 -3
  245. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  246. package/dist/types/features/ajax/constants.d.ts +0 -1
  247. package/dist/types/features/ajax/constants.d.ts.map +1 -1
  248. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -1
  249. package/dist/types/features/ajax/instrument/index.d.ts +1 -0
  250. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  251. package/dist/types/features/{page_action → generic_events}/aggregate/index.d.ts +10 -10
  252. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -0
  253. package/dist/types/features/generic_events/constants.d.ts +4 -0
  254. package/dist/types/features/generic_events/constants.d.ts.map +1 -0
  255. package/dist/types/features/generic_events/index.d.ts +2 -0
  256. package/dist/types/features/generic_events/index.d.ts.map +1 -0
  257. package/dist/types/features/generic_events/instrument/index.d.ts +7 -0
  258. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -0
  259. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
  260. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  261. package/dist/types/features/jserrors/instrument/index.d.ts +1 -0
  262. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  263. package/dist/types/features/logging/aggregate/index.d.ts +4 -7
  264. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  265. package/dist/types/features/logging/constants.d.ts +0 -1
  266. package/dist/types/features/logging/constants.d.ts.map +1 -1
  267. package/dist/types/features/logging/instrument/index.d.ts +1 -0
  268. package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
  269. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  270. package/dist/types/features/metrics/aggregate/websocket-detection.d.ts +12 -0
  271. package/dist/types/features/metrics/aggregate/websocket-detection.d.ts.map +1 -0
  272. package/dist/types/features/metrics/constants.d.ts +1 -0
  273. package/dist/types/features/metrics/constants.d.ts.map +1 -1
  274. package/dist/types/features/metrics/instrument/index.d.ts +1 -0
  275. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  276. package/dist/types/features/page_action/instrument/index.d.ts +9 -4
  277. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  278. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  279. package/dist/types/features/page_view_event/instrument/index.d.ts +1 -0
  280. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  281. package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
  282. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  283. package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -0
  284. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  285. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  286. package/dist/types/features/session_replay/constants.d.ts +0 -4
  287. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  288. package/dist/types/features/session_replay/instrument/index.d.ts +1 -0
  289. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  290. package/dist/types/features/session_replay/shared/recorder-events.d.ts +6 -6
  291. package/dist/types/features/session_replay/shared/recorder-events.d.ts.map +1 -1
  292. package/dist/types/features/session_replay/shared/recorder.d.ts +2 -2
  293. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  294. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -1
  295. package/dist/types/features/session_trace/aggregate/index.d.ts +2 -2
  296. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  297. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts +1 -1
  298. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts.map +1 -1
  299. package/dist/types/features/session_trace/instrument/index.d.ts +1 -0
  300. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  301. package/dist/types/features/soft_navigations/aggregate/index.d.ts +3 -3
  302. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  303. package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -0
  304. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  305. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  306. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  307. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  308. package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -1
  309. package/dist/types/features/spa/constants.d.ts.map +1 -1
  310. package/dist/types/features/spa/instrument/index.d.ts +1 -0
  311. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  312. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  313. package/dist/types/features/utils/aggregate-base.d.ts +1 -0
  314. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  315. package/dist/types/features/utils/event-buffer.d.ts +72 -0
  316. package/dist/types/features/utils/event-buffer.d.ts.map +1 -0
  317. package/dist/types/features/utils/instrument-base.d.ts +1 -0
  318. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  319. package/dist/types/index.d.ts +3 -0
  320. package/dist/types/loaders/agent-base.d.ts +1 -2
  321. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  322. package/dist/types/loaders/agent.d.ts.map +1 -1
  323. package/dist/types/loaders/api/api.d.ts.map +1 -1
  324. package/dist/types/loaders/browser-agent.d.ts.map +1 -1
  325. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  326. package/dist/types/loaders/features/features.d.ts +1 -0
  327. package/dist/types/loaders/features/features.d.ts.map +1 -1
  328. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  329. package/package.json +67 -52
  330. package/src/cdn/experimental.js +2 -4
  331. package/src/cdn/pro.js +2 -2
  332. package/src/cdn/spa.js +2 -2
  333. package/src/common/aggregate/aggregator.js +2 -3
  334. package/src/common/config/__mocks__/info.js +3 -0
  335. package/src/common/config/__mocks__/init.js +3 -0
  336. package/src/common/config/__mocks__/loader-config.js +2 -0
  337. package/src/common/config/__mocks__/runtime.js +2 -0
  338. package/src/common/config/{state/configurable.js → configurable.js} +1 -1
  339. package/src/common/config/{state/info.js → info.js} +1 -1
  340. package/src/common/config/{state/init.js → init.js} +7 -6
  341. package/src/common/config/{state/loader-config.js → loader-config.js} +1 -1
  342. package/src/common/config/{state/runtime.js → runtime.js} +19 -5
  343. package/src/common/constants/agent-constants.js +2 -0
  344. package/src/common/constants/runtime.js +0 -2
  345. package/src/common/drain/drain.js +8 -6
  346. package/src/common/event-emitter/contextual-ee.js +1 -1
  347. package/src/common/harvest/harvest.js +10 -24
  348. package/src/common/serialize/bel-serializer.js +6 -9
  349. package/src/common/session/session-entity.js +4 -4
  350. package/src/common/timing/__mocks__/time-keeper.js +6 -2
  351. package/src/common/timing/time-keeper.js +15 -5
  352. package/src/common/url/encode.js +2 -3
  353. package/src/common/util/__mocks__/console.js +1 -0
  354. package/src/common/util/__mocks__/obfuscate.js +5 -8
  355. package/src/common/util/console.js +2 -0
  356. package/src/common/util/obfuscate.js +94 -50
  357. package/src/common/util/submit-data.js +0 -1
  358. package/src/common/util/text.js +6 -0
  359. package/src/common/window/__mocks__/nreum.js +1 -1
  360. package/src/common/window/nreum.js +2 -1
  361. package/src/common/wrap/wrap-websocket.js +73 -0
  362. package/src/features/ajax/aggregate/chunk.js +3 -2
  363. package/src/features/ajax/aggregate/index.js +20 -19
  364. package/src/features/ajax/constants.js +0 -2
  365. package/src/features/ajax/instrument/distributed-tracing.js +2 -1
  366. package/src/features/ajax/instrument/index.js +9 -5
  367. package/src/features/generic_events/aggregate/index.js +139 -0
  368. package/src/features/generic_events/constants.js +5 -0
  369. package/src/features/generic_events/index.js +1 -0
  370. package/src/features/generic_events/instrument/index.js +24 -0
  371. package/src/features/jserrors/aggregate/index.js +18 -9
  372. package/src/features/jserrors/instrument/index.js +2 -0
  373. package/src/features/logging/aggregate/index.js +39 -31
  374. package/src/features/logging/constants.js +0 -2
  375. package/src/features/logging/instrument/index.js +2 -0
  376. package/src/features/logging/shared/utils.js +1 -1
  377. package/src/features/metrics/aggregate/index.js +24 -9
  378. package/src/features/metrics/aggregate/websocket-detection.js +31 -0
  379. package/src/features/metrics/constants.js +3 -0
  380. package/src/features/metrics/instrument/index.js +13 -1
  381. package/src/features/page_action/instrument/index.js +11 -6
  382. package/src/features/page_view_event/aggregate/index.js +8 -23
  383. package/src/features/page_view_event/aggregate/initialized-features.js +1 -1
  384. package/src/features/page_view_event/instrument/index.js +2 -0
  385. package/src/features/page_view_timing/aggregate/index.js +15 -18
  386. package/src/features/page_view_timing/instrument/index.js +2 -0
  387. package/src/features/session_replay/aggregate/index.js +13 -9
  388. package/src/features/session_replay/constants.js +0 -4
  389. package/src/features/session_replay/index.js +1 -7
  390. package/src/features/session_replay/instrument/index.js +3 -4
  391. package/src/features/session_replay/shared/recorder-events.js +27 -20
  392. package/src/features/session_replay/shared/recorder.js +13 -6
  393. package/src/features/session_replay/shared/stylesheet-evaluator.js +2 -2
  394. package/src/features/session_replay/shared/utils.js +3 -2
  395. package/src/features/session_trace/aggregate/index.js +16 -7
  396. package/src/features/session_trace/aggregate/trace/storage.js +6 -1
  397. package/src/features/session_trace/instrument/index.js +4 -1
  398. package/src/features/soft_navigations/aggregate/ajax-node.js +1 -1
  399. package/src/features/soft_navigations/aggregate/index.js +13 -15
  400. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  401. package/src/features/soft_navigations/aggregate/interaction.js +1 -1
  402. package/src/features/soft_navigations/instrument/index.js +9 -5
  403. package/src/features/spa/aggregate/index.js +12 -20
  404. package/src/features/spa/aggregate/interaction.js +6 -5
  405. package/src/features/spa/aggregate/serializer.js +2 -3
  406. package/src/features/spa/constants.js +2 -2
  407. package/src/features/spa/instrument/index.js +9 -3
  408. package/src/features/utils/agent-session.js +3 -1
  409. package/src/features/utils/aggregate-base.js +13 -3
  410. package/src/features/utils/event-buffer.js +126 -0
  411. package/src/features/utils/feature-gates.js +1 -1
  412. package/src/features/utils/instrument-base.js +2 -1
  413. package/src/features/utils/lazy-feature-loader.js +2 -2
  414. package/src/index.js +3 -0
  415. package/src/loaders/agent-base.js +2 -6
  416. package/src/loaders/agent.js +7 -2
  417. package/src/loaders/api/api.js +3 -2
  418. package/src/loaders/api/apiAsync.js +2 -2
  419. package/src/loaders/browser-agent.js +5 -3
  420. package/src/loaders/configure/configure.js +9 -2
  421. package/src/loaders/features/enabled-features.js +1 -1
  422. package/src/loaders/features/features.js +8 -4
  423. package/src/loaders/micro-agent.js +5 -2
  424. package/dist/cjs/cdn/polyfills/lite.js +0 -16
  425. package/dist/cjs/cdn/polyfills/pro.js +0 -21
  426. package/dist/cjs/cdn/polyfills/spa.js +0 -22
  427. package/dist/cjs/cdn/polyfills.js +0 -24
  428. package/dist/cjs/common/config/config.js +0 -76
  429. package/dist/cjs/common/config/state/originals.js +0 -8
  430. package/dist/cjs/common/util/map-own.js +0 -31
  431. package/dist/cjs/common/wrap/index.js +0 -61
  432. package/dist/cjs/features/page_action/aggregate/index.js +0 -121
  433. package/dist/esm/cdn/polyfills/lite.js +0 -14
  434. package/dist/esm/cdn/polyfills/pro.js +0 -19
  435. package/dist/esm/cdn/polyfills/spa.js +0 -20
  436. package/dist/esm/cdn/polyfills.js +0 -27
  437. package/dist/esm/common/config/config.js +0 -11
  438. package/dist/esm/common/config/state/originals.js +0 -2
  439. package/dist/esm/common/util/map-own.js +0 -24
  440. package/dist/esm/common/wrap/index.js +0 -13
  441. package/dist/esm/features/page_action/aggregate/index.js +0 -114
  442. package/dist/types/cdn/polyfills/lite.d.ts +0 -2
  443. package/dist/types/cdn/polyfills/lite.d.ts.map +0 -1
  444. package/dist/types/cdn/polyfills/pro.d.ts +0 -2
  445. package/dist/types/cdn/polyfills/pro.d.ts.map +0 -1
  446. package/dist/types/cdn/polyfills/spa.d.ts +0 -2
  447. package/dist/types/cdn/polyfills/spa.d.ts.map +0 -1
  448. package/dist/types/cdn/polyfills.d.ts +0 -2
  449. package/dist/types/cdn/polyfills.d.ts.map +0 -1
  450. package/dist/types/common/config/config.d.ts +0 -13
  451. package/dist/types/common/config/config.d.ts.map +0 -1
  452. package/dist/types/common/config/state/configurable.d.ts.map +0 -1
  453. package/dist/types/common/config/state/info.d.ts.map +0 -1
  454. package/dist/types/common/config/state/init.d.ts.map +0 -1
  455. package/dist/types/common/config/state/loader-config.d.ts.map +0 -1
  456. package/dist/types/common/config/state/originals.d.ts +0 -2
  457. package/dist/types/common/config/state/originals.d.ts.map +0 -1
  458. package/dist/types/common/config/state/runtime.d.ts.map +0 -1
  459. package/dist/types/common/util/map-own.d.ts +0 -3
  460. package/dist/types/common/util/map-own.d.ts.map +0 -1
  461. package/dist/types/common/wrap/index.d.ts +0 -10
  462. package/dist/types/common/wrap/index.d.ts.map +0 -1
  463. package/dist/types/features/page_action/aggregate/index.d.ts.map +0 -1
  464. package/src/cdn/polyfills/lite.js +0 -20
  465. package/src/cdn/polyfills/pro.js +0 -30
  466. package/src/cdn/polyfills/spa.js +0 -32
  467. package/src/cdn/polyfills.js +0 -27
  468. package/src/common/config/__mocks__/config.js +0 -11
  469. package/src/common/config/config.js +0 -12
  470. package/src/common/config/state/originals.js +0 -3
  471. package/src/common/util/map-own.js +0 -22
  472. package/src/common/wrap/index.js +0 -16
  473. package/src/features/page_action/aggregate/index.js +0 -114
  474. /package/dist/types/common/config/{state/configurable.d.ts → configurable.d.ts} +0 -0
  475. /package/dist/types/common/config/{state/info.d.ts → info.d.ts} +0 -0
  476. /package/dist/types/common/config/{state/init.d.ts → init.d.ts} +0 -0
  477. /package/dist/types/common/config/{state/loader-config.d.ts → loader-config.d.ts} +0 -0
  478. /package/dist/types/common/config/{state/runtime.d.ts → runtime.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { originTime } from '../constants/runtime';
2
- import { getRuntime } from '../config/config';
2
+ import { getRuntime } from '../config/runtime';
3
3
  const rfc2616Regex = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-3][0-9]) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([0-9]{4}) ([01][0-9]|2[0-3])(:[0-5][0-9]){2} GMT$/;
4
4
 
5
5
  /**
@@ -81,21 +81,31 @@ export class TimeKeeper {
81
81
 
82
82
  /**
83
83
  * Converts a page origin relative time to an absolute timestamp
84
- * corrected to NR server time.
84
+ * using the user's local clock.
85
85
  * @param relativeTime {number} The relative time of the event in milliseconds
86
86
  * @returns {number} Corrected unix/epoch timestamp
87
87
  */
88
88
  convertRelativeTimestamp(relativeTime) {
89
- return Math.floor(this.#correctedOriginTime + relativeTime);
89
+ return originTime + relativeTime;
90
90
  }
91
91
 
92
92
  /**
93
- * Corrects an event timestamp to NR server time.
93
+ * Converts an absolute timestamp to a relative timestamp using the
94
+ * user's local clock.
95
+ * @param timestamp
96
+ * @returns {number}
97
+ */
98
+ convertAbsoluteTimestamp(timestamp) {
99
+ return timestamp - originTime;
100
+ }
101
+
102
+ /**
103
+ * Corrects an absolute timestamp to NR server time.
94
104
  * @param timestamp {number} The unix/epoch timestamp of the event with milliseconds
95
105
  * @return {number} Corrected unix/epoch timestamp
96
106
  */
97
107
  correctAbsoluteTimestamp(timestamp) {
98
- return Math.floor(timestamp - this.#localTimeDiff);
108
+ return timestamp - this.#localTimeDiff;
99
109
  }
100
110
 
101
111
  /** Process the session entity and use the info to set the main time calculations if present */
@@ -3,7 +3,6 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
6
- import { mapOwn } from '../util/map-own';
7
6
  import { stringify } from '../util/stringify';
8
7
 
9
8
  // Characters that are safe in a qs, but get encoded.
@@ -15,9 +14,7 @@ var charMap = {
15
14
  '%24': '$',
16
15
  '%3B': ';'
17
16
  };
18
- var charList = mapOwn(charMap, function (k) {
19
- return k;
20
- });
17
+ var charList = Object.keys(charMap);
21
18
  var safeEncoded = new RegExp(charList.join('|'), 'g');
22
19
  function real(c) {
23
20
  return charMap[c];
@@ -40,7 +37,7 @@ export function fromArray(qs, maxBytes) {
40
37
  export function obj(payload, maxBytes) {
41
38
  var total = 0;
42
39
  var result = '';
43
- mapOwn(payload, function (feature, dataArray) {
40
+ Object.entries(payload || {}).forEach(([feature, dataArray]) => {
44
41
  var intermediate = [];
45
42
  var next;
46
43
  var i;
@@ -63,8 +60,7 @@ export function obj(payload, maxBytes) {
63
60
  }
64
61
 
65
62
  // Constructs an HTTP parameter to add to the BAM router URL
66
- export function param(name, value) {
67
- let base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
63
+ export function param(name, value, base = {}) {
68
64
  if (Object.keys(base).includes(name)) return ''; // we assume if feature supplied a matching qp to the base, we should honor what the feature sent over the default
69
65
  if (value && typeof value === 'string') {
70
66
  return '&' + name + '=' + qs(value);
@@ -1,3 +1,5 @@
1
+ /* eslint no-console: ["error", { allow: ["debug"] }] */
2
+
1
3
  /**
2
4
  * A helper method to warn to the console with New Relic: decoration
3
5
  * @param {string} message The primary message to warn
@@ -20,18 +20,12 @@
20
20
  * @returns {function} A wrapping function that will ensure the provided function
21
21
  * is invoked only once within the given timeout.
22
22
  */
23
- export function debounce(func) {
24
- var _this = this;
25
- let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
26
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
23
+ export function debounce(func, timeout = 500, options = {}) {
27
24
  const leading = options?.leading || false;
28
25
  let timer;
29
- return function () {
30
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
31
- args[_key] = arguments[_key];
32
- }
26
+ return (...args) => {
33
27
  if (leading && timer === undefined) {
34
- func.apply(_this, args);
28
+ func.apply(this, args);
35
29
  timer = setTimeout(() => {
36
30
  timer = clearTimeout(timer);
37
31
  }, timeout);
@@ -39,7 +33,7 @@ export function debounce(func) {
39
33
  if (!leading) {
40
34
  clearTimeout(timer);
41
35
  timer = setTimeout(() => {
42
- func.apply(_this, args);
36
+ func.apply(this, args);
43
37
  }, timeout);
44
38
  }
45
39
  };
@@ -54,15 +48,11 @@ export function debounce(func) {
54
48
  * is invoked only once.
55
49
  */
56
50
  export function single(func) {
57
- var _this2 = this;
58
51
  let called = false;
59
- return function () {
52
+ return (...args) => {
60
53
  if (!called) {
61
54
  called = true;
62
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
63
- args[_key2] = arguments[_key2];
64
- }
65
- func.apply(_this2, args);
55
+ func.apply(this, args);
66
56
  }
67
57
  };
68
58
  }
@@ -1,61 +1,108 @@
1
- import { getConfigurationValue } from '../config/config';
2
- import { SharedContext } from '../context/shared-context';
1
+ import { getConfigurationValue } from '../config/init';
3
2
  import { isFileProtocol } from '../url/protocol';
4
3
  import { warn } from './console';
5
- var fileProtocolRule = {
6
- regex: /^file:\/\/(.*)/,
7
- replacement: atob('ZmlsZTovL09CRlVTQ0FURUQ=')
8
- };
9
- export class Obfuscator extends SharedContext {
10
- shouldObfuscate() {
11
- return getRules(this.sharedContext.agentIdentifier).length > 0;
4
+
5
+ /**
6
+ * Represents an obfuscation rule that can be applied to harvested payloads
7
+ * @typedef {object} ObfuscationRule
8
+ * @property {string|RegExp} regex The regular expression to match against in the payload
9
+ * @property {string} [replacement] The string to replace the matched regex with
10
+ */
11
+
12
+ /**
13
+ * Represents an obfuscation rule validation state
14
+ * @typedef {object} ObfuscationRuleValidation
15
+ * @property {ObfuscationRule} rule The original rule validated
16
+ * @property {boolean} isValid Whether the rule is valid
17
+ * @property {object} errors Validation errors
18
+ * @property {boolean} errors.regexMissingDetected Whether the regex is missing
19
+ * @property {boolean} errors.invalidRegexDetected Whether the regex is invalid
20
+ * @property {boolean} errors.invalidReplacementDetected Whether the replacement is invalid
21
+ */
22
+
23
+ export class Obfuscator {
24
+ /**
25
+ * @type {ObfuscationRuleValidation[]}
26
+ */
27
+ #ruleValidationCache;
28
+ constructor(agentIdentifier) {
29
+ this.#ruleValidationCache = Obfuscator.getRuleValidationCache(agentIdentifier);
30
+ Obfuscator.logObfuscationRuleErrors(this.#ruleValidationCache);
31
+ }
32
+ get ruleValidationCache() {
33
+ return this.#ruleValidationCache;
12
34
  }
13
35
 
14
- // applies all regex obfuscation rules to provided URL string and returns the result
15
- obfuscateString(string) {
16
- // if string is empty string, null or not a string, return unmodified
17
- if (!string || typeof string !== 'string') return string;
18
- var rules = getRules(this.sharedContext.agentIdentifier);
19
- var obfuscated = string;
36
+ /**
37
+ * Applies all valid obfuscation rules to the provided input string
38
+ * @param {string} input String to obfuscate
39
+ * @returns {string}
40
+ */
41
+ obfuscateString(input) {
42
+ // if input is not of type string or is an empty string, short-circuit
43
+ if (typeof input !== 'string' || input.trim().length === 0) return input;
44
+ return this.#ruleValidationCache.filter(ruleValidation => ruleValidation.isValid).reduce((input, ruleValidation) => {
45
+ const {
46
+ rule
47
+ } = ruleValidation;
48
+ return input.replace(rule.regex, rule.replacement || '*');
49
+ }, input);
50
+ }
20
51
 
21
- // apply every rule to URL string
22
- for (var i = 0; i < rules.length; i++) {
23
- var regex = rules[i].regex;
24
- var replacement = rules[i].replacement || '*';
25
- obfuscated = obfuscated.replace(regex, replacement);
52
+ /**
53
+ * Returns an array of obfuscation rules to be applied to harvested payloads
54
+ * @param {string} agentIdentifier The agent identifier to get rules for
55
+ * @returns {ObfuscationRuleValidation[]} The array of rules or validation states
56
+ */
57
+ static getRuleValidationCache(agentIdentifier) {
58
+ /**
59
+ * @type {ObfuscationRule[]}
60
+ */
61
+ let rules = getConfigurationValue(agentIdentifier, 'obfuscate') || [];
62
+ if (isFileProtocol()) {
63
+ rules.push({
64
+ regex: /^file:\/\/(.*)/,
65
+ replacement: atob('ZmlsZTovL09CRlVTQ0FURUQ=')
66
+ });
26
67
  }
27
- return obfuscated;
68
+ return rules.map(rule => Obfuscator.validateObfuscationRule(rule));
28
69
  }
29
- }
30
-
31
- // TO DO: this function should be inside the Obfuscator class since its context relates to agentID
32
- export function getRules(agentIdentifier) {
33
- var rules = [];
34
- var configRules = getConfigurationValue(agentIdentifier, 'obfuscate') || [];
35
- rules = rules.concat(configRules);
36
- if (isFileProtocol()) rules.push(fileProtocolRule);
37
- // could add additional runtime/environment-specific rules here
38
70
 
39
- return rules;
40
- }
71
+ /**
72
+ * Validates an obfuscation rule and provides errors if any are found.
73
+ * @param {ObfuscationRule} rule The rule to validate
74
+ * @returns {ObfuscationRuleValidation} The validation state of the rule
75
+ */
76
+ static validateObfuscationRule(rule) {
77
+ const regexMissingDetected = Boolean(rule.regex === undefined);
78
+ const invalidRegexDetected = Boolean(rule.regex !== undefined && typeof rule.regex !== 'string' && !(rule.regex instanceof RegExp));
79
+ const invalidReplacementDetected = Boolean(rule.replacement && typeof rule.replacement !== 'string');
80
+ return {
81
+ rule,
82
+ isValid: !regexMissingDetected && !invalidRegexDetected && !invalidReplacementDetected,
83
+ errors: {
84
+ regexMissingDetected,
85
+ invalidRegexDetected,
86
+ invalidReplacementDetected
87
+ }
88
+ };
89
+ }
41
90
 
42
- // takes array of rule objects, logs warning and returns false if any portion of rule is invalid
43
- export function validateRules(rules) {
44
- var invalidReplacementDetected = false;
45
- var invalidRegexDetected = false;
46
- for (var i = 0; i < rules.length; i++) {
47
- if (!('regex' in rules[i])) {
48
- warn(12);
49
- invalidRegexDetected = true;
50
- } else if (typeof rules[i].regex !== 'string' && !(rules[i].regex instanceof RegExp)) {
51
- warn(13);
52
- invalidRegexDetected = true;
53
- }
54
- var replacement = rules[i].replacement;
55
- if (replacement && typeof replacement !== 'string') {
56
- warn(14);
57
- invalidReplacementDetected = true;
91
+ /**
92
+ * Logs any obfuscation rule errors to the console. This is called when an obfuscator
93
+ * instance is created.
94
+ * @param {ObfuscationRuleValidation[]} ruleValidationCache The cache of rule validation states
95
+ */
96
+ static logObfuscationRuleErrors(ruleValidationCache) {
97
+ for (const ruleValidation of ruleValidationCache) {
98
+ const {
99
+ rule,
100
+ isValid,
101
+ errors
102
+ } = ruleValidation;
103
+ if (isValid) continue;
104
+ if (errors.regexMissingDetected) warn(12, rule);else if (errors.invalidRegexDetected) warn(13, rule);
105
+ if (errors.invalidReplacementDetected) warn(14, rule);
58
106
  }
59
107
  }
60
- return !invalidReplacementDetected && !invalidRegexDetected;
61
108
  }
@@ -16,14 +16,12 @@ import { isBrowserScope, supportsSendBeacon } from '../constants/runtime';
16
16
  * @param {boolean} opts.isFinalHarvest Indicates if the data submission is due to
17
17
  * a final harvest within the agent.
18
18
  */
19
- export function getSubmitMethod() {
20
- let {
21
- isFinalHarvest = false
22
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ export function getSubmitMethod({
20
+ isFinalHarvest = false
21
+ } = {}) {
23
22
  return isFinalHarvest && isBrowserScope && supportsSendBeacon
24
23
  // Use sendBeacon for final harvest
25
24
  ? beacon
26
- // Only IE does not support sendBeacon for final harvest
27
25
  // If not final harvest, or not browserScope, always use xhr post
28
26
  : xhr;
29
27
  }
@@ -38,17 +36,16 @@ export function getSubmitMethod() {
38
36
  * @param {{key: string, value: string}[]} [args.headers] - The headers to attach.
39
37
  * @returns {XMLHttpRequest}
40
38
  */
41
- export function xhr(_ref) {
42
- let {
43
- url,
44
- body = null,
45
- sync,
46
- method = 'POST',
47
- headers = [{
48
- key: 'content-type',
49
- value: 'text/plain'
50
- }]
51
- } = _ref;
39
+ export function xhr({
40
+ url,
41
+ body = null,
42
+ sync,
43
+ method = 'POST',
44
+ headers = [{
45
+ key: 'content-type',
46
+ value: 'text/plain'
47
+ }]
48
+ }) {
52
49
  const request = new XMLHttpRequest();
53
50
  request.open(method, url, !sync);
54
51
  try {
@@ -71,11 +68,10 @@ export function xhr(_ref) {
71
68
  * @param {string=} args.body - The Stringified body
72
69
  * @returns {boolean}
73
70
  */
74
- export function beacon(_ref2) {
75
- let {
76
- url,
77
- body
78
- } = _ref2;
71
+ export function beacon({
72
+ url,
73
+ body
74
+ }) {
79
75
  try {
80
76
  // Navigator has to be bound to ensure it does not error in some browsers
81
77
  // https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
@@ -0,0 +1,3 @@
1
+ export function toTitleCase(str, regex = /\w*/g) {
2
+ return str.replace(regex, text => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase());
3
+ }
@@ -12,9 +12,7 @@
12
12
  * @param {Array<string>} [ignoreKeys=[]] - The keys of properties to ignore and not modify.
13
13
  * @returns {Object} - The object with function recursively applied.
14
14
  */
15
- export function applyFnToProps(obj, fn) {
16
- let type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'string';
17
- let ignoreKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
15
+ export function applyFnToProps(obj, fn, type = 'string', ignoreKeys = []) {
18
16
  if (!obj || typeof obj !== 'object') return obj;
19
17
  Object.keys(obj).forEach(property => {
20
18
  if (typeof obj[property] === 'object') {
@@ -4,12 +4,11 @@ import { VitalMetric } from './vital-metric';
4
4
  import { isBrowserScope } from '../constants/runtime';
5
5
  export const cumulativeLayoutShift = new VitalMetric(VITAL_NAMES.CUMULATIVE_LAYOUT_SHIFT, x => x);
6
6
  if (isBrowserScope) {
7
- onCLS(_ref => {
8
- let {
9
- value,
10
- attribution,
11
- id
12
- } = _ref;
7
+ onCLS(({
8
+ value,
9
+ attribution,
10
+ id
11
+ }) => {
13
12
  const attrs = {
14
13
  metricId: id,
15
14
  largestShiftTarget: attribution.largestShiftTarget,
@@ -25,11 +25,10 @@ if (isBrowserScope) {
25
25
  // ignore
26
26
  }
27
27
  } else {
28
- onFCP(_ref => {
29
- let {
30
- value,
31
- attribution
32
- } = _ref;
28
+ onFCP(({
29
+ value,
30
+ attribution
31
+ }) => {
33
32
  if (initiallyHidden || firstContentfulPaint.isValid) return;
34
33
  const attrs = {
35
34
  timeToFirstByte: attribution.timeToFirstByte,
@@ -4,11 +4,10 @@ import { VITAL_NAMES } from './constants';
4
4
  import { initiallyHidden, isBrowserScope } from '../constants/runtime';
5
5
  export const firstInputDelay = new VitalMetric(VITAL_NAMES.FIRST_INPUT_DELAY);
6
6
  if (isBrowserScope) {
7
- onFID(_ref => {
8
- let {
9
- value,
10
- attribution
11
- } = _ref;
7
+ onFID(({
8
+ value,
9
+ attribution
10
+ }) => {
12
11
  if (initiallyHidden || firstInputDelay.isValid) return;
13
12
  const attrs = {
14
13
  type: attribution.eventType,
@@ -5,12 +5,11 @@ import { isBrowserScope } from '../constants/runtime';
5
5
  export const interactionToNextPaint = new VitalMetric(VITAL_NAMES.INTERACTION_TO_NEXT_PAINT);
6
6
  if (isBrowserScope) {
7
7
  /* Interaction-to-Next-Paint */
8
- onINP(_ref => {
9
- let {
10
- value,
11
- attribution,
12
- id
13
- } = _ref;
8
+ onINP(({
9
+ value,
10
+ attribution,
11
+ id
12
+ }) => {
14
13
  const attrs = {
15
14
  metricId: id,
16
15
  eventTarget: attribution.eventTarget,
@@ -5,11 +5,10 @@ import { initiallyHidden, isBrowserScope } from '../constants/runtime';
5
5
  import { cleanURL } from '../url/clean-url';
6
6
  export const largestContentfulPaint = new VitalMetric(VITAL_NAMES.LARGEST_CONTENTFUL_PAINT);
7
7
  if (isBrowserScope) {
8
- onLCP(_ref => {
9
- let {
10
- value,
11
- attribution
12
- } = _ref;
8
+ onLCP(({
9
+ value,
10
+ attribution
11
+ }) => {
13
12
  /* Largest Contentful Paint - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
14
13
  if (initiallyHidden || largestContentfulPaint.isValid) return;
15
14
  let attrs;
@@ -12,11 +12,10 @@ export const timeToFirstByte = new VitalMetric(VITAL_NAMES.TIME_TO_FIRST_BYTE);
12
12
  * - cross-origin iframes specifically in firefox and safari
13
13
  */
14
14
  if (isBrowserScope && typeof PerformanceNavigationTiming !== 'undefined' && !isiOS && window === window.parent) {
15
- onTTFB(_ref => {
16
- let {
17
- value,
18
- attribution
19
- } = _ref;
15
+ onTTFB(({
16
+ value,
17
+ attribution
18
+ }) => {
20
19
  if (timeToFirstByte.isValid) return;
21
20
  timeToFirstByte.update({
22
21
  value,
@@ -6,11 +6,10 @@ export class VitalMetric {
6
6
  this.attrs = {};
7
7
  this.roundingMethod = typeof roundingMethod === 'function' ? roundingMethod : Math.floor;
8
8
  }
9
- update(_ref) {
10
- let {
11
- value,
12
- attrs = {}
13
- } = _ref;
9
+ update({
10
+ value,
11
+ attrs = {}
12
+ }) {
14
13
  if (value === undefined || value === null || value < 0) return;
15
14
  const state = {
16
15
  value: this.roundingMethod(value),
@@ -36,8 +35,7 @@ export class VitalMetric {
36
35
  get isValid() {
37
36
  return this.current.value >= 0;
38
37
  }
39
- subscribe(callback) {
40
- let buffered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
38
+ subscribe(callback, buffered = true) {
41
39
  if (typeof callback !== 'function') return;
42
40
  this.#subscribers.add(callback);
43
41
  // emit full history on subscription ("buffered" behavior)
@@ -50,7 +50,8 @@ export function gosNREUMOriginals() {
50
50
  PR: globalScope.Promise,
51
51
  MO: globalScope.MutationObserver,
52
52
  // this'll be undefined if not in a web window
53
- FETCH: globalScope.fetch
53
+ FETCH: globalScope.fetch,
54
+ WS: globalScope.WebSocket
54
55
  };
55
56
  }
56
57
  return nr;
@@ -10,10 +10,7 @@ import { documentAddEventListener } from '../event-listener/event-listener-opts'
10
10
  * @param {boolean} [toHiddenOnly=false] - only execute the 'cb' when the vis is changing to the hidden state; no arg is passed to 'cb' if used
11
11
  * @returns void
12
12
  */
13
- export function subscribeToVisibilityChange(cb) {
14
- let toHiddenOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
15
- let capture = arguments.length > 2 ? arguments[2] : undefined;
16
- let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
13
+ export function subscribeToVisibilityChange(cb, toHiddenOnly = false, capture, abortSignal) {
17
14
  documentAddEventListener('visibilitychange', handleVisibilityChange, capture, abortSignal);
18
15
  function handleVisibilityChange() {
19
16
  if (toHiddenOnly) {
@@ -75,14 +75,11 @@ export function wrapEvents(sharedEE) {
75
75
  * @param {Function} cb - the function to run on the ancestral object once found, accepts an object as a arg
76
76
  * @param {Array} rest - [optional] any additional arguments to pass to the cb
77
77
  */
78
- function findEventListenerProtoAndCb(object, cb) {
78
+ function findEventListenerProtoAndCb(object, cb, ...rest) {
79
79
  let step = object;
80
80
  while (typeof step === 'object' && !Object.prototype.hasOwnProperty.call(step, ADD_EVENT_LISTENER)) {
81
81
  step = Object.getPrototypeOf(step);
82
82
  }
83
- for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
84
- rest[_key - 2] = arguments[_key];
85
- }
86
83
  if (step) cb(step, ...rest);
87
84
  }
88
85
 
@@ -104,13 +104,10 @@ export function wrapPromise(sharedEE) {
104
104
 
105
105
  // Note that this wrapping affects the same originals.PR (prototype) object.
106
106
  const prevPromiseOrigThen = prevPromiseObj.prototype.then;
107
- prevPromiseObj.prototype.then = function wrappedThen() {
107
+ prevPromiseObj.prototype.then = function wrappedThen(...args) {
108
108
  var originalThis = this;
109
109
  var ctx = getContext(originalThis);
110
110
  ctx.promise = originalThis;
111
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
112
- args[_key] = arguments[_key];
113
- }
114
111
  args[0] = promiseWrapper(args[0], 'cb-', ctx, null, false);
115
112
  args[1] = promiseWrapper(args[1], 'cb-', ctx, null, false);
116
113
  const origFnCallWithThis = prevPromiseOrigThen.apply(this, args);
@@ -0,0 +1,67 @@
1
+ import { globalScope } from '../constants/runtime';
2
+ import { now } from '../timing/now';
3
+ import { checkState } from '../window/load';
4
+ import { generateRandomHexString } from '../ids/unique-id';
5
+ import { gosNREUMOriginals } from '../window/nreum';
6
+ export const WEBSOCKET_TAG = 'websocket-';
7
+ export const ADD_EVENT_LISTENER_TAG = 'addEventListener';
8
+ const wrapped = {};
9
+ export function wrapWebSocket(sharedEE) {
10
+ if (wrapped[sharedEE.debugId]++) return sharedEE;
11
+ const originals = gosNREUMOriginals().o;
12
+ if (!originals.WS) return sharedEE;
13
+ function reporter(socketId) {
14
+ const createdAt = now();
15
+ return function (message, ...data) {
16
+ const timestamp = data[0]?.timeStamp || now();
17
+ const isLoaded = checkState();
18
+ sharedEE.emit(WEBSOCKET_TAG + message, [timestamp, timestamp - createdAt, isLoaded, socketId, ...data]);
19
+ };
20
+ }
21
+ Object.defineProperty(WrappedWebSocket, 'name', {
22
+ value: 'WebSocket'
23
+ });
24
+ function WrappedWebSocket() {
25
+ const ws = new originals.WS(...arguments);
26
+ const socketId = generateRandomHexString(6);
27
+ const report = reporter(socketId);
28
+ report('new');
29
+ const events = ['message', 'error', 'open', 'close'];
30
+ /** add event listeners */
31
+ events.forEach(evt => {
32
+ ws.addEventListener(evt, function (e) {
33
+ report(ADD_EVENT_LISTENER_TAG, {
34
+ eventType: evt,
35
+ event: e
36
+ });
37
+ });
38
+ })
39
+
40
+ /** could also observe the on-events for runtime processing, but not implemented yet */
41
+
42
+ /** observe the static method send, but noteably not close, as that is currently observed with the event listener */;
43
+ ['send'].forEach(wrapStaticProperty);
44
+ function wrapStaticProperty(prop) {
45
+ const originalProp = ws[prop];
46
+ if (originalProp) {
47
+ Object.defineProperty(proxiedProp, 'name', {
48
+ value: prop
49
+ });
50
+ function proxiedProp() {
51
+ report(prop, ...arguments);
52
+ try {
53
+ return originalProp.apply(this, arguments);
54
+ } catch (err) {
55
+ report(prop + '-err', ...arguments);
56
+ // rethrow error so we don't effect execution by observing.
57
+ throw err;
58
+ }
59
+ }
60
+ ws[prop] = proxiedProp;
61
+ }
62
+ }
63
+ return ws;
64
+ }
65
+ globalScope.WebSocket = WrappedWebSocket;
66
+ return sharedEE;
67
+ }
@@ -1,5 +1,6 @@
1
1
  import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer';
2
- import { getInfo } from '../../../common/config/config';
2
+ import { getInfo } from '../../../common/config/info';
3
+ import { MAX_PAYLOAD_SIZE } from '../../../common/constants/agent-constants';
3
4
  export default class Chunk {
4
5
  constructor(events, aggregateInstance) {
5
6
  this.addString = getAddStringContext(aggregateInstance.agentIdentifier); // pass agentIdentifier here
@@ -38,6 +39,6 @@ export default class Chunk {
38
39
  if (i + 1 < events.length) insert += ';';
39
40
  this.payload += insert;
40
41
  }
41
- this.tooBig = this.payload.length * 2 > aggregateInstance.MAX_PAYLOAD_SIZE;
42
+ this.tooBig = this.payload.length * 2 > MAX_PAYLOAD_SIZE;
42
43
  }
43
44
  }