@newrelic/browser-agent 1.235.0 → 1.237.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 (389) hide show
  1. package/README.md +41 -1
  2. package/dist/cjs/common/config/state/init.js +4 -0
  3. package/dist/cjs/common/config/state/runtime.js +6 -5
  4. package/dist/cjs/common/constants/env.cdn.js +2 -2
  5. package/dist/cjs/common/constants/env.npm.js +1 -1
  6. package/dist/cjs/common/constants/runtime.js +52 -0
  7. package/dist/cjs/common/deny-list/deny-list.js +14 -10
  8. package/dist/cjs/common/event-listener/event-listener-opts.js +3 -3
  9. package/dist/cjs/common/harvest/harvest-scheduler.js +22 -19
  10. package/dist/cjs/common/harvest/harvest.js +154 -148
  11. package/dist/cjs/common/harvest/types.js +54 -0
  12. package/dist/cjs/common/ids/id.js +2 -2
  13. package/dist/cjs/common/ids/unique-id.js +3 -3
  14. package/dist/cjs/common/session/session-entity.js +2 -2
  15. package/dist/cjs/common/timer/interaction-timer.js +2 -2
  16. package/dist/cjs/common/unload/eol.js +10 -11
  17. package/dist/cjs/common/url/canonicalize-url.js +2 -2
  18. package/dist/cjs/common/url/parse-url.js +3 -3
  19. package/dist/cjs/common/url/protocol.js +2 -2
  20. package/dist/cjs/common/util/submit-data.js +31 -81
  21. package/dist/cjs/common/window/nreum.js +14 -14
  22. package/dist/cjs/common/wrap/wrap-events.js +3 -3
  23. package/dist/cjs/common/wrap/wrap-fetch.js +5 -5
  24. package/dist/cjs/common/wrap/wrap-history.js +2 -2
  25. package/dist/cjs/common/wrap/wrap-jsonp.js +14 -8
  26. package/dist/cjs/common/wrap/wrap-mutation.js +2 -2
  27. package/dist/cjs/common/wrap/wrap-promise.js +2 -2
  28. package/dist/cjs/common/wrap/wrap-raf.js +2 -2
  29. package/dist/cjs/common/wrap/wrap-timer.js +4 -4
  30. package/dist/cjs/common/wrap/wrap-xhr.js +3 -3
  31. package/dist/cjs/features/ajax/aggregate/index.js +25 -28
  32. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +2 -2
  33. package/dist/cjs/features/ajax/instrument/index.js +6 -7
  34. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +1 -1
  35. package/dist/cjs/features/jserrors/aggregate/index.js +7 -4
  36. package/dist/cjs/features/jserrors/constants.js +2 -4
  37. package/dist/cjs/features/jserrors/instrument/index.js +80 -89
  38. package/dist/cjs/features/jserrors/instrument/uncaught-error.js +22 -0
  39. package/dist/cjs/features/metrics/aggregate/framework-detection.js +2 -2
  40. package/dist/cjs/features/metrics/aggregate/index.js +3 -3
  41. package/dist/cjs/features/page_action/aggregate/index.js +3 -3
  42. package/dist/cjs/features/page_view_event/aggregate/index.js +10 -11
  43. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +23 -19
  44. package/dist/cjs/features/page_view_event/instrument/index.js +2 -2
  45. package/dist/cjs/features/page_view_timing/aggregate/index.js +3 -5
  46. package/dist/cjs/features/page_view_timing/instrument/index.js +2 -2
  47. package/dist/cjs/features/session_replay/aggregate/index.js +65 -34
  48. package/dist/cjs/features/session_replay/replay-mode.js +2 -2
  49. package/dist/cjs/features/session_trace/aggregate/index.js +3 -4
  50. package/dist/cjs/features/session_trace/instrument/index.js +2 -2
  51. package/dist/cjs/features/spa/aggregate/index.js +1 -1
  52. package/dist/cjs/features/spa/instrument/index.js +2 -2
  53. package/dist/cjs/features/utils/instrument-base.js +12 -15
  54. package/dist/cjs/index.js +7 -0
  55. package/dist/cjs/loaders/agent-base.js +87 -0
  56. package/dist/cjs/loaders/agent.js +48 -1
  57. package/dist/cjs/loaders/api/api.js +3 -3
  58. package/dist/cjs/loaders/api/apiAsync.js +6 -4
  59. package/dist/cjs/loaders/api/interaction-types.js +87 -0
  60. package/dist/cjs/loaders/configure/configure.js +4 -3
  61. package/dist/cjs/loaders/micro-agent.js +32 -39
  62. package/dist/esm/common/config/state/init.js +4 -0
  63. package/dist/esm/common/config/state/runtime.js +3 -2
  64. package/dist/esm/common/constants/env.cdn.js +2 -2
  65. package/dist/esm/common/constants/env.npm.js +1 -1
  66. package/dist/esm/common/constants/runtime.js +38 -0
  67. package/dist/esm/common/deny-list/deny-list.js +14 -10
  68. package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
  69. package/dist/esm/common/harvest/harvest-scheduler.js +21 -20
  70. package/dist/esm/common/harvest/harvest.js +150 -146
  71. package/dist/esm/common/harvest/types.js +47 -0
  72. package/dist/esm/common/ids/id.js +1 -1
  73. package/dist/esm/common/ids/unique-id.js +1 -1
  74. package/dist/esm/common/session/session-entity.js +1 -1
  75. package/dist/esm/common/timer/interaction-timer.js +1 -1
  76. package/dist/esm/common/unload/eol.js +1 -2
  77. package/dist/esm/common/url/canonicalize-url.js +1 -1
  78. package/dist/esm/common/url/parse-url.js +1 -1
  79. package/dist/esm/common/url/protocol.js +1 -1
  80. package/dist/esm/common/util/submit-data.js +29 -78
  81. package/dist/esm/common/window/nreum.js +1 -1
  82. package/dist/esm/common/wrap/wrap-events.js +1 -1
  83. package/dist/esm/common/wrap/wrap-fetch.js +1 -1
  84. package/dist/esm/common/wrap/wrap-history.js +1 -1
  85. package/dist/esm/common/wrap/wrap-jsonp.js +13 -7
  86. package/dist/esm/common/wrap/wrap-mutation.js +1 -1
  87. package/dist/esm/common/wrap/wrap-promise.js +1 -1
  88. package/dist/esm/common/wrap/wrap-raf.js +1 -1
  89. package/dist/esm/common/wrap/wrap-timer.js +1 -1
  90. package/dist/esm/common/wrap/wrap-xhr.js +1 -1
  91. package/dist/esm/features/ajax/aggregate/index.js +26 -29
  92. package/dist/esm/features/ajax/instrument/distributed-tracing.js +1 -1
  93. package/dist/esm/features/ajax/instrument/index.js +1 -2
  94. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +1 -1
  95. package/dist/esm/features/jserrors/aggregate/index.js +6 -3
  96. package/dist/esm/features/jserrors/constants.js +1 -2
  97. package/dist/esm/features/jserrors/instrument/index.js +79 -88
  98. package/dist/esm/features/jserrors/instrument/uncaught-error.js +15 -0
  99. package/dist/esm/features/metrics/aggregate/framework-detection.js +1 -1
  100. package/dist/esm/features/metrics/aggregate/index.js +1 -1
  101. package/dist/esm/features/page_action/aggregate/index.js +1 -1
  102. package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
  103. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +23 -19
  104. package/dist/esm/features/page_view_event/instrument/index.js +1 -1
  105. package/dist/esm/features/page_view_timing/aggregate/index.js +2 -4
  106. package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
  107. package/dist/esm/features/session_replay/aggregate/index.js +65 -34
  108. package/dist/esm/features/session_replay/replay-mode.js +2 -2
  109. package/dist/esm/features/session_trace/aggregate/index.js +3 -4
  110. package/dist/esm/features/session_trace/instrument/index.js +1 -1
  111. package/dist/esm/features/spa/aggregate/index.js +1 -1
  112. package/dist/esm/features/spa/instrument/index.js +1 -1
  113. package/dist/esm/features/utils/instrument-base.js +11 -14
  114. package/dist/esm/index.js +1 -4
  115. package/dist/esm/loaders/agent-base.js +80 -0
  116. package/dist/esm/loaders/agent.js +48 -1
  117. package/dist/esm/loaders/api/api.js +2 -2
  118. package/dist/esm/loaders/api/apiAsync.js +3 -3
  119. package/dist/esm/loaders/api/interaction-types.js +80 -0
  120. package/dist/esm/loaders/configure/configure.js +4 -3
  121. package/dist/esm/loaders/micro-agent.js +32 -39
  122. package/dist/types/common/config/state/init.d.ts.map +1 -1
  123. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  124. package/dist/types/common/constants/runtime.d.ts +29 -0
  125. package/dist/types/common/constants/runtime.d.ts.map +1 -0
  126. package/dist/types/common/event-emitter/register-handler.d.ts +1 -1
  127. package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -1
  128. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  129. package/dist/types/common/harvest/harvest.d.ts +49 -38
  130. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  131. package/dist/types/common/harvest/types.d.ts +100 -0
  132. package/dist/types/common/harvest/types.d.ts.map +1 -0
  133. package/dist/types/common/session/session-entity.d.ts +6 -6
  134. package/dist/types/common/unload/eol.d.ts.map +1 -1
  135. package/dist/types/common/util/submit-data.d.ts +44 -64
  136. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  137. package/dist/types/common/window/nreum.d.ts +2 -2
  138. package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
  139. package/dist/types/features/ajax/aggregate/index.d.ts +5 -5
  140. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  141. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  142. package/dist/types/features/jserrors/aggregate/index.d.ts +1 -1
  143. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  144. package/dist/types/features/jserrors/constants.d.ts +0 -1
  145. package/dist/types/features/jserrors/constants.d.ts.map +1 -1
  146. package/dist/types/features/jserrors/instrument/index.d.ts +0 -13
  147. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  148. package/dist/types/features/jserrors/instrument/uncaught-error.d.ts +15 -0
  149. package/dist/types/features/jserrors/instrument/uncaught-error.d.ts.map +1 -0
  150. package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +5 -5
  151. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  152. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -1
  153. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  154. package/dist/types/features/session_replay/aggregate/index.d.ts +16 -30
  155. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  156. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  157. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  158. package/dist/types/index.d.ts +1 -0
  159. package/dist/types/loaders/agent-base.d.ts +59 -0
  160. package/dist/types/loaders/agent-base.d.ts.map +1 -0
  161. package/dist/types/loaders/agent.d.ts +39 -5
  162. package/dist/types/loaders/agent.d.ts.map +1 -1
  163. package/dist/types/loaders/api/interaction-types.d.ts +122 -0
  164. package/dist/types/loaders/api/interaction-types.d.ts.map +1 -0
  165. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  166. package/dist/types/loaders/features/features.d.ts +9 -9
  167. package/dist/types/loaders/micro-agent.d.ts +6 -6
  168. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  169. package/package.json +6 -1
  170. package/src/common/config/__mocks__/config.js +11 -0
  171. package/src/common/config/state/init.js +2 -1
  172. package/src/common/config/state/runtime.js +3 -2
  173. package/src/common/constants/__mocks__/env.js +3 -0
  174. package/src/common/constants/__mocks__/runtime.js +8 -0
  175. package/src/common/constants/env.cdn.test.js +7 -0
  176. package/src/common/constants/env.npm.test.js +7 -0
  177. package/src/common/constants/env.test.js +7 -0
  178. package/src/common/constants/runtime.js +71 -0
  179. package/src/common/constants/runtime.test.js +168 -0
  180. package/src/common/context/__mocks__/shared-context.js +8 -0
  181. package/src/common/deny-list/deny-list.js +11 -11
  182. package/src/common/deny-list/deny-list.test.js +31 -0
  183. package/src/common/event-listener/__mocks__/event-listener-opts.js +7 -0
  184. package/src/common/event-listener/event-listener-opts.js +1 -1
  185. package/src/common/harvest/__mocks__/harvest.js +13 -0
  186. package/src/common/harvest/harvest-scheduler.js +21 -20
  187. package/src/common/harvest/harvest-scheduler.test.js +496 -0
  188. package/src/common/harvest/harvest.js +142 -134
  189. package/src/common/harvest/harvest.test.js +798 -0
  190. package/src/common/harvest/types.js +47 -0
  191. package/src/common/ids/id.js +1 -1
  192. package/src/common/ids/unique-id.js +1 -1
  193. package/src/common/session/__mocks__/session-entity.js +25 -0
  194. package/src/common/session/session-entity.component-test.js +1 -1
  195. package/src/common/session/session-entity.js +1 -1
  196. package/src/common/timer/interaction-timer.js +1 -1
  197. package/src/common/timing/__mocks__/now.js +1 -0
  198. package/src/common/unload/__mocks__/eol.js +1 -0
  199. package/src/common/unload/eol.js +1 -2
  200. package/src/common/url/__mocks__/clean-url.js +1 -0
  201. package/src/common/url/__mocks__/encode.js +7 -0
  202. package/src/common/url/__mocks__/location.js +1 -0
  203. package/src/common/url/canonicalize-url.js +1 -1
  204. package/src/common/url/canonicalize-url.test.js +2 -2
  205. package/src/common/url/parse-url.js +1 -1
  206. package/src/common/url/parse-url.test.js +3 -3
  207. package/src/common/url/protocol.js +1 -1
  208. package/src/common/util/__mocks__/obfuscate.js +10 -0
  209. package/src/common/util/__mocks__/stringify.js +1 -0
  210. package/src/common/util/__mocks__/submit-data.js +5 -0
  211. package/src/common/util/__mocks__/traverse.js +1 -0
  212. package/src/common/util/submit-data.js +22 -58
  213. package/src/common/util/submit-data.test.js +30 -73
  214. package/src/common/window/nreum.js +1 -1
  215. package/src/common/wrap/wrap-events.js +1 -1
  216. package/src/common/wrap/wrap-fetch.js +1 -1
  217. package/src/common/wrap/wrap-history.js +1 -1
  218. package/src/common/wrap/wrap-jsonp.js +12 -7
  219. package/src/common/wrap/wrap-mutation.js +1 -1
  220. package/src/common/wrap/wrap-promise.js +1 -1
  221. package/src/common/wrap/wrap-promise.test.js +2 -2
  222. package/src/common/wrap/wrap-raf.js +1 -1
  223. package/src/common/wrap/wrap-timer.js +1 -1
  224. package/src/common/wrap/wrap-xhr.js +1 -1
  225. package/src/features/ajax/aggregate/index.js +26 -32
  226. package/src/features/ajax/instrument/distributed-tracing.js +1 -1
  227. package/src/features/ajax/instrument/index.js +1 -2
  228. package/src/features/jserrors/aggregate/compute-stack-trace.js +1 -1
  229. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
  230. package/src/features/jserrors/aggregate/index.js +7 -3
  231. package/src/features/jserrors/constants.js +0 -1
  232. package/src/features/jserrors/instrument/index.js +92 -88
  233. package/src/features/jserrors/instrument/uncaught-error.js +15 -0
  234. package/src/features/metrics/aggregate/framework-detection.js +1 -1
  235. package/src/features/metrics/aggregate/framework-detection.test.js +2 -2
  236. package/src/features/metrics/aggregate/index.js +1 -1
  237. package/src/features/page_action/aggregate/index.js +1 -1
  238. package/src/features/page_view_event/aggregate/index.js +1 -2
  239. package/src/features/page_view_event/aggregate/initialized-features.js +18 -14
  240. package/src/features/page_view_event/instrument/index.js +1 -1
  241. package/src/features/page_view_timing/aggregate/index.js +2 -4
  242. package/src/features/page_view_timing/instrument/index.js +1 -1
  243. package/src/features/session_replay/aggregate/index.component-test.js +17 -56
  244. package/src/features/session_replay/aggregate/index.js +47 -28
  245. package/src/features/session_replay/replay-mode.js +2 -2
  246. package/src/features/session_trace/aggregate/index.js +3 -4
  247. package/src/features/session_trace/instrument/index.js +1 -1
  248. package/src/features/spa/aggregate/index.js +1 -1
  249. package/src/features/spa/instrument/index.js +1 -1
  250. package/src/features/utils/agent-session.test.js +2 -2
  251. package/src/features/utils/instrument-base.js +11 -14
  252. package/src/features/utils/instrument-base.test.js +29 -3
  253. package/src/index.js +1 -3
  254. package/src/loaders/agent-base.js +81 -0
  255. package/src/loaders/agent.js +50 -1
  256. package/src/loaders/api/api.js +2 -2
  257. package/src/loaders/api/apiAsync.js +3 -3
  258. package/src/loaders/api/interaction-types.js +80 -0
  259. package/src/loaders/configure/configure.js +5 -4
  260. package/src/loaders/micro-agent.js +30 -31
  261. package/dist/cjs/common/browser-version/firefox-version.js +0 -17
  262. package/dist/cjs/common/browser-version/ios-version.js +0 -19
  263. package/dist/cjs/common/event-emitter/contextual-ee.test.js +0 -282
  264. package/dist/cjs/common/event-emitter/handle.test.js +0 -58
  265. package/dist/cjs/common/event-emitter/register-handler.test.js +0 -55
  266. package/dist/cjs/common/harvest/harvest-scheduler.component-test.js +0 -39
  267. package/dist/cjs/common/harvest/harvest.component-test.js +0 -224
  268. package/dist/cjs/common/ids/id.test.js +0 -85
  269. package/dist/cjs/common/ids/unique-id.test.js +0 -49
  270. package/dist/cjs/common/session/session-entity.component-test.js +0 -497
  271. package/dist/cjs/common/storage/local-storage.test.js +0 -14
  272. package/dist/cjs/common/timer/interaction-timer.component-test.js +0 -216
  273. package/dist/cjs/common/timer/timer.test.js +0 -105
  274. package/dist/cjs/common/timing/nav-timing.test.js +0 -192
  275. package/dist/cjs/common/url/canonicalize-url.test.js +0 -38
  276. package/dist/cjs/common/url/clean-url.test.js +0 -9
  277. package/dist/cjs/common/url/encode.component-test.js +0 -74
  278. package/dist/cjs/common/url/location.test.js +0 -13
  279. package/dist/cjs/common/url/parse-url.test.js +0 -111
  280. package/dist/cjs/common/url/protocol.component-test.js +0 -15
  281. package/dist/cjs/common/util/console.test.js +0 -30
  282. package/dist/cjs/common/util/data-size.test.js +0 -64
  283. package/dist/cjs/common/util/feature-flags.test.js +0 -84
  284. package/dist/cjs/common/util/get-or-set.test.js +0 -47
  285. package/dist/cjs/common/util/global-scope.js +0 -27
  286. package/dist/cjs/common/util/global-scope.test.js +0 -72
  287. package/dist/cjs/common/util/invoke.test.js +0 -49
  288. package/dist/cjs/common/util/map-own.test.js +0 -49
  289. package/dist/cjs/common/util/obfuscate.component-test.js +0 -129
  290. package/dist/cjs/common/util/stringify.test.js +0 -48
  291. package/dist/cjs/common/util/submit-data.test.js +0 -245
  292. package/dist/cjs/common/util/traverse.test.js +0 -44
  293. package/dist/cjs/common/wrap/wrap-promise.test.js +0 -119
  294. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +0 -31
  295. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +0 -383
  296. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +0 -40
  297. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +0 -27
  298. package/dist/cjs/features/jserrors/instrument/debug.js +0 -40
  299. package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +0 -137
  300. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -17
  301. package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +0 -165
  302. package/dist/cjs/features/session_replay/aggregate/index.component-test.js +0 -457
  303. package/dist/cjs/features/spa/aggregate/interaction-node.test.js +0 -16
  304. package/dist/cjs/features/utils/agent-session.test.js +0 -211
  305. package/dist/cjs/features/utils/aggregate-base.test.js +0 -110
  306. package/dist/cjs/features/utils/feature-base.test.js +0 -42
  307. package/dist/cjs/features/utils/handler-cache.test.js +0 -53
  308. package/dist/cjs/features/utils/instrument-base.test.js +0 -179
  309. package/dist/cjs/features/utils/lazy-feature-loader.test.js +0 -30
  310. package/dist/esm/common/browser-version/firefox-version.js +0 -10
  311. package/dist/esm/common/browser-version/ios-version.js +0 -11
  312. package/dist/esm/common/event-emitter/contextual-ee.test.js +0 -278
  313. package/dist/esm/common/event-emitter/handle.test.js +0 -54
  314. package/dist/esm/common/event-emitter/register-handler.test.js +0 -51
  315. package/dist/esm/common/harvest/harvest-scheduler.component-test.js +0 -37
  316. package/dist/esm/common/harvest/harvest.component-test.js +0 -222
  317. package/dist/esm/common/ids/id.test.js +0 -81
  318. package/dist/esm/common/ids/unique-id.test.js +0 -44
  319. package/dist/esm/common/session/session-entity.component-test.js +0 -495
  320. package/dist/esm/common/storage/local-storage.test.js +0 -12
  321. package/dist/esm/common/timer/interaction-timer.component-test.js +0 -214
  322. package/dist/esm/common/timer/timer.test.js +0 -103
  323. package/dist/esm/common/timing/nav-timing.test.js +0 -190
  324. package/dist/esm/common/url/canonicalize-url.test.js +0 -34
  325. package/dist/esm/common/url/clean-url.test.js +0 -7
  326. package/dist/esm/common/url/encode.component-test.js +0 -70
  327. package/dist/esm/common/url/location.test.js +0 -11
  328. package/dist/esm/common/url/parse-url.test.js +0 -107
  329. package/dist/esm/common/url/protocol.component-test.js +0 -13
  330. package/dist/esm/common/util/console.test.js +0 -28
  331. package/dist/esm/common/util/data-size.test.js +0 -60
  332. package/dist/esm/common/util/feature-flags.test.js +0 -80
  333. package/dist/esm/common/util/get-or-set.test.js +0 -45
  334. package/dist/esm/common/util/global-scope.js +0 -17
  335. package/dist/esm/common/util/global-scope.test.js +0 -70
  336. package/dist/esm/common/util/invoke.test.js +0 -47
  337. package/dist/esm/common/util/map-own.test.js +0 -47
  338. package/dist/esm/common/util/obfuscate.component-test.js +0 -125
  339. package/dist/esm/common/util/stringify.test.js +0 -46
  340. package/dist/esm/common/util/submit-data.test.js +0 -241
  341. package/dist/esm/common/util/traverse.test.js +0 -42
  342. package/dist/esm/common/wrap/wrap-promise.test.js +0 -115
  343. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +0 -29
  344. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +0 -379
  345. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +0 -38
  346. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +0 -25
  347. package/dist/esm/features/jserrors/instrument/debug.js +0 -38
  348. package/dist/esm/features/metrics/aggregate/framework-detection.test.js +0 -133
  349. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -15
  350. package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +0 -163
  351. package/dist/esm/features/session_replay/aggregate/index.component-test.js +0 -453
  352. package/dist/esm/features/spa/aggregate/interaction-node.test.js +0 -14
  353. package/dist/esm/features/utils/agent-session.test.js +0 -207
  354. package/dist/esm/features/utils/aggregate-base.test.js +0 -108
  355. package/dist/esm/features/utils/feature-base.test.js +0 -40
  356. package/dist/esm/features/utils/handler-cache.test.js +0 -51
  357. package/dist/esm/features/utils/instrument-base.test.js +0 -175
  358. package/dist/esm/features/utils/lazy-feature-loader.test.js +0 -29
  359. package/dist/types/common/browser-version/firefox-version.d.ts +0 -2
  360. package/dist/types/common/browser-version/firefox-version.d.ts.map +0 -1
  361. package/dist/types/common/browser-version/ios-version.d.ts +0 -3
  362. package/dist/types/common/browser-version/ios-version.d.ts.map +0 -1
  363. package/dist/types/common/harvest/harvest-scheduler.component-test.d.ts +0 -2
  364. package/dist/types/common/harvest/harvest-scheduler.component-test.d.ts.map +0 -1
  365. package/dist/types/common/harvest/harvest.component-test.d.ts +0 -2
  366. package/dist/types/common/harvest/harvest.component-test.d.ts.map +0 -1
  367. package/dist/types/common/session/session-entity.component-test.d.ts +0 -2
  368. package/dist/types/common/session/session-entity.component-test.d.ts.map +0 -1
  369. package/dist/types/common/timer/interaction-timer.component-test.d.ts +0 -2
  370. package/dist/types/common/timer/interaction-timer.component-test.d.ts.map +0 -1
  371. package/dist/types/common/url/encode.component-test.d.ts +0 -2
  372. package/dist/types/common/url/encode.component-test.d.ts.map +0 -1
  373. package/dist/types/common/url/protocol.component-test.d.ts +0 -2
  374. package/dist/types/common/url/protocol.component-test.d.ts.map +0 -1
  375. package/dist/types/common/util/global-scope.d.ts +0 -5
  376. package/dist/types/common/util/global-scope.d.ts.map +0 -1
  377. package/dist/types/common/util/obfuscate.component-test.d.ts +0 -2
  378. package/dist/types/common/util/obfuscate.component-test.d.ts.map +0 -1
  379. package/dist/types/features/jserrors/instrument/debug.d.ts +0 -2
  380. package/dist/types/features/jserrors/instrument/debug.d.ts.map +0 -1
  381. package/dist/types/features/session_replay/aggregate/index.component-test.d.ts +0 -2
  382. package/dist/types/features/session_replay/aggregate/index.component-test.d.ts.map +0 -1
  383. package/src/common/browser-version/firefox-version.js +0 -10
  384. package/src/common/browser-version/ios-version.js +0 -11
  385. package/src/common/harvest/harvest-scheduler.component-test.js +0 -25
  386. package/src/common/harvest/harvest.component-test.js +0 -169
  387. package/src/common/util/global-scope.js +0 -23
  388. package/src/common/util/global-scope.test.js +0 -87
  389. package/src/features/jserrors/instrument/debug.js +0 -36
