@newrelic/browser-agent 0.1.229 → 0.1.231

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 (587) hide show
  1. package/README.md +65 -2
  2. package/dist/cjs/common/browser-version/ios-version.js +4 -3
  3. package/dist/cjs/common/config/state/configurable.js +3 -2
  4. package/dist/cjs/common/config/state/info.js +1 -1
  5. package/dist/cjs/common/config/state/init.js +1 -1
  6. package/dist/cjs/common/config/state/loader-config.js +1 -1
  7. package/dist/cjs/common/config/state/runtime.js +6 -5
  8. package/dist/cjs/common/constants/env.cdn.js +29 -0
  9. package/dist/cjs/common/constants/env.js +32 -0
  10. package/dist/cjs/common/constants/env.npm.js +30 -0
  11. package/dist/cjs/common/context/shared-context.js +2 -1
  12. package/dist/cjs/common/drain/drain.js +9 -3
  13. package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
  14. package/dist/cjs/common/event-emitter/handle.test.js +58 -0
  15. package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
  16. package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
  17. package/dist/cjs/common/harvest/harvest-scheduler.js +2 -1
  18. package/dist/cjs/common/harvest/harvest.js +15 -4
  19. package/dist/cjs/common/ids/id.js +14 -6
  20. package/dist/cjs/common/ids/id.test.js +85 -0
  21. package/dist/cjs/common/ids/unique-id.js +75 -51
  22. package/dist/cjs/common/ids/unique-id.test.js +49 -0
  23. package/dist/cjs/common/timing/nav-timing.js +51 -30
  24. package/dist/cjs/common/timing/nav-timing.test.js +192 -0
  25. package/dist/cjs/common/url/clean-url.test.js +9 -0
  26. package/dist/cjs/common/url/encode.test.js +74 -0
  27. package/dist/cjs/common/url/location.js +4 -0
  28. package/dist/cjs/common/url/location.test.js +13 -0
  29. package/dist/cjs/common/url/parse-url.test.js +111 -0
  30. package/dist/cjs/common/url/protocol.js +2 -12
  31. package/dist/cjs/common/url/protocol.test.js +16 -0
  32. package/dist/cjs/common/util/console.js +2 -2
  33. package/dist/cjs/common/util/map-own.js +21 -14
  34. package/dist/cjs/common/util/map-own.test.js +49 -0
  35. package/dist/cjs/common/util/obfuscate.js +1 -1
  36. package/dist/cjs/common/util/submit-data.js +11 -3
  37. package/dist/cjs/common/window/page-visibility.js +4 -2
  38. package/dist/cjs/common/window/session-storage.js +56 -11
  39. package/dist/cjs/common/wrap/index.js +4 -4
  40. package/dist/cjs/common/wrap/wrap-events.js +10 -10
  41. package/dist/cjs/common/wrap/wrap-fetch.js +6 -8
  42. package/dist/cjs/common/wrap/wrap-function.js +4 -18
  43. package/dist/cjs/common/wrap/wrap-history.js +7 -6
  44. package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
  45. package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
  46. package/dist/cjs/common/wrap/wrap-promise.js +11 -7
  47. package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
  48. package/dist/cjs/common/wrap/wrap-raf.js +6 -6
  49. package/dist/cjs/common/wrap/wrap-timer.js +6 -6
  50. package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
  51. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  52. package/dist/cjs/features/ajax/instrument/index.js +2 -1
  53. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
  54. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +1 -2
  55. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  56. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +6 -5
  57. package/dist/cjs/features/jserrors/aggregate/index.js +35 -14
  58. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +5 -4
  59. package/dist/cjs/features/jserrors/instrument/index.js +9 -12
  60. package/dist/cjs/features/metrics/aggregate/index.js +16 -6
  61. package/dist/cjs/features/metrics/instrument/index.js +2 -1
  62. package/dist/cjs/features/metrics/instrument/workers-helper.js +9 -6
  63. package/dist/cjs/features/page_action/aggregate/index.js +12 -4
  64. package/dist/cjs/features/page_action/instrument/index.js +2 -1
  65. package/dist/cjs/features/page_view_event/aggregate/index.js +25 -10
  66. package/dist/cjs/features/page_view_event/instrument/index.js +2 -1
  67. package/dist/cjs/features/page_view_timing/aggregate/index.js +90 -61
  68. package/dist/cjs/features/page_view_timing/instrument/index.js +2 -1
  69. package/dist/cjs/features/session_trace/aggregate/index.js +69 -26
  70. package/dist/cjs/features/session_trace/instrument/index.js +2 -1
  71. package/dist/cjs/features/spa/instrument/index.js +2 -1
  72. package/dist/cjs/features/utils/instrument-base.js +8 -3
  73. package/dist/cjs/features/utils/lazy-loader.js +1 -1
  74. package/dist/cjs/index.js +9 -9
  75. package/dist/cjs/loaders/agent.js +3 -2
  76. package/dist/cjs/loaders/api/api.js +90 -22
  77. package/dist/cjs/loaders/api/apiAsync.js +3 -3
  78. package/dist/cjs/loaders/configure/configure.js +13 -7
  79. package/dist/cjs/loaders/features/enabled-features.js +1 -1
  80. package/dist/cjs/loaders/micro-agent.js +20 -14
  81. package/dist/esm/common/browser-version/ios-version.js +4 -3
  82. package/dist/esm/common/config/state/configurable.js +3 -2
  83. package/dist/esm/common/config/state/info.js +1 -1
  84. package/dist/esm/common/config/state/init.js +1 -1
  85. package/dist/esm/common/config/state/loader-config.js +1 -1
  86. package/dist/esm/common/config/state/runtime.js +3 -2
  87. package/dist/esm/common/constants/env.cdn.js +20 -0
  88. package/dist/esm/common/constants/env.js +23 -0
  89. package/dist/esm/common/constants/env.npm.js +21 -0
  90. package/dist/esm/common/context/shared-context.js +2 -1
  91. package/dist/esm/common/drain/drain.js +9 -3
  92. package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
  93. package/dist/esm/common/event-emitter/handle.test.js +54 -0
  94. package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
  95. package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
  96. package/dist/esm/common/harvest/harvest-scheduler.js +2 -1
  97. package/dist/esm/common/harvest/harvest.js +14 -3
  98. package/dist/esm/common/ids/id.js +16 -6
  99. package/dist/esm/common/ids/id.test.js +81 -0
  100. package/dist/esm/common/ids/unique-id.js +75 -51
  101. package/dist/esm/common/ids/unique-id.test.js +44 -0
  102. package/dist/esm/common/timing/nav-timing.js +51 -29
  103. package/dist/esm/common/timing/nav-timing.test.js +190 -0
  104. package/dist/esm/common/url/clean-url.test.js +7 -0
  105. package/dist/esm/common/url/encode.test.js +70 -0
  106. package/dist/esm/common/url/location.js +4 -0
  107. package/dist/esm/common/url/location.test.js +11 -0
  108. package/dist/esm/common/url/parse-url.test.js +107 -0
  109. package/dist/esm/common/url/protocol.js +3 -12
  110. package/dist/esm/common/url/protocol.test.js +14 -0
  111. package/dist/esm/common/util/console.js +2 -2
  112. package/dist/esm/common/util/map-own.js +19 -13
  113. package/dist/esm/common/util/map-own.test.js +47 -0
  114. package/dist/esm/common/util/obfuscate.js +2 -2
  115. package/dist/esm/common/util/submit-data.js +11 -3
  116. package/dist/esm/common/window/page-visibility.js +4 -2
  117. package/dist/esm/common/window/session-storage.js +54 -13
  118. package/dist/esm/common/wrap/index.js +3 -3
  119. package/dist/esm/common/wrap/wrap-events.js +11 -11
  120. package/dist/esm/common/wrap/wrap-fetch.js +7 -9
  121. package/dist/esm/common/wrap/wrap-function.js +4 -17
  122. package/dist/esm/common/wrap/wrap-history.js +8 -7
  123. package/dist/esm/common/wrap/wrap-jsonp.js +8 -7
  124. package/dist/esm/common/wrap/wrap-mutation.js +7 -6
  125. package/dist/esm/common/wrap/wrap-promise.js +11 -7
  126. package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
  127. package/dist/esm/common/wrap/wrap-raf.js +7 -7
  128. package/dist/esm/common/wrap/wrap-timer.js +7 -7
  129. package/dist/esm/common/wrap/wrap-xhr.js +7 -8
  130. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  131. package/dist/esm/features/ajax/instrument/index.js +2 -1
  132. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
  133. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +1 -2
  134. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  135. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +6 -5
  136. package/dist/esm/features/jserrors/aggregate/index.js +35 -14
  137. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +5 -4
  138. package/dist/esm/features/jserrors/instrument/index.js +9 -12
  139. package/dist/esm/features/metrics/aggregate/index.js +17 -7
  140. package/dist/esm/features/metrics/instrument/index.js +2 -1
  141. package/dist/esm/features/metrics/instrument/workers-helper.js +9 -6
  142. package/dist/esm/features/page_action/aggregate/index.js +12 -4
  143. package/dist/esm/features/page_action/instrument/index.js +2 -1
  144. package/dist/esm/features/page_view_event/aggregate/index.js +25 -10
  145. package/dist/esm/features/page_view_event/instrument/index.js +2 -1
  146. package/dist/esm/features/page_view_timing/aggregate/index.js +90 -61
  147. package/dist/esm/features/page_view_timing/instrument/index.js +2 -1
  148. package/dist/esm/features/session_trace/aggregate/index.js +69 -26
  149. package/dist/esm/features/session_trace/instrument/index.js +2 -1
  150. package/dist/esm/features/spa/instrument/index.js +2 -1
  151. package/dist/esm/features/utils/instrument-base.js +3 -2
  152. package/dist/esm/features/utils/lazy-loader.js +1 -1
  153. package/dist/esm/index.js +4 -4
  154. package/dist/esm/loaders/agent.js +3 -2
  155. package/dist/esm/loaders/api/api.js +85 -21
  156. package/dist/esm/loaders/api/apiAsync.js +3 -3
  157. package/dist/esm/loaders/configure/configure.js +14 -8
  158. package/dist/esm/loaders/features/enabled-features.js +1 -1
  159. package/dist/esm/loaders/micro-agent.js +18 -13
  160. package/dist/types/cdn/lite.d.ts +2 -0
  161. package/dist/types/cdn/lite.d.ts.map +1 -0
  162. package/dist/types/cdn/polyfills/lite.d.ts +2 -0
  163. package/dist/types/cdn/polyfills/lite.d.ts.map +1 -0
  164. package/dist/types/cdn/polyfills/pro.d.ts +2 -0
  165. package/dist/types/cdn/polyfills/pro.d.ts.map +1 -0
  166. package/dist/types/cdn/polyfills/spa.d.ts +2 -0
  167. package/dist/types/cdn/polyfills/spa.d.ts.map +1 -0
  168. package/dist/types/cdn/polyfills.d.ts +2 -0
  169. package/dist/types/cdn/polyfills.d.ts.map +1 -0
  170. package/dist/types/cdn/pro.d.ts +2 -0
  171. package/dist/types/cdn/pro.d.ts.map +1 -0
  172. package/dist/types/cdn/spa.d.ts +2 -0
  173. package/dist/types/cdn/spa.d.ts.map +1 -0
  174. package/dist/types/cdn/worker.d.ts +2 -0
  175. package/dist/types/cdn/worker.d.ts.map +1 -0
  176. package/dist/types/common/aggregate/aggregator.d.ts +11 -0
  177. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -0
  178. package/dist/types/common/browser-version/firefox-version.d.ts +2 -0
  179. package/dist/types/common/browser-version/firefox-version.d.ts.map +1 -0
  180. package/dist/types/common/browser-version/ios-version.d.ts +3 -0
  181. package/dist/types/common/browser-version/ios-version.d.ts.map +1 -0
  182. package/dist/types/common/config/config.d.ts +13 -0
  183. package/dist/types/common/config/config.d.ts.map +1 -0
  184. package/dist/types/common/config/state/configurable.d.ts +4 -0
  185. package/dist/types/common/config/state/configurable.d.ts.map +1 -0
  186. package/dist/types/common/config/state/info.d.ts +4 -0
  187. package/dist/types/common/config/state/info.d.ts.map +1 -0
  188. package/dist/types/common/config/state/init.d.ts +4 -0
  189. package/dist/types/common/config/state/init.d.ts.map +1 -0
  190. package/dist/types/common/config/state/loader-config.d.ts +3 -0
  191. package/dist/types/common/config/state/loader-config.d.ts.map +1 -0
  192. package/dist/types/common/config/state/originals.d.ts +2 -0
  193. package/dist/types/common/config/state/originals.d.ts.map +1 -0
  194. package/dist/types/common/config/state/runtime.d.ts +3 -0
  195. package/dist/types/common/config/state/runtime.d.ts.map +1 -0
  196. package/dist/types/common/constants/env.cdn.d.ts +18 -0
  197. package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
  198. package/dist/types/common/constants/env.d.ts +13 -0
  199. package/dist/types/common/constants/env.d.ts.map +1 -0
  200. package/dist/types/common/constants/env.npm.d.ts +19 -0
  201. package/dist/types/common/constants/env.npm.d.ts.map +1 -0
  202. package/dist/types/common/context/shared-context.d.ts +5 -0
  203. package/dist/types/common/context/shared-context.d.ts.map +1 -0
  204. package/dist/types/common/deny-list/deny-list.d.ts +12 -0
  205. package/dist/types/common/deny-list/deny-list.d.ts.map +1 -0
  206. package/dist/types/common/drain/drain.d.ts +17 -0
  207. package/dist/types/common/drain/drain.d.ts.map +1 -0
  208. package/dist/types/common/event-emitter/contextual-ee.d.ts +4 -0
  209. package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -0
  210. package/dist/types/common/event-emitter/handle.d.ts +3 -0
  211. package/dist/types/common/event-emitter/handle.d.ts.map +1 -0
  212. package/dist/types/common/event-emitter/register-handler.d.ts +8 -0
  213. package/dist/types/common/event-emitter/register-handler.d.ts.map +1 -0
  214. package/dist/types/common/event-listener/event-listener-opts.d.ts +10 -0
  215. package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -0
  216. package/dist/types/common/harvest/harvest-scheduler.d.ts +21 -0
  217. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -0
  218. package/dist/types/common/harvest/harvest.d.ts +58 -0
  219. package/dist/types/common/harvest/harvest.d.ts.map +1 -0
  220. package/dist/types/common/ids/id.d.ts +12 -0
  221. package/dist/types/common/ids/id.d.ts.map +1 -0
  222. package/dist/types/common/ids/unique-id.d.ts +28 -0
  223. package/dist/types/common/ids/unique-id.d.ts.map +1 -0
  224. package/dist/types/common/metrics/framework-detection.d.ts +2 -0
  225. package/dist/types/common/metrics/framework-detection.d.ts.map +1 -0
  226. package/dist/types/common/metrics/paint-metrics.d.ts +2 -0
  227. package/dist/types/common/metrics/paint-metrics.d.ts.map +1 -0
  228. package/dist/types/common/serialize/bel-serializer.d.ts +5 -0
  229. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -0
  230. package/dist/types/common/timing/nav-timing.d.ts +4 -0
  231. package/dist/types/common/timing/nav-timing.d.ts.map +1 -0
  232. package/dist/types/common/timing/now.d.ts +2 -0
  233. package/dist/types/common/timing/now.d.ts.map +1 -0
  234. package/dist/types/common/unload/eol.d.ts +8 -0
  235. package/dist/types/common/unload/eol.d.ts.map +1 -0
  236. package/dist/types/common/url/clean-url.d.ts +2 -0
  237. package/dist/types/common/url/clean-url.d.ts.map +1 -0
  238. package/dist/types/common/url/encode.d.ts +5 -0
  239. package/dist/types/common/url/encode.d.ts.map +1 -0
  240. package/dist/types/common/url/location.d.ts +6 -0
  241. package/dist/types/common/url/location.d.ts.map +1 -0
  242. package/dist/types/common/url/parse-url.d.ts +2 -0
  243. package/dist/types/common/url/parse-url.d.ts.map +1 -0
  244. package/dist/types/common/url/protocol.d.ts +2 -0
  245. package/dist/types/common/url/protocol.d.ts.map +1 -0
  246. package/dist/types/common/util/console.d.ts +8 -0
  247. package/dist/types/common/util/console.d.ts.map +1 -0
  248. package/dist/types/common/util/data-size.d.ts +2 -0
  249. package/dist/types/common/util/data-size.d.ts.map +1 -0
  250. package/dist/types/common/util/feature-flags.d.ts +3 -0
  251. package/dist/types/common/util/feature-flags.d.ts.map +1 -0
  252. package/dist/types/common/util/get-or-set.d.ts +2 -0
  253. package/dist/types/common/util/get-or-set.d.ts.map +1 -0
  254. package/dist/types/common/util/global-scope.d.ts +13 -0
  255. package/dist/types/common/util/global-scope.d.ts.map +1 -0
  256. package/dist/types/common/util/map-own.d.ts +3 -0
  257. package/dist/types/common/util/map-own.d.ts.map +1 -0
  258. package/dist/types/common/util/obfuscate.d.ts +8 -0
  259. package/dist/types/common/util/obfuscate.d.ts.map +1 -0
  260. package/dist/types/common/util/s-hash.d.ts +2 -0
  261. package/dist/types/common/util/s-hash.d.ts.map +1 -0
  262. package/dist/types/common/util/single.d.ts +2 -0
  263. package/dist/types/common/util/single.d.ts.map +1 -0
  264. package/dist/types/common/util/stringify.d.ts +8 -0
  265. package/dist/types/common/util/stringify.d.ts.map +1 -0
  266. package/dist/types/common/util/submit-data.d.ts +35 -0
  267. package/dist/types/common/util/submit-data.d.ts.map +1 -0
  268. package/dist/types/common/util/traverse.d.ts +2 -0
  269. package/dist/types/common/util/traverse.d.ts.map +1 -0
  270. package/dist/types/common/util/user-agent.d.ts +5 -0
  271. package/dist/types/common/util/user-agent.d.ts.map +1 -0
  272. package/dist/types/common/window/load.d.ts +3 -0
  273. package/dist/types/common/window/load.d.ts.map +1 -0
  274. package/dist/types/common/window/nreum.d.ts +14 -0
  275. package/dist/types/common/window/nreum.d.ts.map +1 -0
  276. package/dist/types/common/window/page-visibility.d.ts +7 -0
  277. package/dist/types/common/window/page-visibility.d.ts.map +1 -0
  278. package/dist/types/common/window/session-storage.d.ts +18 -0
  279. package/dist/types/common/window/session-storage.d.ts.map +1 -0
  280. package/dist/types/common/window/supports-performance-observer.d.ts +2 -0
  281. package/dist/types/common/window/supports-performance-observer.d.ts.map +1 -0
  282. package/dist/types/common/wrap/index.d.ts +11 -0
  283. package/dist/types/common/wrap/index.d.ts.map +1 -0
  284. package/dist/types/common/wrap/wrap-events.d.ts +17 -0
  285. package/dist/types/common/wrap/wrap-events.d.ts.map +1 -0
  286. package/dist/types/common/wrap/wrap-fetch.d.ts +18 -0
  287. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -0
  288. package/dist/types/common/wrap/wrap-function.d.ts +28 -0
  289. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -0
  290. package/dist/types/common/wrap/wrap-history.d.ts +16 -0
  291. package/dist/types/common/wrap/wrap-history.d.ts.map +1 -0
  292. package/dist/types/common/wrap/wrap-jsonp.d.ts +16 -0
  293. package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -0
  294. package/dist/types/common/wrap/wrap-mutation.d.ts +16 -0
  295. package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -0
  296. package/dist/types/common/wrap/wrap-promise.d.ts +17 -0
  297. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -0
  298. package/dist/types/common/wrap/wrap-raf.d.ts +16 -0
  299. package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -0
  300. package/dist/types/common/wrap/wrap-timer.d.ts +17 -0
  301. package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -0
  302. package/dist/types/common/wrap/wrap-xhr.d.ts +16 -0
  303. package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -0
  304. package/dist/types/features/ajax/aggregate/index.d.ts +16 -0
  305. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -0
  306. package/dist/types/features/ajax/constants.d.ts +2 -0
  307. package/dist/types/features/ajax/constants.d.ts.map +1 -0
  308. package/dist/types/features/ajax/index.d.ts +2 -0
  309. package/dist/types/features/ajax/index.d.ts.map +1 -0
  310. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +19 -0
  311. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -0
  312. package/dist/types/features/ajax/instrument/index.d.ts +9 -0
  313. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -0
  314. package/dist/types/features/ajax/instrument/response-size.d.ts +2 -0
  315. package/dist/types/features/ajax/instrument/response-size.d.ts.map +1 -0
  316. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +2 -0
  317. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -0
  318. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +22 -0
  319. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -0
  320. package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts +3 -0
  321. package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts.map +1 -0
  322. package/dist/types/features/jserrors/aggregate/index.d.ts +24 -0
  323. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -0
  324. package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts +2 -0
  325. package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts.map +1 -0
  326. package/dist/types/features/jserrors/constants.d.ts +3 -0
  327. package/dist/types/features/jserrors/constants.d.ts.map +1 -0
  328. package/dist/types/features/jserrors/index.d.ts +2 -0
  329. package/dist/types/features/jserrors/index.d.ts.map +1 -0
  330. package/dist/types/features/jserrors/instrument/debug.d.ts +2 -0
  331. package/dist/types/features/jserrors/instrument/debug.d.ts.map +1 -0
  332. package/dist/types/features/jserrors/instrument/index.d.ts +22 -0
  333. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -0
  334. package/dist/types/features/metrics/aggregate/index.d.ts +12 -0
  335. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -0
  336. package/dist/types/features/metrics/constants.d.ts +6 -0
  337. package/dist/types/features/metrics/constants.d.ts.map +1 -0
  338. package/dist/types/features/metrics/index.d.ts +2 -0
  339. package/dist/types/features/metrics/index.d.ts.map +1 -0
  340. package/dist/types/features/metrics/instrument/index.d.ts +6 -0
  341. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -0
  342. package/dist/types/features/metrics/instrument/workers-helper.d.ts +7 -0
  343. package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -0
  344. package/dist/types/features/page_action/aggregate/index.d.ts +24 -0
  345. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -0
  346. package/dist/types/features/page_action/constants.d.ts +2 -0
  347. package/dist/types/features/page_action/constants.d.ts.map +1 -0
  348. package/dist/types/features/page_action/index.d.ts +2 -0
  349. package/dist/types/features/page_action/index.d.ts.map +1 -0
  350. package/dist/types/features/page_action/instrument/index.d.ts +6 -0
  351. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -0
  352. package/dist/types/features/page_view_event/aggregate/index.d.ts +9 -0
  353. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -0
  354. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts +8 -0
  355. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -0
  356. package/dist/types/features/page_view_event/constants.d.ts +5 -0
  357. package/dist/types/features/page_view_event/constants.d.ts.map +1 -0
  358. package/dist/types/features/page_view_event/index.d.ts +2 -0
  359. package/dist/types/features/page_view_event/index.d.ts.map +1 -0
  360. package/dist/types/features/page_view_event/instrument/index.d.ts +6 -0
  361. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -0
  362. package/dist/types/features/page_view_timing/aggregate/index.d.ts +32 -0
  363. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -0
  364. package/dist/types/features/page_view_timing/constants.d.ts +2 -0
  365. package/dist/types/features/page_view_timing/constants.d.ts.map +1 -0
  366. package/dist/types/features/page_view_timing/first-paint.d.ts +2 -0
  367. package/dist/types/features/page_view_timing/first-paint.d.ts.map +1 -0
  368. package/dist/types/features/page_view_timing/index.d.ts +2 -0
  369. package/dist/types/features/page_view_timing/index.d.ts.map +1 -0
  370. package/dist/types/features/page_view_timing/instrument/index.d.ts +6 -0
  371. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -0
  372. package/dist/types/features/page_view_timing/long-tasks.d.ts +2 -0
  373. package/dist/types/features/page_view_timing/long-tasks.d.ts.map +1 -0
  374. package/dist/types/features/session_trace/aggregate/index.d.ts +77 -0
  375. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -0
  376. package/dist/types/features/session_trace/constants.d.ts +13 -0
  377. package/dist/types/features/session_trace/constants.d.ts.map +1 -0
  378. package/dist/types/features/session_trace/index.d.ts +2 -0
  379. package/dist/types/features/session_trace/index.d.ts.map +1 -0
  380. package/dist/types/features/session_trace/instrument/index.d.ts +11 -0
  381. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -0
  382. package/dist/types/features/spa/aggregate/index.d.ts +25 -0
  383. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -0
  384. package/dist/types/features/spa/aggregate/interaction-node.d.ts +15 -0
  385. package/dist/types/features/spa/aggregate/interaction-node.d.ts.map +1 -0
  386. package/dist/types/features/spa/aggregate/interaction.d.ts +20 -0
  387. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -0
  388. package/dist/types/features/spa/aggregate/serializer.d.ts +15 -0
  389. package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -0
  390. package/dist/types/features/spa/constants.d.ts +23 -0
  391. package/dist/types/features/spa/constants.d.ts.map +1 -0
  392. package/dist/types/features/spa/index.d.ts +2 -0
  393. package/dist/types/features/spa/index.d.ts.map +1 -0
  394. package/dist/types/features/spa/instrument/index.d.ts +8 -0
  395. package/dist/types/features/spa/instrument/index.d.ts.map +1 -0
  396. package/dist/types/features/utils/aggregate-base.d.ts +4 -0
  397. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -0
  398. package/dist/types/features/utils/feature-base.d.ts +23 -0
  399. package/dist/types/features/utils/feature-base.d.ts.map +1 -0
  400. package/dist/types/features/utils/handler-cache.d.ts +22 -0
  401. package/dist/types/features/utils/handler-cache.d.ts.map +1 -0
  402. package/dist/types/features/utils/instrument-base.d.ts +27 -0
  403. package/dist/types/features/utils/instrument-base.d.ts.map +1 -0
  404. package/dist/types/features/utils/lazy-loader.d.ts +13 -0
  405. package/dist/types/features/utils/lazy-loader.d.ts.map +1 -0
  406. package/dist/types/index.d.ts +12 -0
  407. package/dist/types/index.d.ts.map +1 -0
  408. package/dist/types/loaders/agent.d.ts +20 -0
  409. package/dist/types/loaders/agent.d.ts.map +1 -0
  410. package/dist/types/loaders/api/api.d.ts +17 -0
  411. package/dist/types/loaders/api/api.d.ts.map +1 -0
  412. package/dist/types/loaders/api/apiAsync.d.ts +2 -0
  413. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -0
  414. package/dist/types/loaders/browser-agent.d.ts +9 -0
  415. package/dist/types/loaders/browser-agent.d.ts.map +1 -0
  416. package/dist/types/loaders/configure/configure.d.ts +10 -0
  417. package/dist/types/loaders/configure/configure.d.ts.map +1 -0
  418. package/dist/types/loaders/features/enabled-features.d.ts +2 -0
  419. package/dist/types/loaders/features/enabled-features.d.ts.map +1 -0
  420. package/dist/types/loaders/features/featureDependencies.d.ts +3 -0
  421. package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -0
  422. package/dist/types/loaders/features/features.d.ts +18 -0
  423. package/dist/types/loaders/features/features.d.ts.map +1 -0
  424. package/dist/types/loaders/micro-agent.d.ts +25 -0
  425. package/dist/types/loaders/micro-agent.d.ts.map +1 -0
  426. package/dist/types/loaders/worker-agent.d.ts +8 -0
  427. package/dist/types/loaders/worker-agent.d.ts.map +1 -0
  428. package/package.json +67 -59
  429. package/src/cdn/lite.js +18 -0
  430. package/src/cdn/polyfills/lite.js +7 -0
  431. package/src/cdn/polyfills/pro.js +7 -0
  432. package/src/cdn/polyfills/spa.js +7 -0
  433. package/src/cdn/polyfills.js +17 -0
  434. package/src/cdn/pro.js +27 -0
  435. package/src/cdn/spa.js +28 -0
  436. package/src/cdn/worker.js +21 -0
  437. package/src/common/aggregate/aggregator.js +171 -0
  438. package/src/common/browser-version/firefox-version.js +10 -0
  439. package/src/common/browser-version/ios-version.js +11 -0
  440. package/src/common/config/config.js +12 -0
  441. package/src/common/config/state/configurable.js +26 -0
  442. package/src/common/config/state/info.js +49 -0
  443. package/src/common/config/state/init.js +56 -0
  444. package/src/common/config/state/loader-config.js +25 -0
  445. package/src/common/config/state/originals.js +3 -0
  446. package/src/common/config/state/runtime.js +47 -0
  447. package/src/common/constants/env.cdn.js +20 -0
  448. package/src/common/constants/env.js +23 -0
  449. package/src/common/constants/env.npm.js +21 -0
  450. package/src/common/context/shared-context.js +21 -0
  451. package/src/common/deny-list/deny-list.js +116 -0
  452. package/src/common/drain/drain.js +119 -0
  453. package/src/common/event-emitter/contextual-ee.js +159 -0
  454. package/src/common/event-emitter/contextual-ee.test.js +310 -0
  455. package/src/common/event-emitter/handle.js +17 -0
  456. package/src/common/event-emitter/handle.test.js +56 -0
  457. package/src/common/event-emitter/register-handler.js +25 -0
  458. package/src/common/event-emitter/register-handler.test.js +61 -0
  459. package/src/common/event-listener/event-listener-opts.js +41 -0
  460. package/src/common/harvest/harvest-scheduler.js +112 -0
  461. package/src/common/harvest/harvest.js +248 -0
  462. package/src/common/ids/id.js +32 -0
  463. package/src/common/ids/id.test.js +92 -0
  464. package/src/common/ids/unique-id.js +104 -0
  465. package/src/common/ids/unique-id.test.js +58 -0
  466. package/src/common/metrics/framework-detection.js +71 -0
  467. package/src/common/metrics/paint-metrics.js +6 -0
  468. package/src/common/serialize/bel-serializer.js +93 -0
  469. package/src/common/timing/nav-timing.js +90 -0
  470. package/src/common/timing/nav-timing.test.js +161 -0
  471. package/src/common/timing/now.js +9 -0
  472. package/src/common/unload/eol.js +62 -0
  473. package/src/common/url/clean-url.js +10 -0
  474. package/src/common/url/clean-url.test.js +25 -0
  475. package/src/common/url/encode.js +75 -0
  476. package/src/common/url/encode.test.js +80 -0
  477. package/src/common/url/location.js +12 -0
  478. package/src/common/url/location.test.js +15 -0
  479. package/src/common/url/parse-url.js +70 -0
  480. package/src/common/url/parse-url.test.js +110 -0
  481. package/src/common/url/protocol.js +9 -0
  482. package/src/common/url/protocol.test.js +18 -0
  483. package/src/common/util/console.js +11 -0
  484. package/src/common/util/data-size.js +21 -0
  485. package/src/common/util/feature-flags.js +38 -0
  486. package/src/common/util/get-or-set.js +34 -0
  487. package/src/common/util/global-scope.js +47 -0
  488. package/src/common/util/map-own.js +22 -0
  489. package/src/common/util/map-own.test.js +52 -0
  490. package/src/common/util/obfuscate.js +73 -0
  491. package/src/common/util/s-hash.js +14 -0
  492. package/src/common/util/single.js +18 -0
  493. package/src/common/util/stringify.js +42 -0
  494. package/src/common/util/submit-data.js +101 -0
  495. package/src/common/util/traverse.js +36 -0
  496. package/src/common/util/user-agent.js +56 -0
  497. package/src/common/window/load.js +15 -0
  498. package/src/common/window/nreum.js +110 -0
  499. package/src/common/window/page-visibility.js +24 -0
  500. package/src/common/window/session-storage.js +75 -0
  501. package/src/common/window/supports-performance-observer.js +10 -0
  502. package/src/common/wrap/index.js +17 -0
  503. package/src/common/wrap/wrap-events.js +106 -0
  504. package/src/common/wrap/wrap-fetch.js +110 -0
  505. package/src/common/wrap/wrap-function.js +248 -0
  506. package/src/common/wrap/wrap-history.js +51 -0
  507. package/src/common/wrap/wrap-jsonp.js +136 -0
  508. package/src/common/wrap/wrap-mutation.js +58 -0
  509. package/src/common/wrap/wrap-promise.js +166 -0
  510. package/src/common/wrap/wrap-promise.test.js +140 -0
  511. package/src/common/wrap/wrap-raf.js +52 -0
  512. package/src/common/wrap/wrap-timer.js +69 -0
  513. package/src/common/wrap/wrap-xhr.js +214 -0
  514. package/src/features/ajax/aggregate/index.js +248 -0
  515. package/src/features/ajax/constants.js +3 -0
  516. package/src/features/ajax/index.js +1 -0
  517. package/src/features/ajax/instrument/distributed-tracing.js +166 -0
  518. package/src/features/ajax/instrument/index.js +380 -0
  519. package/src/features/ajax/instrument/response-size.js +18 -0
  520. package/src/features/jserrors/aggregate/canonical-function-name.js +14 -0
  521. package/src/features/jserrors/aggregate/canonical-function-name.test.js +13 -0
  522. package/src/features/jserrors/aggregate/compute-stack-trace.js +231 -0
  523. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +297 -0
  524. package/src/features/jserrors/aggregate/format-stack-trace.js +30 -0
  525. package/src/features/jserrors/aggregate/format-stack-trace.test.js +39 -0
  526. package/src/features/jserrors/aggregate/index.js +310 -0
  527. package/src/features/jserrors/aggregate/string-hash-code.js +17 -0
  528. package/src/features/jserrors/aggregate/string-hash-code.test.js +12 -0
  529. package/src/features/jserrors/constants.js +4 -0
  530. package/src/features/jserrors/index.js +1 -0
  531. package/src/features/jserrors/instrument/debug.js +36 -0
  532. package/src/features/jserrors/instrument/index.js +151 -0
  533. package/src/features/metrics/aggregate/index.js +133 -0
  534. package/src/features/metrics/constants.js +7 -0
  535. package/src/features/metrics/index.js +1 -0
  536. package/src/features/metrics/instrument/index.js +14 -0
  537. package/src/features/metrics/instrument/workers-helper.js +113 -0
  538. package/src/features/page_action/aggregate/index.js +113 -0
  539. package/src/features/page_action/constants.js +3 -0
  540. package/src/features/page_action/index.js +1 -0
  541. package/src/features/page_action/instrument/index.js +15 -0
  542. package/src/features/page_view_event/aggregate/index.js +143 -0
  543. package/src/features/page_view_event/aggregate/initialized-features.js +31 -0
  544. package/src/features/page_view_event/constants.js +6 -0
  545. package/src/features/page_view_event/index.js +1 -0
  546. package/src/features/page_view_event/instrument/index.js +33 -0
  547. package/src/features/page_view_timing/aggregate/index.js +257 -0
  548. package/src/features/page_view_timing/constants.js +3 -0
  549. package/src/features/page_view_timing/first-paint.js +41 -0
  550. package/src/features/page_view_timing/index.js +1 -0
  551. package/src/features/page_view_timing/instrument/index.js +30 -0
  552. package/src/features/page_view_timing/long-tasks.js +60 -0
  553. package/src/features/session_trace/aggregate/index.js +413 -0
  554. package/src/features/session_trace/constants.js +15 -0
  555. package/src/features/session_trace/index.js +1 -0
  556. package/src/features/session_trace/instrument/index.js +127 -0
  557. package/src/features/spa/aggregate/index.js +738 -0
  558. package/src/features/spa/aggregate/interaction-node.js +85 -0
  559. package/src/features/spa/aggregate/interaction-node.test.js +17 -0
  560. package/src/features/spa/aggregate/interaction.js +112 -0
  561. package/src/features/spa/aggregate/serializer.js +198 -0
  562. package/src/features/spa/constants.js +36 -0
  563. package/src/features/spa/index.js +1 -0
  564. package/src/features/spa/instrument/index.js +114 -0
  565. package/src/features/utils/aggregate-base.js +7 -0
  566. package/src/features/utils/feature-base.js +51 -0
  567. package/src/features/utils/handler-cache.js +60 -0
  568. package/src/features/utils/instrument-base.js +68 -0
  569. package/src/features/utils/lazy-loader.js +37 -0
  570. package/src/index.js +15 -0
  571. package/src/loaders/agent.js +80 -0
  572. package/src/loaders/api/api.js +175 -0
  573. package/src/loaders/api/apiAsync.js +92 -0
  574. package/src/loaders/browser-agent.js +33 -0
  575. package/src/loaders/configure/configure.js +39 -0
  576. package/src/loaders/features/enabled-features.js +16 -0
  577. package/src/loaders/features/featureDependencies.js +26 -0
  578. package/src/loaders/features/features.js +25 -0
  579. package/src/loaders/micro-agent.js +84 -0
  580. package/src/loaders/worker-agent.js +24 -0
  581. package/dist/cjs/common/constants/environment-variables.js +0 -20
  582. package/dist/cjs/common/util/reduce.js +0 -22
  583. package/dist/cjs/common/window/top-level-callers.js +0 -23
  584. package/dist/esm/common/constants/environment-variables.js +0 -11
  585. package/dist/esm/common/util/reduce.js +0 -16
  586. package/dist/esm/common/window/top-level-callers.js +0 -17
  587. package/types.ts +0 -221