@@ -13,6 +13,7 @@ var _config = require("../../../common/config/config");
13
13
  var _sessionEntity = require("../../../common/session/session-entity");
14
14
  var _aggregateBase = require("../../utils/aggregate-base");
15
15
  var _sharedChannel = require("../../../common/constants/shared-channel");
16
+ var _encode = require("../../../common/url/encode");
16
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /*
18
19
  * Copyright 2023 New Relic Corporation. All rights reserved.
@@ -36,9 +37,13 @@ const MAX_PAYLOAD_SIZE = 1000000;
36
37
  /** Unloading caps around 64kb */
37
38
  exports.MAX_PAYLOAD_SIZE = MAX_PAYLOAD_SIZE;
38
39
  const IDEAL_PAYLOAD_SIZE = 64000;
39
- /** Interval between forcing new full snapshots in "error" mode */
40
+ /** Interval between forcing new full snapshots -- 30 seconds in error mode, 5 minutes in full mode */
40
41
  exports.IDEAL_PAYLOAD_SIZE = IDEAL_PAYLOAD_SIZE;
41
- const CHECKOUT_MS = 30000;
42
+ const CHECKOUT_MS = {
43
+ [_sessionEntity.MODE.ERROR]: 30000,
44
+ [_sessionEntity.MODE.FULL]: 300000,
45
+ [_sessionEntity.MODE.OFF]: 0
46
+ };
42
47
  class Aggregate extends _aggregateBase.AggregateBase {
43
48
  static featureName = _constants.FEATURE_NAME;
44
49
  constructor(agentIdentifier, aggregator) {
@@ -70,6 +75,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
70
75
  /** Payload metadata -- Should indicate that the payload being sent contains an error. Used for query/filter purposes in UI */
71
76
  this.hasError = false;
72
77
 
78
+ /** Payload metadata -- Should indicate when a replay blob started recording. Resets each time a harvest occurs. */
79
+ this.timestamp = {
80
+ first: undefined,
81
+ last: undefined
82
+ };
83
+
73
84
  /** A value which increments with every new mutation node reported. Resets after a harvest is sent */
74
85
  this.payloadBytesEstimation = 0;
75
86
  const shouldSetup = (0, _config.getConfigurationValue)(agentIdentifier, 'privacy.cookies_enabled') === true && (0, _config.getConfigurationValue)(agentIdentifier, 'session_trace.enabled') === true;
@@ -93,7 +104,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
93
104
  });