@@ -0,0 +1,738 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /*eslint no-undef: "error"*/
6
+ import { registerHandler as register } from '../../../common/event-emitter/register-handler'
7
+ import { parseUrl } from '../../../common/url/parse-url'
8
+ import { shouldCollectEvent } from '../../../common/deny-list/deny-list'
9
+ import { mapOwn } from '../../../common/util/map-own'
10
+ import { navTimingValues as navTiming } from '../../../common/timing/nav-timing'
11
+ import { generateUuid } from '../../../common/ids/unique-id'
12
+ import { paintMetrics } from '../../../common/metrics/paint-metrics'
13
+ import { Interaction } from './interaction'
14
+ import { getConfigurationValue, getRuntime } from '../../../common/config/config'
15
+ import { eventListenerOpts } from '../../../common/event-listener/event-listener-opts'
16
+ import { AggregateBase } from '../../utils/aggregate-base'
17
+ import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
18
+ import { Serializer } from './serializer'
19
+ import { ee } from '../../../common/event-emitter/contextual-ee'
20
+ import * as CONSTANTS from '../constants'
21
+ import { drain } from '../../../common/drain/drain'
22
+ import { FEATURE_NAMES } from '../../../loaders/features/features'
23
+
24
+ const {
25
+ FEATURE_NAME, INTERACTION_EVENTS, MAX_TIMER_BUDGET, FN_START, FN_END, CB_START, INTERACTION_API, REMAINING,
26
+ INTERACTION, SPA_NODE, JSONP_NODE, FETCH_START, FETCH_DONE, FETCH_BODY, JSONP_END, originalSetTimeout
27
+ } = CONSTANTS
28
+ export class Aggregate extends AggregateBase {
29
+ static featureName = FEATURE_NAME
30
+ constructor (agentIdentifier, aggregator) {
31
+ super(agentIdentifier, aggregator, FEATURE_NAME)
32
+
33
+ this.state = {
34
+ initialPageURL: getRuntime(agentIdentifier).origin,
35
+ lastSeenUrl: getRuntime(agentIdentifier).origin,
36
+ lastSeenRouteName: null,
37
+ timerMap: {},
38
+ timerBudget: MAX_TIMER_BUDGET,
39
+ currentNode: null,
40
+ prevNode: null,
41
+ nodeOnLastHashUpdate: null,
42
+ initialPageLoad: null,
43
+ pageLoaded: false,
44
+ childTime: 0,
45
+ depth: 0,
46
+ harvestTimeSeconds: getConfigurationValue(agentIdentifier, 'spa.harvestTimeSeconds') || 10,
47
+ interactionsToHarvest: [],
48
+ interactionsSent: []
49
+ }
50
+
51
+ this.serializer = new Serializer(this)
52
+
53
+ const { state, serializer } = this
54
+ let { blocked } = this
55
+
56
+ const baseEE = ee.get(agentIdentifier) // <-- parent baseEE
57
+ const mutationEE = baseEE.get('mutation')
58
+ const promiseEE = baseEE.get('promise')
59
+ const historyEE = baseEE.get('history')
60
+ const eventsEE = baseEE.get('events') // ajax --> ee(123).emit() ee()
61
+ const timerEE = baseEE.get('timer')
62
+ const fetchEE = baseEE.get('fetch')
63
+ const jsonpEE = baseEE.get('jsonp')
64
+ const xhrEE = baseEE.get('xhr')
65
+ const tracerEE = baseEE.get('tracer')
66
+
67
+ const scheduler = new HarvestScheduler('events', {
68
+ onFinished: onHarvestFinished,
69
+ retryDelay: state.harvestTimeSeconds
70
+ }, { agentIdentifier })
71
+ scheduler.harvest.on('events', onHarvestStarted)
72
+
73
+ // childTime is used when calculating exclusive time for a cb duration.
74
+ //
75
+ // Exclusive time will be different than the total time for either callbacks
76
+ // which synchronously invoke a customTracer callback or, trigger a synchronous
77
+ // event (eg. onreadystate=1 or popstate).
78
+ //
79
+ // At fn-end, childTime will contain the total time of all timed callbacks and
80
+ // event handlers which executed as a child of the current callback. At the
81
+ // begining of every callback, childTime is saved to the event context (which at
82
+ // that time contains the sum of its preceeding siblings) and is reset to 0. The
83
+ // callback is then executed, and its children may increase childTime. At the
84
+ // end of the callback, it reports its exclusive time as its
85
+ // execution time - exlcuded. childTime is then reset to its previous
86
+ // value, and the totalTime of the callback that just finished executing is
87
+ // added to the childTime time.
88
+ // | clock | childTime | ctx.ct | totalTime | exclusive |
89
+ // click fn-start | 0 | 0 | 0 | | |
90
+ // | click begining: | 5 | 0 | 0 | | |
91
+ // | | custom-1 fn-start | 10 | 0 | 0 | | |
92
+ // | | | custom-1 begining | 15 | 0 | 0 | | |
93
+ // | | | | custom-2 fn-start | 20 | 0 | 0 | | |
94
+ // | | | | | custom-2 | 25 | 0 | 0 | | |
95
+ // | | | | custom-2 fn-end | 30 | 10 | 0 | 10 | 10 |
96
+ // | | | custom-1 middle | 35 | 10 | 0 | | |
97
+ // | | | | custom-3 fn-start | 40 | 0 | 10 | | |
98
+ // | | | | | custom-3 | 45 | 0 | 10 | | |
99
+ // | | | | custom-3 fn-end | 50 | 20 | 0 | 10 | 10 |
100
+ // | | | custom-1 ending | 55 | 20 | 0 | | |
101
+ // | custom-1 fn-end | 60 | 50 | 0 | 50 | 30 |
102
+ // | click ending: | 65 | 50 | | | |
103
+ // click fn-end | 70 | 0 | 0 | 70 | 20 |
104
+
105
+ // if rum response determines that customer lacks entitlements for spa endpoint, block it
106
+ register('block-spa', () => {
107
+ blocked = true
108
+ scheduler.stopTimer(true)
109
+ }, this.featureName, baseEE)
110
+
111
+ if (!isEnabled()) return
112
+
113
+ state.initialPageLoad = new Interaction('initialPageLoad', 0, state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentIdentifier)
114
+ state.initialPageLoad.save = true
115
+ state.prevInteraction = state.initialPageLoad
116
+ state.currentNode = state.initialPageLoad.root // hint
117
+ // ensure that checkFinish calls are safe during initialPageLoad
118
+ state.initialPageLoad[REMAINING]++
119
+
120
+ register(FN_START, callbackStart, this.featureName, baseEE)
121
+ register(CB_START, callbackStart, this.featureName, promiseEE)
122
+
123
+ // register plugins
124
+ var pluginApi = {
125
+ getCurrentNode: getCurrentNode,
126
+ setCurrentNode: setCurrentNode
127
+ }
128
+
129
+ register('spa-register', function (init) {
130
+ if (typeof init === 'function') {
131
+ init(pluginApi)
132
+ }
133
+ }, FEATURE_NAMES.spa, baseEE)
134
+
135
+ function callbackStart () {
136
+ state.depth++
137
+ this.prevNode = state.currentNode
138
+ this.ct = state.childTime
139
+ state.childTime = 0
140
+ state.timerBudget = MAX_TIMER_BUDGET
141
+ }
142
+
143
+ register(FN_END, callbackEnd, this.featureName, baseEE)
144
+ register('cb-end', callbackEnd, this.featureName, promiseEE)
145
+
146
+ function callbackEnd () {
147
+ state.depth--
148
+ var totalTime = this.jsTime || 0
149
+ var exclusiveTime = totalTime - state.childTime
150
+ state.childTime = this.ct + totalTime
151
+ if (state.currentNode) {
152
+ // transfer accumulated callback time to the active interaction node
153
+ // run even if jsTime is 0 to update jsEnd
154
+ state.currentNode.callback(exclusiveTime, this[FN_END])
155
+ if (this.isTraced) {
156
+ state.currentNode.attrs.tracedTime = exclusiveTime
157
+ }
158
+ }
159
+
160
+ this.jsTime = state.currentNode ? 0 : exclusiveTime
161
+ setCurrentNode(this.prevNode)
162
+ this.prevNode = null
163
+ state.timerBudget = MAX_TIMER_BUDGET
164
+ }
165
+
166
+ register(FN_START, function (args, eventSource) {
167
+ var ev = args[0]
168
+ var evName = ev.type
169
+ var eventNode = ev.__nrNode
170
+
171
+ if (!state.pageLoaded && evName === 'load' && eventSource === window) {
172
+ state.pageLoaded = true
173
+ // set to null so prevNode is set correctly
174
+ this.prevNode = state.currentNode = null
175
+ if (state.initialPageLoad) {
176
+ eventNode = state.initialPageLoad.root
177
+
178
+ // Even if initialPageLoad has remaining callbacks, force the initialPageLoad
179
+ // interaction to complete when the page load event occurs.
180
+ state.initialPageLoad[REMAINING] = 0
181
+
182
+ originalSetTimeout(function () {
183
+ INTERACTION_EVENTS.push('popstate')
184
+ })
185
+ }
186
+ }
187
+
188
+ if (eventNode) {
189
+ // If we've already seen a previous handler for this specific event object,
190
+ // just restore that. We want multiple handlers for the same event to share
191
+ // a node.
192
+ setCurrentNode(eventNode)
193
+ } else if (evName === 'hashchange') {
194
+ setCurrentNode(state.nodeOnLastHashUpdate)
195
+ state.nodeOnLastHashUpdate = null
196
+ } else if (eventSource instanceof XMLHttpRequest) {
197
+ // If this event was emitted by an XHR, restore the node ID associated with
198
+ // that XHR.
199
+ setCurrentNode(baseEE.context(eventSource).spaNode)
200
+ } else if (!state.currentNode) {
201
+ // Otherwise, if no interaction is currently active, create a new node ID,
202
+ // and let the aggregator know that we entered a new event handler callback
203
+ // so that it has a chance to possibly start an interaction.
204
+ if (INTERACTION_EVENTS.indexOf(evName) !== -1) {
205
+ var ixn = new Interaction(evName, this[FN_START], state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentIdentifier)
206
+
207
+ // Store the interaction as prevInteraction in case it is prematurely discarded
208
+ state.prevInteraction = ixn
209
+
210
+ setCurrentNode(ixn.root)
211
+
212
+ if (evName === 'click') {
213
+ var value = getActionText(ev.target)
214
+ if (value) {
215
+ state.currentNode.attrs.custom['actionText'] = value
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ ev.__nrNode = state.currentNode
222
+ }, this.featureName, eventsEE)
223
+
224
+ /**
225
+ * *** TIMERS ***
226
+ * setTimeout call needs to keep the interaction active in case a node is started
227
+ * in its callback.
228
+ */
229
+
230
+ // The context supplied to this callback will be shared with the fn-start/fn-end
231
+ // callbacks that fire around the callback passed to setTimeout originally.
232
+ register('setTimeout-end', function saveId (args, obj, timerId) {
233
+ if (!state.currentNode || (state.timerBudget - this.timerDuration) < 0) return
234
+ if (args && !(args[0] instanceof Function)) return
235
+ state.currentNode[INTERACTION][REMAINING]++
236
+ this.timerId = timerId
237
+ state.timerMap[timerId] = state.currentNode
238
+ this.timerBudget = state.timerBudget - 50
239
+ }, this.featureName, timerEE)
240
+
241
+ register('clearTimeout-start', function clear (args) {
242
+ var timerId = args[0]
243
+ var node = state.timerMap[timerId]
244
+ if (node) {
245
+ var interaction = node[INTERACTION]
246
+ interaction[REMAINING]--
247
+ interaction.checkFinish()
248
+ delete state.timerMap[timerId]
249
+ }
250
+ }, this.featureName, timerEE)
251
+
252
+ register(FN_START, function () {
253
+ state.timerBudget = this.timerBudget || MAX_TIMER_BUDGET
254
+ var id = this.timerId
255
+ var node = state.timerMap[id]
256
+ setCurrentNode(node)
257
+ delete state.timerMap[id]
258
+ if (node) node[INTERACTION][REMAINING]--
259
+ }, this.featureName, timerEE)
260
+
261
+ /**
262
+ * *** XHR ***
263
+ * - `new-xhr` event is fired when new instance of XHR is created. Here we create
264
+ * a new node and store it on the XHR object.
265
+ * - When the send method is called (`send-xhr-start` event), we tell the interaction
266
+ * to wait for this XHR to complete.
267
+ * - When any direct event handlers are invoked (`fn-start` on the `xhr` emitter),
268
+ * we restore the node in case other child nodes are started here.
269
+ * - Callbacks attached using `addEventListener` are handled using `fn-start` on the
270
+ * `events` emitter.
271
+ * - When `xhr-resolved` is emitted, we end the node. The node.finish() call also
272
+ * instructs the interaction to stop waiting for this node.
273
+ */
274
+
275
+ // context is shared with new-xhr event, and is stored on the xhr iteself.
276
+ register(FN_START, function () {
277
+ setCurrentNode(this[SPA_NODE])
278
+ }, this.featureName, xhrEE)
279
+
280
+ // context is stored on the xhr and is shared with all callbacks associated
281
+ // with the new xhr
282
+ register('new-xhr', function () {
283
+ if (!state.currentNode && state.prevInteraction && !state.prevInteraction.ignored) {
284
+ /*
285
+ * The previous interaction was discarded before a route change. Restore the interaction
286
+ * in case this XHR is associated with a route change.
287
+ */
288
+ const interaction = state.prevInteraction
289
+ state.currentNode = interaction.root
290
+ interaction.root.end = null
291
+ }
292
+
293
+ if (state.currentNode) {
294
+ this[SPA_NODE] = state.currentNode.child('ajax', null, null, true)
295
+ }
296
+ }, this.featureName, xhrEE)
297
+
298
+ register('send-xhr-start', function () {
299
+ var node = this[SPA_NODE]
300
+ if (node && !this.sent) {
301
+ this.sent = true
302
+ node.dt = this.dt
303
+ node.jsEnd = node.start = this.startTime
304
+ node[INTERACTION][REMAINING]++
305
+ }
306
+ }, this.featureName, xhrEE)
307
+
308
+ register('xhr-resolved', function () {
309
+ var node = this[SPA_NODE]
310
+ if (node) {
311
+ if (!shouldCollectEvent(this.params)) {
312
+ node.cancel()
313
+ return
314
+ }
315
+
316
+ var attrs = node.attrs
317
+ attrs.params = this.params
318
+ attrs.metrics = this.metrics
319
+
320
+ node.finish(this.endTime)
321
+ if (!!this.currentNode && !!this.currentNode.interaction) this.currentNode.interaction.checkFinish()
322
+ }
323
+ }, this.featureName, baseEE)
324
+
325
+ /**
326
+ * *** JSONP ***
327
+ *
328
+ */
329
+
330
+ register('new-jsonp', function (url) {
331
+ if (state.currentNode) {
332
+ var node = this[JSONP_NODE] = state.currentNode.child('ajax', this[FETCH_START])
333
+ node.start = this['new-jsonp']
334
+ this.url = url
335
+ this.status = null
336
+ }
337
+ }, this.featureName, jsonpEE)
338
+
339
+ register('cb-start', function (args) {
340
+ var node = this[JSONP_NODE]
341
+ if (node) {
342
+ setCurrentNode(node)
343
+ this.status = 200
344
+ }
345
+ }, this.featureName, jsonpEE)
346
+
347
+ register('jsonp-error', function () {
348
+ var node = this[JSONP_NODE]
349
+ if (node) {
350
+ setCurrentNode(node)
351
+ this.status = 0
352
+ }
353
+ }, this.featureName, jsonpEE)
354
+
355
+ register(JSONP_END, function () {
356
+ var node = this[JSONP_NODE]
357
+ if (node) {
358
+ // if no status is set then cb never fired - so it's not a valid JSONP
359
+ if (this.status === null) {
360
+ node.cancel()
361
+ return
362
+ }
363
+ var attrs = node.attrs
364
+ var params = attrs.params = {}
365
+
366
+ var parsed = parseUrl(this.url)
367
+ params.method = 'GET'
368
+ params.pathname = parsed.pathname
369
+ params.host = parsed.hostname + ':' + parsed.port
370
+ params.status = this.status
371
+
372
+ attrs.metrics = {
373
+ txSize: 0,
374
+ rxSize: 0
375
+ }
376
+
377
+ attrs.isJSONP = true
378
+ node.jsEnd = this[JSONP_END]
379
+ node.jsTime = this[CB_START] ? (this[JSONP_END] - this[CB_START]) : 0
380
+ node.finish(node.jsEnd)
381
+ }
382
+ }, this.featureName, jsonpEE)
383
+
384
+ register(FETCH_START, function (fetchArguments, dtPayload) {
385
+ if (fetchArguments) {
386
+ if (!state.currentNode && state.prevInteraction && !state.prevInteraction.ignored) {
387
+ /*
388
+ * The previous interaction was discarded before a route change. Restore the interaction
389
+ * in case this XHR is associated with a route change.
390
+ */
391
+ const interaction = state.prevInteraction
392
+ state.currentNode = interaction.root
393
+ interaction.root.end = null
394
+ }
395
+
396
+ if (state.currentNode) {
397
+ this[SPA_NODE] = state.currentNode.child('ajax', this[FETCH_START])
398
+ if (dtPayload && this[SPA_NODE]) this[SPA_NODE].dt = dtPayload
399
+ }
400
+ }
401
+ }, this.featureName, fetchEE)
402
+
403
+ register(FETCH_BODY + 'start', function (args) {
404
+ if (state.currentNode) {
405
+ this[SPA_NODE] = state.currentNode
406
+ state.currentNode[INTERACTION][REMAINING]++
407
+ }
408
+ }, this.featureName, fetchEE)
409
+
410
+ register(FETCH_BODY + 'end', function (args, ctx, bodyPromise) {
411
+ var node = this[SPA_NODE]
412
+ if (node) node[INTERACTION][REMAINING]--
413
+ }, this.featureName, fetchEE)
414
+
415
+ register(FETCH_DONE, function (err, res) {
416
+ var node = this[SPA_NODE]
417
+ if (node) {
418
+ if (err) {
419
+ node.cancel()
420
+ return
421
+ }
422
+
423
+ var attrs = node.attrs
424
+ attrs.params = this.params
425
+ attrs.metrics = {
426
+ txSize: this.txSize,
427
+ rxSize: this.rxSize
428
+ }
429
+ attrs.isFetch = true
430
+
431
+ node.finish(this[FETCH_DONE])
432
+ }
433
+ }, this.featureName, fetchEE)
434
+
435
+ register('newURL', function (url, hashChangedDuringCb) {
436
+ if (state.currentNode) {
437
+ state.currentNode[INTERACTION].setNewURL(url)
438
+ } else if (state.prevInteraction && !state.prevInteraction.ignored) {
439
+ /*
440
+ * The previous interaction was discarded before the route was changed. This can happen in SPA
441
+ * frameworks when using lazy loading. We have also seen this in version 11+ of Nextjs where
442
+ * some route changes re-use cached resolved promises.
443
+ */
444
+ const interaction = state.prevInteraction
445
+ interaction.setNewURL(url)
446
+ interaction.root.end = null
447
+
448
+ setCurrentNode(interaction.root)
449
+ }
450
+
451
+ if (state.currentNode) {
452
+ if (state.lastSeenUrl !== url) {
453
+ state.currentNode[INTERACTION].routeChange = true
454
+ }
455
+ if (hashChangedDuringCb) {
456
+ state.nodeOnLastHashUpdate = state.currentNode
457
+ }
458
+ }
459
+
460
+ state.lastSeenUrl = url
461
+ }, this.featureName, historyEE)
462
+
463
+ /**
464
+ * SCRIPTS
465
+ * This is only needed to keep the interaction open while external scripts are being loaded.
466
+ * The script that is loaded could continue the interaction by making additional AJAX
467
+ * calls or changing the URL. The interaction context (currentNode) needs to be
468
+ * restored somehow, but this differs based on the specific customer code. In some cases, we
469
+ * could wrap a JSONP callback, in other cases we could wrap a higher-level API, and in
470
+ * some cases we may not be able to restore context automatically (customer would need
471
+ * to instrument their code manually).
472
+ *
473
+ * - We do not restore the original context in the load/error callbacks. This would not
474
+ * work for the scripts themselves because by the time the load event fires, the
475
+ * script content has already been executed.
476
+ */
477
+
478
+ // dom-start is emitted when appendChild or replaceChild are called. If the element being
479
+ // inserted is script and we are inside an interaction, we will keep the interaction open
480
+ // until the script is loaded.
481
+ jsonpEE.on('dom-start', function (args) {
482
+ if (!state.currentNode) return
483
+
484
+ var el = args[0]
485
+ var isScript = (el && el.nodeName === 'SCRIPT' && el.src !== '')
486
+ var interaction = state.currentNode.interaction
487
+
488
+ if (isScript) {
489
+ // increase remaining count to keep the interaction open
490
+ interaction[REMAINING]++
491
+ el.addEventListener('load', onload, eventListenerOpts(false))
492
+ el.addEventListener('error', onerror, eventListenerOpts(false))
493
+ }
494
+
495
+ function onload () {
496
+ // decrease remaining to allow interaction to finish
497
+ interaction[REMAINING]--
498
+
499
+ // checkFinish is what initiates closing interaction, but is only called
500
+ // when setCurrentNode is called. Since we are not restoring a node here,
501
+ // we need to initiate the check manually.
502
+ // The reason we are not restoring the node here is because 1) this is not
503
+ // where the code of the external script runs (by the time the load event
504
+ // fires, it has already executed), and 2) it would require storing the context
505
+ // probably on the DOM node and restoring in all callbacks, which is a different
506
+ // use case than lazy loading.
507
+ interaction.checkFinish()
508
+ }
509
+
510
+ function onerror () {
511
+ interaction[REMAINING]--
512
+ interaction.checkFinish()
513
+ }
514
+ })
515
+
516
+ register(FN_START, function () {
517
+ setCurrentNode(state.prevNode)
518
+ }, this.featureName, mutationEE)
519
+
520
+ register('resolve-start', resolvePromise, this.featureName, promiseEE)
521
+ register('executor-err', resolvePromise, this.featureName, promiseEE)
522
+
523
+ register('propagate', saveNode, this.featureName, promiseEE)
524
+
525
+ register(CB_START, function () {
526
+ var ctx = this.getCtx ? this.getCtx() : this
527
+ setCurrentNode(ctx[SPA_NODE])
528
+ }, this.featureName, promiseEE)
529
+
530
+ register(INTERACTION_API + 'get', function (t) {
531
+ var interaction
532
+ if (state?.currentNode?.[INTERACTION]) interaction = this.ixn = state.currentNode[INTERACTION]
533
+ else if (state?.prevNode?.end === null && state?.prevNode?.[INTERACTION]?.root?.[INTERACTION]?.eventName != 'initialPageLoad') interaction = this.ixn = state.prevNode[INTERACTION]
534
+ else interaction = this.ixn = new Interaction('api', t, state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentIdentifier)
535
+ if (!state.currentNode) {
536
+ interaction.checkFinish()
537
+ if (state.depth) setCurrentNode(interaction.root)
538
+ }
539
+ }, this.featureName, baseEE)
540
+
541
+ register(INTERACTION_API + 'actionText', function (t, actionText) {
542
+ var customAttrs = this.ixn.root.attrs.custom
543
+ if (actionText) customAttrs.actionText = actionText
544
+ }, this.featureName, baseEE)
545
+
546
+ register(INTERACTION_API + 'setName', function (t, name, trigger) {
547
+ var attrs = this.ixn.root.attrs
548
+ if (name) attrs.customName = name
549
+ if (trigger) attrs.trigger = trigger
550
+ }, this.featureName, baseEE)
551
+
552
+ register(INTERACTION_API + 'setAttribute', function (t, name, value) {
553
+ this.ixn.root.attrs.custom[name] = value
554
+ }, this.featureName, baseEE)
555
+
556
+ register(INTERACTION_API + 'end', function (timestamp) {
557
+ var interaction = this.ixn
558
+ var node = activeNodeFor(interaction)
559
+ setCurrentNode(null)
560
+ node.child('customEnd', timestamp).finish(timestamp)
561
+ interaction.finish()
562
+ }, this.featureName, baseEE)
563
+
564
+ register(INTERACTION_API + 'ignore', function (t) {
565
+ this.ixn.ignored = true
566
+ }, this.featureName, baseEE)
567
+
568
+ register(INTERACTION_API + 'save', function (t) {
569
+ this.ixn.save = true
570
+ }, this.featureName, baseEE)
571
+
572
+ register(INTERACTION_API + 'tracer', function (timestamp, name, store) {
573
+ var interaction = this.ixn
574
+ var parent = activeNodeFor(interaction)
575
+ var ctx = baseEE.context(store)
576
+ if (!name) {
577
+ ctx.inc = ++interaction[REMAINING]
578
+
579
+ return (ctx[SPA_NODE] = parent)
580
+ }
581
+ ctx[SPA_NODE] = parent.child('customTracer', timestamp, name)
582
+ }, this.featureName, baseEE)
583
+
584
+ register(FN_START, tracerDone, this.featureName, tracerEE)
585
+ register('no-' + FN_START, tracerDone, this.featureName, tracerEE)
586
+
587
+ function tracerDone (timestamp, interactionContext, hasCb) {
588
+ var node = this[SPA_NODE]
589
+ if (!node) return
590
+ var interaction = node[INTERACTION]
591
+ var inc = this.inc
592
+ this.isTraced = true
593
+ if (inc) {
594
+ interaction[REMAINING]--
595
+ } else if (node) {
596
+ node.finish(timestamp)
597
+ }
598
+ hasCb ? setCurrentNode(node) : interaction.checkFinish()
599
+ }
600
+
601
+ register(INTERACTION_API + 'getContext', function (t, cb) {
602
+ var store = this.ixn.root.attrs.store
603
+ setTimeout(function () {
604
+ cb(store)
605
+ }, 0)
606
+ }, this.featureName, baseEE)
607
+
608
+ register(INTERACTION_API + 'onEnd', function (t, cb) {
609
+ this.ixn.handlers.push(cb)
610
+ }, this.featureName, baseEE)
611
+
612
+ register('api-routeName', function (t, currentRouteName) {
613
+ state.lastSeenRouteName = currentRouteName
614
+ if (state.currentNode) state.currentNode[INTERACTION].setNewRoute(currentRouteName)
615
+ }, this.featureName, baseEE)
616
+
617
+ function activeNodeFor (interaction) {
618
+ return (state.currentNode && state.currentNode[INTERACTION] === interaction) ? state.currentNode : interaction.root
619
+ }
620
+
621
+ function saveNode (val, overwrite) {
622
+ if (overwrite || !this[SPA_NODE]) this[SPA_NODE] = state.currentNode
623
+ }
624
+
625
+ function resolvePromise () {
626
+ if (!this.resolved) {
627
+ this.resolved = true
628
+ this[SPA_NODE] = state.currentNode
629
+ }
630
+ }
631
+
632
+ function getCurrentNode () {
633
+ return state.currentNode
634
+ }
635
+
636
+ function setCurrentNode (newNode) {
637
+ if (!state.pageLoaded && !newNode && state.initialPageLoad) newNode = state.initialPageLoad.root
638
+ if (state.currentNode) {
639
+ state.currentNode[INTERACTION].checkFinish()
640
+ }
641
+
642
+ state.prevNode = state.currentNode
643
+ state.currentNode = (newNode && !newNode[INTERACTION].root.end) ? newNode : null
644
+ }
645
+
646
+ function onInteractionFinished (interaction) {
647
+ if (interaction === state.initialPageLoad) state.initialPageLoad = null
648
+
649
+ var root = interaction.root
650
+ var attrs = root.attrs
651
+
652
+ // make sure that newrelic[INTERACTION]() works in end handler
653
+ state.currentNode = root
654
+ mapOwn(interaction.handlers, function (i, cb) {
655
+ cb(attrs.store)
656
+ })
657
+ setCurrentNode(null)
658
+ }
659
+
660
+ function onHarvestStarted (options) {
661
+ if (state.interactionsToHarvest.length === 0 || blocked) return {}
662
+ var payload = serializer.serializeMultiple(state.interactionsToHarvest, 0, navTiming)
663
+
664
+ if (options.retry) {
665
+ state.interactionsToHarvest.forEach(function (interaction) {
666
+ state.interactionsSent.push(interaction)
667
+ })
668
+ }
669
+ state.interactionsToHarvest = []
670
+
671
+ return { body: { e: payload } }
672
+ }
673
+
674
+ function onHarvestFinished (result) {
675
+ if (result.sent && result.retry && state.interactionsSent.length > 0) {
676
+ state.interactionsSent.forEach(function (interaction) {
677
+ state.interactionsToHarvest.push(interaction)
678
+ })
679
+ state.interactionsSent = []
680
+ }
681
+ }
682
+
683
+ baseEE.on('errorAgg', function (type, name, params, metrics) {
684
+ if (!state.currentNode) return
685
+ params._interactionId = state.currentNode.interaction.id
686
+ // do not capture parentNodeId when in root node
687
+ if (state.currentNode.type && state.currentNode.type !== 'interaction') {
688
+ params._interactionNodeId = state.currentNode.id
689
+ }
690
+ })
691
+
692
+ baseEE.on('interaction', saveInteraction)
693
+
694
+ function getActionText (node) {
695
+ var nodeType = node.tagName.toLowerCase()
696
+ var goodNodeTypes = ['a', 'button', 'input']
697
+ var isGoodNode = goodNodeTypes.indexOf(nodeType) !== -1
698
+ if (isGoodNode) {
699
+ return node.title || node.value || node.innerText
700
+ }
701
+ }
702
+
703
+ function saveInteraction (interaction) {
704
+ if (interaction.ignored || (!interaction.save && !interaction.routeChange)) {
705
+ baseEE.emit('interactionDiscarded', [interaction])
706
+ return
707
+ }
708
+
709
+ if (state.prevInteraction === interaction) {
710
+ // If the interaction is being saved, remove it from prevInteraction variable
711
+ // to prevent the interaction from possibly being sent twice or causing an internal
712
+ // recursive loop issue.
713
+ state.prevInteraction = null
714
+ }
715
+
716
+ // assign unique id, this is serialized and used to link interactions with errors
717
+ interaction.root.attrs.id = generateUuid()
718
+
719
+ if (interaction.root.attrs.trigger === 'initialPageLoad') {
720
+ interaction.root.attrs.firstPaint = paintMetrics['first-paint']
721
+ interaction.root.attrs.firstContentfulPaint = paintMetrics['first-contentful-paint']
722
+ }
723
+ baseEE.emit('interactionSaved', [interaction])
724
+ state.interactionsToHarvest.push(interaction)
725
+ scheduler.scheduleHarvest(0)
726
+ }
727
+
728
+ function isEnabled () {
729
+ var enabled = getConfigurationValue(agentIdentifier, 'spa.enabled')
730
+ if (enabled === false) {
731
+ return false
732
+ }
733
+ return true
734
+ }
735
+
736
+ drain(this.agentIdentifier, this.featureName)
737
+ }
738
+ }