94
105
 
95
106
  // Bespoke logic for new endpoint. This will change as downstream dependencies become solidified.
96
- this.scheduler = new _harvestScheduler.HarvestScheduler('blob', {
107
+ this.scheduler = new _harvestScheduler.HarvestScheduler('browser/blobs', {
97
108
  onFinished: this.onHarvestFinished.bind(this),
98
109
  retryDelay: this.harvestTimeSeconds,
99
110
  getPayload: this.prepareHarvest.bind(this),
@@ -113,10 +124,9 @@ class Aggregate extends _aggregateBase.AggregateBase {
113
124
  this.stopRecording();
114
125
  this.startRecording();
115
126
  this.scheduler.startTimer(this.harvestTimeSeconds);
116
- const {
117
- session
118
- } = (0, _config.getRuntime)(this.agentIdentifier);
119
- session.state.sessionReplay = this.mode;
127
+ this.syncWithSessionManager({
128
+ sessionReplay: this.mode
129
+ });
120
130
  }
121
131
  }
122
132
  }, this.featureName, this.ee);
@@ -189,17 +199,18 @@ class Aggregate extends _aggregateBase.AggregateBase {
189
199
  }
190
200
  this.startRecording();
191
201
  this.isFirstChunk = !!session.isNew;
192
- session.state.sessionReplay = this.mode;
202
+ this.syncWithSessionManager({
203
+ sessionReplay: this.mode
204
+ });
193
205
  }
194
206
  prepareHarvest() {
195
- if (this.events.length === 0) return;
207
+ if (this.events.length === 0 || this.mode !== _sessionEntity.MODE.FULL && !this.blocked) return;
196
208
  const payload = this.getHarvestContents();
197
209
  if (this.shouldCompress) {
198
210
  payload.body = gzipper(u8((0, _stringify.stringify)(payload.body)));
199
211
  this.scheduler.opts.gzip = true;
200
212
  } else {
201
213
  this.scheduler.opts.gzip = false;
202
- delete payload.qs.content_encoding;
203
214
  }
204
215
  // TODO -- Gracefully handle the buffer for retries.
205
216
  this.clearBuffer();
@@ -210,25 +221,28 @@ class Aggregate extends _aggregateBase.AggregateBase {
210
221
  const info = (0, _config.getInfo)(this.agentIdentifier);
211
222
  return {
212
223
  qs: {
213
- protocol_version: '0',
214
- content_encoding: 'gzip',
215
- browser_monitoring_key: info.licenseKey
216
- },
217
- body: {
224
+ browser_monitoring_key: info.licenseKey,
218
225
  type: 'SessionReplay',
219
- appId: Number(info.applicationID),
220
- timestamp: Date.now(),
221
- blob: JSON.stringify(this.events),
222
- // this needs to be a stringified JSON array of rrweb nodes
223
- attributes: {
226
+ app_id: info.applicationID,
227
+ protocol_version: '0',
228
+ attributes: (0, _encode.obj)({
229
+ ...(this.shouldCompress && {
230
+ content_encoding: 'gzip'
231
+ }),
232
+ 'replay.firstTimestamp': this.timestamp.first,
233
+ 'replay.lastTimestamp': this.timestamp.last,
234
+ 'replay.durationMs': this.timestamp.last - this.timestamp.first,
235
+ agentVersion: agentRuntime.version,
224
236
  session: agentRuntime.session.state.value,
225
237
  hasSnapshot: this.hasSnapshot,
226
238
  hasError: this.hasError,
227
- agentVersion: agentRuntime.version,
228
239
  isFirstChunk: this.isFirstChunk,
240
+ decompressedBytes: this.payloadBytesEstimation,
229
241
  'nr.rrweb.version': RRWEB_VERSION
230
- }
231
- }
242
+ }, MAX_PAYLOAD_SIZE - this.payloadBytesEstimation).substring(1) // remove the leading '&'
243
+ },
244
+
245
+ body: this.events
232
246
  };
233
247
  }
234
248
  onHarvestFinished(result) {
@@ -246,6 +260,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
246
260
  this.hasSnapshot = false;
247
261
  this.hasError = false;
248
262
  this.payloadBytesEstimation = 0;
263
+ this.clearTimestamps();
249
264
  }
250
265
 
251
266
  /** Begin recording using configured recording lib */
@@ -254,6 +269,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
254
269
  warn('Recording library was never imported');
255
270
  return this.abort();
256
271
  }
272
+ this.recording = true;
257
273
  const {
258
274
  blockClass,
259
275
  ignoreClass,
@@ -263,7 +279,6 @@ class Aggregate extends _aggregateBase.AggregateBase {
263
279
  maskTextSelector,
264
280
  maskAllInputs
265
281
  } = (0, _config.getConfigurationValue)(this.agentIdentifier, 'session_replay');
266
- this.hasSnapshot = true;
267
282
  // set up rrweb configurations for maximum privacy --
268
283
  // https://newrelic.atlassian.net/wiki/spaces/O11Y/pages/2792293280/2023+02+28+Browser+-+Session+Replay#Configuration-options
269
284
  const stop = recorder({
@@ -275,11 +290,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
275
290
  maskInputOptions,
276
291
  maskTextSelector,
277
292
  maskAllInputs,
278
- ...(this.mode === _sessionEntity.MODE.ERROR && {
279
- checkoutEveryNms: CHECKOUT_MS
280
- })
293
+ checkoutEveryNms: CHECKOUT_MS[this.mode]
281
294
  });
282
- this.recording = true;
283
295
  this.stopRecording = () => {
284
296
  this.recording = false;
285
297
  stop();
@@ -304,12 +316,14 @@ class Aggregate extends _aggregateBase.AggregateBase {
304
316
  // we are still waiting for an error to throw, so keep wiping the buffer over time
305
317
  this.clearBuffer();
306
318
  }
319
+ this.setTimestamps(event);
320
+ if (event.type === 2) this.hasSnapshot = true;
307
321
  this.events.push(event);
308
322
  this.payloadBytesEstimation += eventBytes;
309
323
 
310
324
  // We are making an effort to try to keep payloads manageable for unloading. If they reach the unload limit before their interval,
311
325
  // it will send immediately. This often happens on the first snapshot, which can be significantly larger than the other payloads.
312
- if (payloadSize > IDEAL_PAYLOAD_SIZE) {
326
+ if (payloadSize > IDEAL_PAYLOAD_SIZE && this.mode !== _sessionEntity.MODE.ERROR) {
313
327
  // if we've made it to the ideal size of ~64kb before the interval timer, we should send early.
314
328
  this.scheduler.runHarvest();
315
329
  }
@@ -319,7 +333,17 @@ class Aggregate extends _aggregateBase.AggregateBase {
319
333
  takeFullSnapshot() {
320
334
  if (!recorder) return;
321
335
  recorder.takeFullSnapshot();
322
- this.hasSnapshot = true;
336
+ }
337
+ setTimestamps(rrwebEvent) {
338
+ if (!rrwebEvent) return;
339
+ if (!this.timestamp.first) this.timestamp.first = rrwebEvent.timestamp;
340
+ this.timestamp.last = rrwebEvent.timestamp;
341
+ }
342
+ clearTimestamps() {
343
+ this.timestamp = {
344
+ first: undefined,
345
+ last: undefined
346
+ };
323
347
  }
324
348
 
325
349
  /** Estimate the payload size */
@@ -334,11 +358,11 @@ class Aggregate extends _aggregateBase.AggregateBase {
334
358
  this.blocked = true;
335
359
  this.mode = _sessionEntity.MODE.OFF;
336
360
  this.stopRecording();
361
+ this.syncWithSessionManager({
362
+ sessionReplay: this.mode
363
+ });
364
+ this.clearTimestamps();
337
365
  this.ee.emit('REPLAY_ABORTED');
338
- const {
339
- session
340
- } = (0, _config.getRuntime)(this.agentIdentifier);
341
- session.state.sessionReplay = this.mode;
342
366
  }
343
367
 
344
368
  /** Extensive research has yielded about an 88% compression factor on these payloads.
@@ -349,5 +373,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
349
373
  if (this.shouldCompress) return data * AVG_COMPRESSION;
350
374
  return data;
351
375
  }
376
+ syncWithSessionManager() {
377
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
378
+ const {
379
+ session
380
+ } = (0, _config.getRuntime)(this.agentIdentifier);
381
+ session.write(state);
382
+ }
352
383
  }
353
384
  exports.Aggregate = Aggregate;
@@ -20,8 +20,8 @@ async function getSessionReplayMode(agentId) {
20
20
  const newrelic = (0, _nreum.gosNREUM)();
21
21
  // Should be enabled by configuration and using an agent build that includes it (via checking that the instrument class was initialized).
22
22
  if ((0, _config.getConfigurationValue)(agentId, 'session_replay.enabled') && typeof newrelic.initializedAgents[agentId].features.session_replay === 'object') {
23
- await newrelic.initializedAgents[agentId].features.session_replay.onAggregateImported; // if Replay could not initialize, this throws a (uncaught) rejection
24
- return await _sharedChannel.sharedChannel.sessionReplayInitialized; // wait for replay to determine which mode it's after running its sampling logic
23
+ const srInitialized = await newrelic.initializedAgents[agentId].features.session_replay.onAggregateImported;
24
+ if (srInitialized) return await _sharedChannel.sharedChannel.sessionReplayInitialized; // wait for replay to determine which mode it's after running its sampling logic
25
25
  }
26
26
  } catch (e) {/* exception ==> off */}
27
27
  return _sessionEntity.MODE.OFF; // at any step of the way s.t. SR cannot be on by implication or is explicitly off
@@ -116,8 +116,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
116
116
  sessionTraceMode: _sessionEntity.MODE.OFF
117
117
  });
118
118
  operationalGate.permanentlyDecide(false);
119
- this.#scheduler?.stopTimer(true);
120
119
  if (mostRecentModeKnown === _sessionEntity.MODE.FULL) this.#scheduler?.runHarvest(); // allow queued nodes (past opGate) to final harvest, unless they were buffered in other modes
120
+ this.#scheduler?.stopTimer(true); // the 'true' arg here will forcibly block any future call to runHarvest, so the last runHarvest above must be prior
121
121
  this.#scheduler = null;
122
122
  };
123
123
 
@@ -143,9 +143,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
143
143
  this.ee.on(_sessionEntity.SESSION_EVENTS.PAUSE, () => mostRecentModeKnown = sessionEntity.state.sessionTraceMode);
144
144
  if (!sessionEntity.isNew) {
145
145
  // inherit the same mode as existing session's Trace
146
- const existingTraceMode = mostRecentModeKnown = sessionEntity.state.sessionTraceMode;
147
- if (existingTraceMode === _sessionEntity.MODE.OFF) this.isStandalone = true;
148
- controlTraceOp(existingTraceMode);
146
+ if (sessionEntity.state.sessionReplay === _sessionEntity.MODE.OFF) this.isStandalone = true;
147
+ controlTraceOp(mostRecentModeKnown = sessionEntity.state.sessionTraceMode);
149
148
  } else {
150
149
  // for new sessions, see the truth table associated with NEWRELIC-8662 wrt the new Trace behavior under session management
151
150
  const replayMode = await (0, _replayMode.getSessionReplayMode)(agentIdentifier);
@@ -10,7 +10,7 @@ var _now = require("../../../common/timing/now");
10
10
  var _instrumentBase = require("../../utils/instrument-base");
11
11
  var CONSTANTS = _interopRequireWildcard(require("../constants"));
12
12
  var _features = require("../../../loaders/features/features");
13
- var _globalScope = require("../../../common/util/global-scope");
13
+ var _runtime = require("../../../common/constants/runtime");
14
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
16
  /*
@@ -33,7 +33,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
33
33
  constructor(agentIdentifier, aggregator) {
34
34
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
35
35
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
36
- if (!_globalScope.isBrowserScope) return; // session traces not supported outside web env
36
+ if (!_runtime.isBrowserScope) return; // session traces not supported outside web env
37
37
 
38
38
  const thisInstrumentEE = this.ee;
39
39
  (0, _wrap.wrapHistory)(thisInstrumentEE);
@@ -628,7 +628,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
628
628
  function onHarvestFinished(result) {
629
629
  if (result.sent && result.retry && state.interactionsSent.length > 0) {
630
630
  state.interactionsSent.forEach(function (interaction) {
631
- state.interactionsToHarvest.push(interaction);
631
+ state.interactionsToHarvest.unshift(interaction);
632
632
  });
633
633
  state.interactionsSent = [];
634
634
  }
@@ -10,7 +10,7 @@ var _instrumentBase = require("../../utils/instrument-base");
10
10
  var _config = require("../../../common/config/config");
11
11
  var _now = require("../../../common/timing/now");
12
12
  var CONSTANTS = _interopRequireWildcard(require("../constants"));
13
- var _globalScope = require("../../../common/util/global-scope");
13
+ var _runtime = require("../../../common/constants/runtime");
14
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
16
  /*
@@ -35,7 +35,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
35
35
  constructor(agentIdentifier, aggregator) {
36
36
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
37
37
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
38
- if (!_globalScope.isBrowserScope) return; // SPA not supported outside web env
38
+ if (!_runtime.isBrowserScope) return; // SPA not supported outside web env
39
39
 
40
40
  if (!(0, _config.getRuntime)(agentIdentifier).xhrWrappable) return;
41
41
  try {
@@ -7,7 +7,7 @@ exports.InstrumentBase = void 0;
7
7
  var _drain = require("../../common/drain/drain");
8
8
  var _featureBase = require("./feature-base");
9
9
  var _load = require("../../common/window/load");
10
- var _globalScope = require("../../common/util/global-scope");
10
+ var _runtime = require("../../common/constants/runtime");
11
11
  var _console = require("../../common/util/console");
12
12
  var _features = require("../../loaders/features/features");
13
13
  var _config = require("../../common/config/config");
@@ -60,11 +60,10 @@ class InstrumentBase extends _featureBase.FeatureBase {
60
60
  importAggregator() {
61
61
  let argsObjFromInstrument = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
62
62
  if (this.featAggregate || !this.auto) return;
63
- const enableSessionTracking = _globalScope.isBrowserScope && (0, _config.getConfigurationValue)(this.agentIdentifier, 'privacy.cookies_enabled') === true;
64
- let loadedSuccessfully, loadFailed;
65
- this.onAggregateImported = new Promise((resolve, reject) => {
63
+ const enableSessionTracking = _runtime.isBrowserScope && (0, _config.getConfigurationValue)(this.agentIdentifier, 'privacy.cookies_enabled') === true;
64
+ let loadedSuccessfully;
65
+ this.onAggregateImported = new Promise(resolve => {
66
66
  loadedSuccessfully = resolve;
67
- loadFailed = reject;
68
67
  });
69
68
  const importLater = async () => {
70
69
  let session;
@@ -87,6 +86,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
87
86
  try {
88
87
  if (!this.shouldImportAgg(this.featureName, session)) {
89
88
  (0, _drain.drain)(this.agentIdentifier, this.featureName);
89
+ loadedSuccessfully(false); // aggregate module isn't loaded at all
90
90
  return;
91
91
  }
92
92
  const {
@@ -96,18 +96,18 @@ class InstrumentBase extends _featureBase.FeatureBase {
96
96
  Aggregate
97
97
  } = await lazyFeatureLoader(this.featureName, 'aggregate');
98
98
  this.featAggregate = new Aggregate(this.agentIdentifier, this.aggregator, argsObjFromInstrument);
99
- loadedSuccessfully();
99
+ loadedSuccessfully(true);
100
100
  } catch (e) {
101
101
  (0, _console.warn)("Downloading and initializing ".concat(this.featureName, " failed..."), e);
102
102
  this.abortHandler?.(); // undo any important alterations made to the page
103
103
  // not supported yet but nice to do: "abort" this agent's EE for this feature specifically
104
- loadFailed();
104
+ loadedSuccessfully(false);
105
105
  }
106
106
  };
107
107
 
108
108
  // For regular web pages, we want to wait and lazy-load the aggregator only after all page resources are loaded.
109
109
  // Non-browser scopes (i.e. workers) have no `window.load` event, so the aggregator can be lazy-loaded immediately.
110
- if (!_globalScope.isBrowserScope) importLater();else (0, _load.onWindowLoad)(() => importLater(), true);
110
+ if (!_runtime.isBrowserScope) importLater();else (0, _load.onWindowLoad)(() => importLater(), true);
111
111
  }
112
112
 
113
113
  /**
@@ -117,15 +117,12 @@ class InstrumentBase extends _featureBase.FeatureBase {
117
117
  * @returns
118
118
  */
119
119
  shouldImportAgg(featureName, session) {
120
- // if this isnt the FIRST load of a session AND
121
- // we are not actively recording SR... DO NOT run the aggregator
122
- // session replay samples can only be decided on the first load of a session
123
- // session replays can continue if in progress
124
120
  if (featureName === _features.FEATURE_NAMES.sessionReplay) {
125
- if ((0, _config.getConfigurationValue)(this.agentIdentifier, 'session_trace.enabled') === false) return false;
126
- return !!session?.isNew || !!session?.state.sessionReplay;
121
+ if (!_config.originals.MO) return false; // Session Replay cannot work without Mutation Observer
122
+ if ((0, _config.getConfigurationValue)(this.agentIdentifier, 'session_trace.enabled') === false) return false; // Session Replay as of now is tightly coupled with Session Trace in the UI
123
+ return !!session?.isNew || !!session?.state.sessionReplay; // Session Replay should only try to run if already running from a previous page, or at the beginning of a session
127
124
  }
128
- // todo -- add case like above for session trace
125
+
129
126
  return true;
130
127
  }
131
128
  }
package/dist/cjs/index.js CHANGED
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "Metrics", {
33
33
  return _metrics.Metrics;
34
34
  }
35
35
  });
36
+ Object.defineProperty(exports, "MicroAgent", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _microAgent.MicroAgent;
40
+ }
41
+ });
36
42
  Object.defineProperty(exports, "PageAction", {
37
43
  enumerable: true,
38
44
  get: function () {
@@ -72,6 +78,7 @@ Object.defineProperty(exports, "WorkerAgent", {
72
78
  var _agent = require("./loaders/agent");
73
79
  var _browserAgent = require("./loaders/browser-agent");
74
80
  var _workerAgent = require("./loaders/worker-agent");
81
+ var _microAgent = require("./loaders/micro-agent");
75
82
  var _ajax = require("./features/ajax");
76
83
  var _jserrors = require("./features/jserrors");
77
84
  var _metrics = require("./features/metrics");
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AgentBase = void 0;
7
+ var _console = require("../common/util/console");
8
+ class AgentBase {
9
+ /**
10
+ * Reports a browser PageAction event along with a name and optional attributes.
11
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addpageaction/}
12
+ * @param {string} name Name or category of the action. Reported as the actionName attribute.
13
+ * @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}. The key is reported as its own PageAction attribute with the specified values.
14
+ */
15
+ addPageAction(name, attributes) {
16
+ (0, _console.warn)('Call to agent api addPageAction failed. The session trace feature is not currently initialized.');
17
+ }
18
+
19
+ /**
20
+ * Groups page views to help URL structure or to capture the URL's routing information.
21
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setpageviewname/}
22
+ * @param {string} name The page name you want to use. Use alphanumeric characters.
23
+ * @param {string} [host] Default is http://custom.transaction. Typically set host to your site's domain URI.
24
+ */
25
+ setPageViewName(name, host) {
26
+ (0, _console.warn)('Call to agent api setPageViewName failed. The page view feature is not currently initialized.');
27
+ }
28
+
29
+ /**
30
+ * Adds a user-defined attribute name and value to subsequent events on the page.
31
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
32
+ * @param {string} name Name of the attribute. Appears as column in the PageView event. It will also appear as a column in the PageAction event if you are using it.
33
+ * @param {string|number|null} value Value of the attribute. Appears as the value in the named attribute column in the PageView event. It will appear as a column in the PageAction event if you are using it. Custom attribute values cannot be complex objects, only simple types such as Strings and Integers.
34
+ * @param {boolean} [persist] Default false. f set to true, the name-value pair will also be set into the browser's storage API. Then on the following instrumented pages that load within the same session, the pair will be re-applied as a custom attribute.
35
+ */
36
+ setCustomAttribute(name, value, persist) {
37
+ (0, _console.warn)('Call to agent api setCustomAttribute failed. The js errors feature is not currently initialized.');
38
+ }
39
+
40
+ /**
41
+ * Identifies a browser error without disrupting your app's operations.
42
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/noticeerror/}
43
+ * @param {Error|string} error Provide a meaningful error message that you can use when analyzing data on browser's JavaScript errors page.
44
+ * @param {object} [customAttributes] An object containing name/value pairs representing custom attributes.
45
+ */
46
+ noticeError(error, customAttributes) {
47
+ (0, _console.warn)('Call to agent api noticeError failed. The js errors feature is not currently initialized.');
48
+ }
49
+
50
+ /**
51
+ * Adds a user-defined identifier string to subsequent events on the page.
52
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setuserid/}
53
+ * @param {string|null} value A string identifier for the end-user, useful for tying all browser events to specific users. The value parameter does not have to be unique. If IDs should be unique, the caller is responsible for that validation. Passing a null value unsets any existing user ID.
54
+ */
55
+ setUserId(value) {
56
+ (0, _console.warn)('Call to agent api setUserId failed. The js errors feature is not currently initialized.');
57
+ }
58
+
59
+ /**
60
+ * Allows selective ignoring and grouping of known errors that the browser agent captures.
61
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/seterrorhandler/}
62
+ * @param {(error: Error|string) => boolean | { group: string }} callback When an error occurs, the callback is called with the error object as a parameter. The callback will be called with each error, so it is not specific to one error.
63
+ */
64
+ setErrorHandler(callback) {
65
+ (0, _console.warn)('Call to agent api setErrorHandler failed. The js errors feature is not currently initialized.');
66
+ }
67
+
68
+ /**
69
+ * Records an additional time point as "finished" in a session trace, and sends the event to New Relic.
70
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/finished/}
71
+ * @param {number} [timeStamp] Defaults to the current time of the call. If used, this marks the time that the page is "finished" according to your own criteria.
72
+ */
73
+ finished(timeStamp) {
74
+ (0, _console.warn)('Call to agent api finished failed. The page action feature is not currently initialized.');
75
+ }
76
+
77
+ /**
78
+ * Adds a unique name and ID to identify releases with multiple JavaScript bundles on the same page.
79
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addrelease/}
80
+ * @param {string} name A short description of the component; for example, the name of a project, application, file, or library.
81
+ * @param {string} id The ID or version of this release; for example, a version number, build number from your CI environment, GitHub SHA, GUID, or a hash of the contents.
82
+ */
83
+ addRelease(name, id) {
84
+ (0, _console.warn)('Call to agent api addRelease failed. The agent is not currently initialized.');
85
+ }
86
+ }
87
+ exports.AgentBase = AgentBase;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Agent = void 0;
7
+ var _agentBase = require("./agent-base");
7
8
  var _enabledFeatures = require("./features/enabled-features");
8
9
  var _configure = require("./configure/configure");
9
10
  var _featureDependencies = require("./features/featureDependencies");
@@ -15,19 +16,31 @@ var _uniqueId = require("../common/ids/unique-id");
15
16
  var _config = require("../common/config/config");
16
17
  var _console = require("../common/util/console");
17
18
  var _stringify = require("../common/util/stringify");
19
+ var _runtime = require("../common/constants/runtime");
18
20
  // loader files
19
21
 
20
22
  // required features
21
23
 
22
24
  // common files
23
25
 
26
+ /**
27
+ * @typedef {import('./api/interaction-types').InteractionInstance} InteractionInstance
28
+ */
29
+
24
30
  /**
25
31
  * A flexible class that may be used to compose an agent from a select subset of feature modules. In applications
26
32
  * sensitive to network load, this may result in smaller builds with slightly lower performance impact.
27
33
  */
28
- class Agent {
34
+ class Agent extends _agentBase.AgentBase {
29
35
  constructor(options) {
30
36
  let agentIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _uniqueId.generateRandomHexString)(16);
37
+ super();
38
+ if (!_runtime.globalScope) {
39
+ // We could not determine the runtime environment. Short-circuite the agent here
40
+ // to avoid possible exceptions later that may cause issues with customer's application.
41
+ (0, _console.warn)('Failed to initial the agent. Could not determine the runtime environment.');
42
+ return;
43
+ }
31
44
  this.agentIdentifier = agentIdentifier;
32
45
  this.sharedAggregator = new _aggregator.Aggregator({
33
46
  agentIdentifier: this.agentIdentifier
@@ -82,5 +95,39 @@ class Agent {
82
95
  return false;
83
96
  }
84
97
  }
98
+
99
+ /* Below API methods are only available on a standard agent and not the micro agent */
100
+
101
+ /**
102
+ * Adds a JavaScript object with a custom name, start time, etc. to an in-progress session trace.
103
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addtotrace/}
104
+ * @param {{name: string, start: number, end?: number, origin?: string, type?: string}} customAttributes Supply a JavaScript object with these required and optional name/value pairs:
105
+ *
106
+ * - Required name/value pairs: name, start
107
+ * - Optional name/value pairs: end, origin, type
108
+ *
109
+ * If you are sending the same event object to New Relic as a PageAction, omit the TYPE attribute. (type is a string to describe what type of event you are marking inside of a session trace.) If included, it will override the event type and cause the PageAction event to be sent incorrectly. Instead, use the name attribute for event information.
110
+ */
111
+ addToTrace(customAttributes) {
112
+ (0, _console.warn)('Call to agent api addToTrace failed. The page action feature is not currently initialized.');
113
+ }
114
+
115
+ /**
116
+ * Gives SPA routes more accurate names than default names. Monitors specific routes rather than by default grouping.
117
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcurrentroutename/}
118
+ * @param {string} name Current route name for the page.
119
+ */
120
+ setCurrentRouteName(name) {
121
+ (0, _console.warn)('Call to agent api setCurrentRouteName failed. The spa feature is not currently initialized.');
122
+ }
123
+
124
+ /**
125
+ * Returns a new API object that is bound to the current SPA interaction.
126
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/interaction/}
127
+ * @returns {InteractionInstance} An API object that is bound to a specific BrowserInteraction event. Each time this method is called for the same BrowserInteraction, a new object is created, but it still references the same interaction.
128
+ */
129
+ interaction() {
130
+ (0, _console.warn)('Call to agent api interaction failed. The spa feature is not currently initialized.');
131
+ }
85
132
  }
86
133
  exports.Agent = Agent;
@@ -13,7 +13,7 @@ var _contextualEe = require("../../common/event-emitter/contextual-ee");
13
13
  var _now = require("../../common/timing/now");
14
14
  var _drain = require("../../common/drain/drain");
15
15
  var _load = require("../../common/window/load");
16
- var _globalScope = require("../../common/util/global-scope");
16
+ var _runtime = require("../../common/constants/runtime");
17
17
  var _console = require("../../common/util/console");
18
18
  var _constants = require("../../features/metrics/constants");
19
19
  var _nreum = require("../../common/window/nreum");
@@ -131,7 +131,7 @@ function setAPI(agentIdentifier, forceDrain) {
131
131
  try {
132
132
  return cb.apply(this, arguments);
133
133
  } catch (err) {
134
- tracerEE.emit('fn-err', [arguments, this, typeof err == 'string' ? new Error(err) : err], contextStore);
134
+ tracerEE.emit('fn-err', [arguments, this, err], contextStore);
135
135
  // the error came from outside the agent, so don't swallow
136
136
  throw err;
137
137
  } finally {
@@ -158,7 +158,7 @@ function setAPI(agentIdentifier, forceDrain) {
158
158
  };
159
159
 
160
160
  // theres no window.load event on non-browser scopes, lazy load immediately
161
- if (!_globalScope.isBrowserScope) lazyLoad();
161
+ if (!_runtime.isBrowserScope) lazyLoad();
162
162
  // try to stay out of the way of the window.load event, lazy load once that has finished.
163
163
  else (0, _load.onWindowLoad)(() => lazyLoad(), true);
164
164
  function lazyLoad() {
@@ -10,9 +10,11 @@ var _contextualEe = require("../../common/event-emitter/contextual-ee");
10
10
  var _handle = require("../../common/event-emitter/handle");
11
11
  var _registerHandler = require("../../common/event-emitter/register-handler");
12
12
  var _invoke = require("../../common/util/invoke");
13
- var _submitData = require("../../common/util/submit-data");
14
- var _globalScope = require("../../common/util/global-scope");
13
+ var submitData = _interopRequireWildcard(require("../../common/util/submit-data"));
14
+ var _runtime = require("../../common/constants/runtime");
15
15
  var _constants = require("../../features/metrics/constants");
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
18
  function setAPI(agentIdentifier) {
17
19
  var instanceEE = _contextualEe.ee.get(agentIdentifier);
18
20
  var cycle = 0;
@@ -67,7 +69,7 @@ function setAPI(agentIdentifier) {
67
69
  // dom_time - the time spent processing the result of the service call (or user defined)
68
70
  // fe_time - the time spent rendering the result of the service call (or user defined)
69
71
  function inlineHit(t, request_name, queue_time, app_time, total_be_time, dom_time, fe_time) {
70
- if (!_globalScope.isBrowserScope) return;
72
+ if (!_runtime.isBrowserScope) return;
71
73
  request_name = window.encodeURIComponent(request_name);
72
74
  cycle += 1;
73
75
  const agentInfo = (0, _config.getInfo)(agentIdentifier);
@@ -82,7 +84,7 @@ function setAPI(agentIdentifier) {
82
84
  url += 'dc=' + ~~dom_time + '&';
83
85
  url += 'fe=' + ~~fe_time + '&';
84
86
  url += 'c=' + cycle;
85
- _submitData.submitData.img({
87
+ submitData.xhr({
86
88
  url
87
89
  });
88
90
  }