@newrelic/browser-agent 0.0.9 → 0.1.229

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 (339) hide show
  1. package/README.md +84 -207
  2. package/dist/cjs/cdn/lite.js +14 -0
  3. package/dist/cjs/cdn/polyfills/lite.js +4 -0
  4. package/dist/cjs/cdn/polyfills/pro.js +4 -0
  5. package/dist/cjs/cdn/polyfills/spa.js +4 -0
  6. package/dist/cjs/cdn/polyfills.js +14 -0
  7. package/dist/cjs/cdn/pro.js +19 -0
  8. package/dist/cjs/cdn/spa.js +19 -0
  9. package/dist/cjs/cdn/worker.js +16 -0
  10. package/dist/cjs/common/aggregate/aggregator.js +168 -0
  11. package/dist/cjs/common/browser-version/firefox-version.js +17 -0
  12. package/dist/cjs/common/browser-version/ios-version.js +18 -0
  13. package/dist/cjs/common/config/config.js +76 -0
  14. package/dist/cjs/common/config/state/configurable.js +32 -0
  15. package/dist/cjs/common/config/state/info.js +50 -0
  16. package/dist/cjs/common/config/state/init.js +86 -0
  17. package/dist/cjs/common/config/state/loader-config.js +28 -0
  18. package/dist/cjs/common/config/state/originals.js +9 -0
  19. package/dist/cjs/common/config/state/runtime.js +50 -0
  20. package/dist/cjs/common/constants/environment-variables.js +20 -0
  21. package/dist/cjs/common/context/shared-context.js +25 -0
  22. package/dist/cjs/common/deny-list/deny-list.js +108 -0
  23. package/dist/cjs/common/drain/drain.js +126 -0
  24. package/dist/cjs/common/event-emitter/contextual-ee.js +149 -0
  25. package/dist/cjs/common/event-emitter/handle.js +24 -0
  26. package/dist/cjs/common/event-emitter/register-handler.js +24 -0
  27. package/dist/cjs/common/event-listener/event-listener-opts.js +46 -0
  28. package/dist/cjs/common/harvest/harvest-scheduler.js +111 -0
  29. package/dist/cjs/common/harvest/harvest.js +236 -0
  30. package/dist/cjs/common/ids/id.js +30 -0
  31. package/dist/cjs/common/ids/unique-id.js +84 -0
  32. package/dist/cjs/common/metrics/framework-detection.js +72 -0
  33. package/dist/cjs/common/metrics/paint-metrics.js +13 -0
  34. package/dist/cjs/common/serialize/bel-serializer.js +89 -0
  35. package/dist/cjs/common/timing/nav-timing.js +77 -0
  36. package/dist/cjs/common/timing/now.js +15 -0
  37. package/dist/cjs/common/unload/eol.js +69 -0
  38. package/dist/cjs/common/url/clean-url.js +16 -0
  39. package/dist/cjs/common/url/encode.js +79 -0
  40. package/dist/cjs/common/url/location.js +14 -0
  41. package/dist/cjs/common/url/parse-url.js +66 -0
  42. package/dist/cjs/common/url/protocol.js +25 -0
  43. package/dist/cjs/common/util/console.js +17 -0
  44. package/dist/cjs/common/util/data-size.js +25 -0
  45. package/dist/cjs/common/util/feature-flags.js +42 -0
  46. package/dist/cjs/common/util/get-or-set.js +39 -0
  47. package/dist/cjs/common/util/global-scope.js +56 -0
  48. package/dist/cjs/common/util/map-own.js +24 -0
  49. package/dist/cjs/common/util/obfuscate.js +76 -0
  50. package/dist/cjs/common/util/reduce.js +22 -0
  51. package/dist/cjs/common/util/s-hash.js +19 -0
  52. package/dist/cjs/common/util/single.js +23 -0
  53. package/dist/cjs/common/util/stringify.js +47 -0
  54. package/dist/cjs/common/util/submit-data.js +99 -0
  55. package/dist/cjs/common/util/traverse.js +41 -0
  56. package/dist/cjs/common/util/user-agent.js +57 -0
  57. package/dist/cjs/common/window/load.js +19 -0
  58. package/dist/cjs/common/window/nreum.js +107 -0
  59. package/dist/cjs/common/window/page-visibility.js +28 -0
  60. package/dist/cjs/common/window/session-storage.js +42 -0
  61. package/dist/cjs/common/window/supports-performance-observer.js +15 -0
  62. package/dist/cjs/common/window/top-level-callers.js +23 -0
  63. package/dist/cjs/common/wrap/index.js +68 -0
  64. package/dist/cjs/common/wrap/wrap-events.js +105 -0
  65. package/dist/cjs/common/wrap/wrap-fetch.js +114 -0
  66. package/dist/cjs/common/wrap/wrap-function.js +269 -0
  67. package/dist/cjs/common/wrap/wrap-history.js +56 -0
  68. package/dist/cjs/common/wrap/wrap-jsonp.js +129 -0
  69. package/dist/cjs/common/wrap/wrap-mutation.js +61 -0
  70. package/dist/cjs/common/wrap/wrap-promise.js +160 -0
  71. package/dist/cjs/common/wrap/wrap-raf.js +55 -0
  72. package/dist/cjs/common/wrap/wrap-timer.js +70 -0
  73. package/dist/cjs/common/wrap/wrap-xhr.js +206 -0
  74. package/dist/cjs/features/ajax/aggregate/index.js +226 -0
  75. package/dist/cjs/features/ajax/constants.js +9 -0
  76. package/dist/cjs/features/ajax/index.js +12 -0
  77. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +145 -0
  78. package/dist/cjs/features/ajax/instrument/index.js +338 -0
  79. package/dist/cjs/features/ajax/instrument/response-size.js +26 -0
  80. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +18 -0
  81. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +30 -0
  82. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +216 -0
  83. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +257 -0
  84. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.js +36 -0
  85. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +39 -0
  86. package/dist/cjs/features/jserrors/aggregate/index.js +267 -0
  87. package/dist/cjs/features/jserrors/aggregate/string-hash-code.js +23 -0
  88. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +26 -0
  89. package/dist/cjs/features/jserrors/constants.js +11 -0
  90. package/dist/cjs/features/jserrors/index.js +12 -0
  91. package/dist/cjs/features/jserrors/instrument/debug.js +40 -0
  92. package/dist/cjs/features/jserrors/instrument/index.js +158 -0
  93. package/dist/cjs/features/metrics/aggregate/index.js +136 -0
  94. package/dist/cjs/features/metrics/constants.js +17 -0
  95. package/dist/cjs/features/metrics/index.js +12 -0
  96. package/dist/cjs/features/metrics/instrument/index.js +20 -0
  97. package/dist/cjs/features/metrics/instrument/workers-helper.js +121 -0
  98. package/dist/cjs/features/page_action/aggregate/index.js +112 -0
  99. package/dist/cjs/features/page_action/constants.js +9 -0
  100. package/dist/cjs/features/page_action/index.js +12 -0
  101. package/dist/cjs/features/page_action/instrument/index.js +21 -0
  102. package/dist/cjs/features/page_view_event/aggregate/index.js +133 -0
  103. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +39 -0
  104. package/dist/cjs/features/page_view_event/constants.js +15 -0
  105. package/dist/cjs/features/page_view_event/index.js +12 -0
  106. package/dist/cjs/features/page_view_event/instrument/index.js +38 -0
  107. package/dist/cjs/features/page_view_timing/aggregate/index.js +265 -0
  108. package/dist/cjs/features/page_view_timing/constants.js +9 -0
  109. package/dist/cjs/features/page_view_timing/first-paint.js +50 -0
  110. package/dist/cjs/features/page_view_timing/index.js +12 -0
  111. package/dist/cjs/features/page_view_timing/instrument/index.js +36 -0
  112. package/dist/cjs/features/page_view_timing/long-tasks.js +75 -0
  113. package/dist/cjs/features/session_trace/aggregate/index.js +375 -0
  114. package/dist/cjs/features/session_trace/constants.js +32 -0
  115. package/dist/cjs/features/session_trace/index.js +12 -0
  116. package/dist/cjs/features/session_trace/instrument/index.js +133 -0
  117. package/dist/cjs/features/spa/aggregate/index.js +684 -0
  118. package/dist/cjs/features/spa/aggregate/interaction-node.js +84 -0
  119. package/dist/cjs/features/spa/aggregate/interaction-node.test.js +16 -0
  120. package/dist/cjs/features/spa/aggregate/interaction.js +98 -0
  121. package/dist/cjs/features/spa/aggregate/serializer.js +147 -0
  122. package/dist/cjs/features/spa/constants.js +53 -0
  123. package/dist/cjs/features/spa/index.js +12 -0
  124. package/dist/cjs/features/spa/instrument/index.js +114 -0
  125. package/dist/cjs/features/utils/aggregate-base.js +13 -0
  126. package/dist/cjs/features/utils/feature-base.js +58 -0
  127. package/dist/cjs/features/utils/handler-cache.js +64 -0
  128. package/dist/cjs/features/utils/instrument-base.js +71 -0
  129. package/dist/cjs/features/utils/lazy-loader.js +44 -0
  130. package/dist/cjs/index.js +81 -58
  131. package/dist/cjs/loaders/agent.js +86 -0
  132. package/dist/cjs/loaders/api/api.js +109 -0
  133. package/dist/cjs/loaders/api/apiAsync.js +94 -0
  134. package/dist/cjs/loaders/browser-agent.js +29 -0
  135. package/dist/cjs/loaders/configure/configure.js +47 -0
  136. package/dist/cjs/loaders/features/enabled-features.js +19 -0
  137. package/dist/cjs/loaders/features/featureDependencies.js +32 -0
  138. package/dist/cjs/loaders/features/features.js +33 -0
  139. package/dist/cjs/loaders/micro-agent.js +93 -0
  140. package/dist/cjs/loaders/worker-agent.js +24 -0
  141. package/dist/esm/cdn/lite.js +12 -0
  142. package/dist/esm/cdn/polyfills/lite.js +7 -0
  143. package/dist/esm/cdn/polyfills/pro.js +7 -0
  144. package/dist/esm/cdn/polyfills/spa.js +7 -0
  145. package/dist/esm/cdn/polyfills.js +17 -0
  146. package/dist/esm/cdn/pro.js +17 -0
  147. package/dist/esm/cdn/spa.js +17 -0
  148. package/dist/esm/cdn/worker.js +14 -0
  149. package/dist/esm/common/aggregate/aggregator.js +161 -0
  150. package/dist/esm/common/browser-version/firefox-version.js +10 -0
  151. package/dist/esm/common/browser-version/ios-version.js +10 -0
  152. package/dist/esm/common/config/config.js +11 -0
  153. package/dist/esm/common/config/state/configurable.js +25 -0
  154. package/dist/esm/common/config/state/info.js +42 -0
  155. package/dist/esm/common/config/state/init.js +78 -0
  156. package/dist/esm/common/config/state/loader-config.js +21 -0
  157. package/dist/esm/common/config/state/originals.js +2 -0
  158. package/dist/esm/common/config/state/runtime.js +41 -0
  159. package/dist/esm/common/constants/environment-variables.js +11 -0
  160. package/dist/esm/common/context/shared-context.js +18 -0
  161. package/dist/esm/common/deny-list/deny-list.js +101 -0
  162. package/dist/esm/common/drain/drain.js +119 -0
  163. package/dist/esm/common/event-emitter/contextual-ee.js +142 -0
  164. package/dist/esm/common/event-emitter/handle.js +16 -0
  165. package/dist/esm/common/event-emitter/register-handler.js +19 -0
  166. package/dist/esm/common/event-listener/event-listener-opts.js +39 -0
  167. package/dist/esm/common/harvest/harvest-scheduler.js +105 -0
  168. package/dist/esm/common/harvest/harvest.js +228 -0
  169. package/dist/esm/common/ids/id.js +23 -0
  170. package/dist/esm/common/ids/unique-id.js +75 -0
  171. package/dist/esm/common/metrics/framework-detection.js +66 -0
  172. package/dist/esm/common/metrics/paint-metrics.js +6 -0
  173. package/dist/esm/common/serialize/bel-serializer.js +80 -0
  174. package/dist/esm/common/timing/nav-timing.js +67 -0
  175. package/dist/esm/common/timing/now.js +9 -0
  176. package/dist/esm/common/unload/eol.js +62 -0
  177. package/dist/esm/common/url/clean-url.js +10 -0
  178. package/dist/esm/common/url/encode.js +71 -0
  179. package/dist/esm/common/url/location.js +8 -0
  180. package/dist/esm/common/url/parse-url.js +60 -0
  181. package/dist/esm/common/url/protocol.js +17 -0
  182. package/dist/esm/common/util/console.js +11 -0
  183. package/dist/esm/common/util/data-size.js +19 -0
  184. package/dist/esm/common/util/feature-flags.js +33 -0
  185. package/dist/esm/common/util/get-or-set.js +33 -0
  186. package/dist/esm/common/util/global-scope.js +44 -0
  187. package/dist/esm/common/util/map-own.js +18 -0
  188. package/dist/esm/common/util/obfuscate.js +67 -0
  189. package/dist/esm/common/util/reduce.js +16 -0
  190. package/dist/esm/common/util/s-hash.js +13 -0
  191. package/dist/esm/common/util/single.js +16 -0
  192. package/dist/esm/common/util/stringify.js +42 -0
  193. package/dist/esm/common/util/submit-data.js +91 -0
  194. package/dist/esm/common/util/traverse.js +35 -0
  195. package/dist/esm/common/util/user-agent.js +48 -0
  196. package/dist/esm/common/window/load.js +12 -0
  197. package/dist/esm/common/window/nreum.js +91 -0
  198. package/dist/esm/common/window/page-visibility.js +23 -0
  199. package/dist/esm/common/window/session-storage.js +36 -0
  200. package/dist/esm/common/window/supports-performance-observer.js +9 -0
  201. package/dist/esm/common/window/top-level-callers.js +17 -0
  202. package/dist/esm/common/wrap/index.js +14 -0
  203. package/dist/esm/common/wrap/wrap-events.js +97 -0
  204. package/dist/esm/common/wrap/wrap-fetch.js +105 -0
  205. package/dist/esm/common/wrap/wrap-function.js +257 -0
  206. package/dist/esm/common/wrap/wrap-history.js +48 -0
  207. package/dist/esm/common/wrap/wrap-jsonp.js +122 -0
  208. package/dist/esm/common/wrap/wrap-mutation.js +54 -0
  209. package/dist/esm/common/wrap/wrap-promise.js +153 -0
  210. package/dist/esm/common/wrap/wrap-raf.js +48 -0
  211. package/dist/esm/common/wrap/wrap-timer.js +63 -0
  212. package/dist/esm/common/wrap/wrap-xhr.js +199 -0
  213. package/dist/esm/features/ajax/aggregate/index.js +218 -0
  214. package/dist/esm/features/ajax/constants.js +2 -0
  215. package/dist/esm/features/ajax/index.js +1 -0
  216. package/dist/esm/features/ajax/instrument/distributed-tracing.js +137 -0
  217. package/dist/esm/features/ajax/instrument/index.js +330 -0
  218. package/dist/esm/features/ajax/instrument/response-size.js +19 -0
  219. package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +12 -0
  220. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +28 -0
  221. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +209 -0
  222. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +255 -0
  223. package/dist/esm/features/jserrors/aggregate/format-stack-trace.js +29 -0
  224. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +37 -0
  225. package/dist/esm/features/jserrors/aggregate/index.js +260 -0
  226. package/dist/esm/features/jserrors/aggregate/string-hash-code.js +17 -0
  227. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +24 -0
  228. package/dist/esm/features/jserrors/constants.js +3 -0
  229. package/dist/esm/features/jserrors/index.js +1 -0
  230. package/dist/esm/features/jserrors/instrument/debug.js +38 -0
  231. package/dist/esm/features/jserrors/instrument/index.js +150 -0
  232. package/dist/esm/features/metrics/aggregate/index.js +129 -0
  233. package/dist/esm/features/metrics/constants.js +6 -0
  234. package/dist/esm/features/metrics/index.js +1 -0
  235. package/dist/esm/features/metrics/instrument/index.js +13 -0
  236. package/dist/esm/features/metrics/instrument/workers-helper.js +116 -0
  237. package/dist/esm/features/page_action/aggregate/index.js +105 -0
  238. package/dist/esm/features/page_action/constants.js +2 -0
  239. package/dist/esm/features/page_action/index.js +1 -0
  240. package/dist/esm/features/page_action/instrument/index.js +14 -0
  241. package/dist/esm/features/page_view_event/aggregate/index.js +124 -0
  242. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +34 -0
  243. package/dist/esm/features/page_view_event/constants.js +5 -0
  244. package/dist/esm/features/page_view_event/index.js +1 -0
  245. package/dist/esm/features/page_view_event/instrument/index.js +29 -0
  246. package/dist/esm/features/page_view_timing/aggregate/index.js +258 -0
  247. package/dist/esm/features/page_view_timing/constants.js +2 -0
  248. package/dist/esm/features/page_view_timing/first-paint.js +43 -0
  249. package/dist/esm/features/page_view_timing/index.js +1 -0
  250. package/dist/esm/features/page_view_timing/instrument/index.js +28 -0
  251. package/dist/esm/features/page_view_timing/long-tasks.js +69 -0
  252. package/dist/esm/features/session_trace/aggregate/index.js +366 -0
  253. package/dist/esm/features/session_trace/constants.js +14 -0
  254. package/dist/esm/features/session_trace/index.js +1 -0
  255. package/dist/esm/features/session_trace/instrument/index.js +123 -0
  256. package/dist/esm/features/spa/aggregate/index.js +674 -0
  257. package/dist/esm/features/spa/aggregate/interaction-node.js +78 -0
  258. package/dist/esm/features/spa/aggregate/interaction-node.test.js +14 -0
  259. package/dist/esm/features/spa/aggregate/interaction.js +92 -0
  260. package/dist/esm/features/spa/aggregate/serializer.js +139 -0
  261. package/dist/esm/features/spa/constants.js +25 -0
  262. package/dist/esm/features/spa/index.js +1 -0
  263. package/dist/esm/features/spa/instrument/index.js +104 -0
  264. package/dist/esm/features/utils/aggregate-base.js +6 -0
  265. package/dist/esm/features/utils/feature-base.js +51 -0
  266. package/dist/esm/features/utils/handler-cache.js +57 -0
  267. package/dist/esm/features/utils/instrument-base.js +69 -0
  268. package/dist/esm/features/utils/lazy-loader.js +37 -0
  269. package/dist/esm/index.js +15 -0
  270. package/dist/esm/loaders/agent.js +77 -0
  271. package/dist/esm/loaders/api/api.js +104 -0
  272. package/dist/esm/loaders/api/apiAsync.js +88 -0
  273. package/dist/esm/loaders/browser-agent.js +23 -0
  274. package/dist/esm/loaders/configure/configure.js +41 -0
  275. package/dist/esm/loaders/features/enabled-features.js +13 -0
  276. package/dist/esm/loaders/features/featureDependencies.js +25 -0
  277. package/dist/esm/loaders/features/features.js +25 -0
  278. package/dist/esm/loaders/micro-agent.js +86 -0
  279. package/dist/esm/loaders/worker-agent.js +18 -0
  280. package/package.json +204 -71
  281. package/types.ts +221 -0
  282. package/dist/bundled/es5/index.js +0 -2
  283. package/dist/bundled/es5/index.js.map +0 -1
  284. package/dist/bundled/es6/index.js +0 -2
  285. package/dist/bundled/es6/index.js.map +0 -1
  286. package/dist/cjs/index.d.ts +0 -19
  287. package/dist/cjs/index.js.map +0 -1
  288. package/dist/cjs/types.d.ts +0 -94
  289. package/dist/cjs/types.js +0 -28
  290. package/dist/cjs/types.js.map +0 -1
  291. package/dist/cjs/utils/api/api.d.ts +0 -10
  292. package/dist/cjs/utils/api/api.js +0 -40
  293. package/dist/cjs/utils/api/api.js.map +0 -1
  294. package/dist/cjs/utils/config/build-configs.d.ts +0 -6
  295. package/dist/cjs/utils/config/build-configs.js +0 -68
  296. package/dist/cjs/utils/config/build-configs.js.map +0 -1
  297. package/dist/cjs/utils/features/features.d.ts +0 -5
  298. package/dist/cjs/utils/features/features.js +0 -14
  299. package/dist/cjs/utils/features/features.js.map +0 -1
  300. package/dist/cjs/utils/features/initialize.d.ts +0 -5
  301. package/dist/cjs/utils/features/initialize.js +0 -51
  302. package/dist/cjs/utils/features/initialize.js.map +0 -1
  303. package/dist/es/index.d.ts +0 -19
  304. package/dist/es/index.js +0 -55
  305. package/dist/es/index.js.map +0 -1
  306. package/dist/es/types.d.ts +0 -94
  307. package/dist/es/types.js +0 -24
  308. package/dist/es/types.js.map +0 -1
  309. package/dist/es/utils/api/api.d.ts +0 -10
  310. package/dist/es/utils/api/api.js +0 -36
  311. package/dist/es/utils/api/api.js.map +0 -1
  312. package/dist/es/utils/config/build-configs.d.ts +0 -6
  313. package/dist/es/utils/config/build-configs.js +0 -64
  314. package/dist/es/utils/config/build-configs.js.map +0 -1
  315. package/dist/es/utils/features/features.d.ts +0 -5
  316. package/dist/es/utils/features/features.js +0 -10
  317. package/dist/es/utils/features/features.js.map +0 -1
  318. package/dist/es/utils/features/initialize.d.ts +0 -5
  319. package/dist/es/utils/features/initialize.js +0 -24
  320. package/dist/es/utils/features/initialize.js.map +0 -1
  321. package/dist/umd/index.d.ts +0 -19
  322. package/dist/umd/index.js +0 -69
  323. package/dist/umd/index.js.map +0 -1
  324. package/dist/umd/types.d.ts +0 -94
  325. package/dist/umd/types.js +0 -38
  326. package/dist/umd/types.js.map +0 -1
  327. package/dist/umd/utils/api/api.d.ts +0 -10
  328. package/dist/umd/utils/api/api.js +0 -50
  329. package/dist/umd/utils/api/api.js.map +0 -1
  330. package/dist/umd/utils/config/build-configs.d.ts +0 -6
  331. package/dist/umd/utils/config/build-configs.js +0 -78
  332. package/dist/umd/utils/config/build-configs.js.map +0 -1
  333. package/dist/umd/utils/features/features.d.ts +0 -5
  334. package/dist/umd/utils/features/features.js +0 -24
  335. package/dist/umd/utils/features/features.js.map +0 -1
  336. package/dist/umd/utils/features/initialize.d.ts +0 -5
  337. package/dist/umd/utils/features/initialize.js +0 -63
  338. package/dist/umd/utils/features/initialize.js.map +0 -1
  339. package/dist/webpack-analysis.html +0 -38
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.InteractionNode = InteractionNode;
7
+ /*
8
+ * Copyright 2020 New Relic Corporation. All rights reserved.
9
+ * SPDX-License-Identifier: Apache-2.0
10
+ */
11
+
12
+ var MAX_NODES = 128;
13
+ var lastId = 0;
14
+ function InteractionNode(interaction, parent, type, timestamp) {
15
+ Object.defineProperty(this, 'interaction', {
16
+ value: interaction,
17
+ writable: true // enumerable: false -- by default, which hides this prop from obj (iterations)
18
+ });
19
+
20
+ this.parent = parent;
21
+ this.id = ++lastId;
22
+ this.type = type;
23
+ this.children = [];
24
+ this.end = null;
25
+ this.jsEnd = this.start = timestamp;
26
+ this.jsTime = 0;
27
+ this.attrs = {};
28
+ this.cancelled = false;
29
+ }
30
+ var InteractionNodePrototype = InteractionNode.prototype;
31
+
32
+ /**
33
+ * @param {string} type
34
+ * @param {number} timestamp
35
+ * @param {string} name
36
+ * @param {bool} dontWait - When true, the interaction will not immediately start waiting
37
+ * for this node to complete. This is used when the creation of
38
+ * the node and its start happen at different times (e.g. XHR).
39
+ */
40
+ InteractionNodePrototype.child = function child(type, timestamp, name, dontWait) {
41
+ var interaction = this.interaction;
42
+ if (interaction.end || interaction.nodes >= MAX_NODES) return null;
43
+ interaction.onNodeAdded(this);
44
+ var node = new InteractionNode(interaction, this, type, timestamp);
45
+ node.attrs.name = name;
46
+ interaction.nodes++;
47
+ if (!dontWait) {
48
+ interaction.remaining++;
49
+ }
50
+ return node;
51
+ };
52
+ InteractionNodePrototype.callback = function addCallbackTime(exclusiveTime, end) {
53
+ var node = this;
54
+ node.jsTime += exclusiveTime;
55
+ if (end > node.jsEnd) {
56
+ node.jsEnd = end;
57
+ node.interaction.lastCb = end;
58
+ }
59
+ };
60
+ InteractionNodePrototype.cancel = function cancel() {
61
+ this.cancelled = true;
62
+ var interaction = this.interaction;
63
+ interaction.remaining--;
64
+ };
65
+ InteractionNodePrototype.finish = function finish(timestamp) {
66
+ var node = this;
67
+ if (node.end) return;
68
+ node.end = timestamp;
69
+
70
+ // Find the next parent node that is not cancelled
71
+ let parent = node.parent;
72
+ while (parent?.cancelled) parent = parent.parent;
73
+
74
+ // Assign the node to the non-cancelled parent node
75
+ if (parent) parent.children.push(node);
76
+ node.parent = null;
77
+
78
+ // Update the interaction remaining counter
79
+ var interaction = this.interaction;
80
+ interaction.remaining--;
81
+ interaction.lastFinish = timestamp;
82
+ // check if interaction has finished, (this is needed for older browsers for unknown reasons)
83
+ interaction.checkFinish();
84
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _faker = require("@faker-js/faker");
4
+ var _interactionNode = require("./interaction-node");
5
+ test('finishing node with cancelled parent should not throw an error', () => {
6
+ const interaction = {
7
+ remaining: 0,
8
+ onNodeAdded: jest.fn(),
9
+ checkFinish: jest.fn()
10
+ };
11
+ const interactionRootNode = new _interactionNode.InteractionNode(interaction, null, 'interaction', _faker.faker.date.past().getUTCSeconds());
12
+ const interactionNode = interactionRootNode.child('test', _faker.faker.date.past().getUTCSeconds(), 'test', false);
13
+ interactionRootNode.cancel();
14
+ interactionNode.finish();
15
+ expect(interactionRootNode.children.length).toEqual(0);
16
+ });
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Interaction = Interaction;
7
+ var _config = require("../../../common/config/config");
8
+ var _mapOwn = require("../../../common/util/map-own");
9
+ var _contextualEe = require("../../../common/event-emitter/contextual-ee");
10
+ var _interactionNode = require("./interaction-node");
11
+ var _now = require("../../../common/timing/now");
12
+ /*
13
+ * Copyright 2020 New Relic Corporation. All rights reserved.
14
+ * SPDX-License-Identifier: Apache-2.0
15
+ */
16
+
17
+ var originalSetTimeout = _config.originals.ST;
18
+ var originalClearTimeout = _config.originals.CT;
19
+ var lastId = {};
20
+ function Interaction(eventName, timestamp, url, routeName, onFinished, agentIdentifier) {
21
+ this.agentIdentifier = agentIdentifier;
22
+ this.ee = _contextualEe.ee.get(agentIdentifier);
23
+ lastId[agentIdentifier] = 0;
24
+ this.id = ++lastId[agentIdentifier];
25
+ this.eventName = eventName;
26
+ this.nodes = 0;
27
+ this.remaining = 0;
28
+ this.finishTimer = null;
29
+ this.checkingFinish = false;
30
+ this.lastCb = this.lastFinish = timestamp;
31
+ this.handlers = [];
32
+ this.onFinished = onFinished;
33
+ this.done = false;
34
+ var root = this.root = new _interactionNode.InteractionNode(this, null, 'interaction', timestamp);
35
+ var attrs = root.attrs;
36
+ attrs.trigger = eventName;
37
+ attrs.initialPageURL = (0, _config.getRuntime)(agentIdentifier).origin;
38
+ attrs.oldRoute = routeName;
39
+ attrs.newURL = attrs.oldURL = url;
40
+ attrs.custom = {};
41
+ attrs.store = {};
42
+ }
43
+ var InteractionPrototype = Interaction.prototype;
44
+ InteractionPrototype.checkFinish = function checkFinish() {
45
+ var interaction = this;
46
+ if (interaction.remaining > 0) {
47
+ interaction._resetFinishCheck();
48
+ return;
49
+ }
50
+ if (interaction.checkingFinish) {
51
+ return;
52
+ }
53
+ if (interaction.root.end !== null) return;
54
+ interaction._resetFinishCheck();
55
+ interaction.checkingFinish = true;
56
+ interaction.finishTimer = originalSetTimeout(() => {
57
+ interaction.checkingFinish = false;
58
+ interaction.finishTimer = originalSetTimeout(() => {
59
+ interaction.finishTimer = null;
60
+ if (interaction.remaining <= 0) interaction.finish();
61
+ }, 1);
62
+ }, 0);
63
+ };
64
+ InteractionPrototype.setNewURL = function setNewURL(url) {
65
+ this.root.attrs.newURL = url;
66
+ };
67
+ InteractionPrototype.setNewRoute = function setNewRoute(route) {
68
+ this.root.attrs.newRoute = route;
69
+ };
70
+ InteractionPrototype.onNodeAdded = function onNodeAdded() {
71
+ this._resetFinishCheck();
72
+ };
73
+ InteractionPrototype._resetFinishCheck = function _resetFinishCheck() {
74
+ if (this.finishTimer) {
75
+ originalClearTimeout(this.finishTimer);
76
+ this.finishTimer = null;
77
+ this.checkingFinish = false;
78
+ }
79
+ };
80
+
81
+ // serialize report and remove nodes from map
82
+ InteractionPrototype.finish = function finishInteraction() {
83
+ var interaction = this;
84
+ var root = interaction.root;
85
+ if (root.end !== null) return;
86
+ var endTimestamp = Math.max(interaction.lastCb, interaction.lastFinish);
87
+ var delta = (0, _now.now)() - endTimestamp;
88
+ var attrs = root.attrs;
89
+ var customAttrs = attrs.custom;
90
+ if (this.onFinished) {
91
+ this.onFinished(this);
92
+ }
93
+ (0, _mapOwn.mapOwn)((0, _config.getInfo)(interaction.agentIdentifier).jsAttributes, function (attr, value) {
94
+ if (!(attr in customAttrs)) customAttrs[attr] = value;
95
+ });
96
+ root.end = endTimestamp;
97
+ interaction.ee.emit('interaction', [this]);
98
+ };
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Serializer = void 0;
7
+ var _cleanUrl = require("../../../common/url/clean-url");
8
+ var _mapOwn = require("../../../common/util/map-own");
9
+ var _belSerializer = require("../../../common/serialize/bel-serializer");
10
+ var _sharedContext = require("../../../common/context/shared-context");
11
+ var _config = require("../../../common/config/config");
12
+ /*
13
+ * Copyright 2020 New Relic Corporation. All rights reserved.
14
+ * SPDX-License-Identifier: Apache-2.0
15
+ */
16
+
17
+ class Serializer extends _sharedContext.SharedContext {
18
+ constructor(parent) {
19
+ super(parent);
20
+
21
+ /**
22
+ * This variable is used to calculate an interactions ending offset when the
23
+ * harvest includes multiple interactions. This variable is set by the first
24
+ * interaction processed and used by subsequent interactions in the same harvest.
25
+ * See https://issues.newrelic.com/browse/NEWRELIC-5498
26
+ * @type {number|undefined}
27
+ */
28
+ this.firstTimestamp = undefined;
29
+ }
30
+ serializeMultiple(interactions, offset, navTiming) {
31
+ const info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
32
+ var addString = (0, _belSerializer.getAddStringContext)(this.sharedContext.agentIdentifier);
33
+ var serialized = 'bel.7';
34
+ interactions.forEach(interaction => {
35
+ serialized += ';' + this.serializeInteraction(interaction.root, offset, navTiming, interaction.routeChange, addString, info);
36
+ });
37
+ this.firstTimestamp = undefined;
38
+ return serialized;
39
+ }
40
+ serializeSingle(root, offset, navTiming, isRouteChange) {
41
+ const info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
42
+ var addString = (0, _belSerializer.getAddStringContext)(this.sharedContext.agentIdentifier);
43
+ var serialized = 'bel.7;' + this.serializeInteraction(root, offset, navTiming, isRouteChange, addString, info);
44
+ this.firstTimestamp = undefined;
45
+ return serialized;
46
+ }
47
+ serializeInteraction(root, offset, navTiming, isRouteChange, addString, info) {
48
+ offset = offset || 0;
49
+ var isInitialPage = root.attrs.trigger === 'initialPageLoad';
50
+ var typeIdsByName = {
51
+ interaction: 1,
52
+ ajax: 2,
53
+ customTracer: 4
54
+ };
55
+
56
+ // Include the hash fragment with all SPA data
57
+ var includeHashFragment = true;
58
+ const addNode = (node, nodeList) => {
59
+ if (node.type === 'customEnd') return nodeList.push([3, (0, _belSerializer.numeric)(node.end - this.firstTimestamp)]);
60
+ var typeName = node.type;
61
+ var typeId = typeIdsByName[typeName];
62
+ var startTimestamp = node.start;
63
+ var childCount = node.children.length;
64
+ var attrCount = 0;
65
+ var apmAttributes = info.atts;
66
+ var hasNavTiming = isInitialPage && navTiming.length && typeId === 1;
67
+ var children = [];
68
+ var attrs = node.attrs;
69
+ var metrics = attrs.metrics;
70
+ var params = attrs.params;
71
+ var queueTime = info.queueTime;
72
+ var appTime = info.applicationTime;
73
+ if (typeof this.firstTimestamp === 'undefined') {
74
+ startTimestamp += offset;
75
+ this.firstTimestamp = startTimestamp;
76
+ } else {
77
+ startTimestamp -= this.firstTimestamp;
78
+ }
79
+ var fields = [(0, _belSerializer.numeric)(startTimestamp), (0, _belSerializer.numeric)(node.end - node.start), (0, _belSerializer.numeric)(node.jsEnd - node.end), (0, _belSerializer.numeric)(node.jsTime)];
80
+ switch (typeId) {
81
+ case 1:
82
+ fields[2] = (0, _belSerializer.numeric)(node.jsEnd - this.firstTimestamp);
83
+ fields.push(addString(attrs.trigger), addString((0, _cleanUrl.cleanURL)(attrs.initialPageURL, includeHashFragment)), addString((0, _cleanUrl.cleanURL)(attrs.oldURL, includeHashFragment)), addString((0, _cleanUrl.cleanURL)(attrs.newURL, includeHashFragment)), addString(attrs.customName), isInitialPage ? '' : isRouteChange ? 1 : 2, (0, _belSerializer.nullable)(isInitialPage && queueTime, _belSerializer.numeric, true) + (0, _belSerializer.nullable)(isInitialPage && appTime, _belSerializer.numeric, true) + (0, _belSerializer.nullable)(attrs.oldRoute, addString, true) + (0, _belSerializer.nullable)(attrs.newRoute, addString, true) + addString(attrs.id), addString(node.id), (0, _belSerializer.nullable)(attrs.firstPaint, _belSerializer.numeric, true) + (0, _belSerializer.nullable)(attrs.firstContentfulPaint, _belSerializer.numeric, false));
84
+ var attrParts = (0, _belSerializer.addCustomAttributes)(attrs.custom, addString);
85
+ children = children.concat(attrParts);
86
+ attrCount = attrParts.length;
87
+ if (apmAttributes) {
88
+ childCount++;
89
+ children.push('a,' + addString(apmAttributes));
90
+ }
91
+ break;
92
+ case 2:
93
+ fields.push(addString(params.method), (0, _belSerializer.numeric)(params.status), addString(params.host), addString(params.pathname), (0, _belSerializer.numeric)(metrics.txSize), (0, _belSerializer.numeric)(metrics.rxSize), attrs.isFetch ? 1 : attrs.isJSONP ? 2 : '', addString(node.id), (0, _belSerializer.nullable)(node.dt && node.dt.spanId, addString, true) + (0, _belSerializer.nullable)(node.dt && node.dt.traceId, addString, true) + (0, _belSerializer.nullable)(node.dt && node.dt.timestamp, _belSerializer.numeric, false));
94
+ break;
95
+ case 4:
96
+ var tracedTime = attrs.tracedTime;
97
+ fields.push(addString(attrs.name), (0, _belSerializer.nullable)(tracedTime, _belSerializer.numeric, true) + addString(node.id));
98
+ break;
99
+ }
100
+ for (var i = 0; i < node.children.length; i++) {
101
+ addNode(node.children[i], children);
102
+ }
103
+ fields.unshift((0, _belSerializer.numeric)(typeId), (0, _belSerializer.numeric)(childCount += attrCount));
104
+ nodeList.push(fields);
105
+ if (childCount) {
106
+ nodeList.push(children.join(';'));
107
+ }
108
+ if (hasNavTiming) {
109
+ // this build up the navTiming node
110
+ // it for each navTiming value (pre aggregated in nav-timing.js):
111
+ // we initialize the seperator to ',' (seperates the nodeType id from the first value)
112
+ // we initialize the navTiming node to 'b' (the nodeType id)
113
+ // if the value is present:
114
+ // we add the seperator followed by the value
115
+ // otherwise
116
+ // we add null seperator ('!') to the navTimingNode
117
+ // we set the seperator to an empty string since we already wrote it above
118
+ // the reason for writing the null seperator instead of setting the seperator
119
+ // is to ensure we still write it if the null is the last navTiming value.
120
+
121
+ var seperator = ',';
122
+ var navTimingNode = 'b';
123
+ var prev = 0;
124
+
125
+ // get all navTiming values except navigationStart
126
+ // (since its the same as interaction.start)
127
+ // and limit to just the first 20 values we know about
128
+ (0, _mapOwn.mapOwn)(navTiming.slice(1, 21), function (i, v) {
129
+ if (v !== void 0) {
130
+ navTimingNode += seperator + (0, _belSerializer.numeric)(v - prev);
131
+ seperator = ',';
132
+ prev = v;
133
+ } else {
134
+ navTimingNode += seperator + '!';
135
+ seperator = '';
136
+ }
137
+ });
138
+ nodeList.push(navTimingNode);
139
+ } else if (typeId === 1) {
140
+ nodeList.push('');
141
+ }
142
+ return nodeList;
143
+ };
144
+ return addNode(root, []).join(';');
145
+ }
146
+ }
147
+ exports.Serializer = Serializer;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.originalSetTimeout = exports.START = exports.SPA_NODE = exports.REMAINING = exports.MAX_TIMER_BUDGET = exports.JS_TIME = exports.JSONP_NODE = exports.JSONP_END = exports.INTERACTION_EVENTS = exports.INTERACTION_API = exports.INTERACTION = exports.FN_START = exports.FN_END = exports.FETCH_START = exports.FETCH_DONE = exports.FETCH_BODY = exports.FETCH = exports.FEATURE_NAME = exports.END = exports.CB_START = exports.CB_END = exports.BODY = void 0;
7
+ var _config = require("../../common/config/config");
8
+ var _globalScope = require("../../common/util/global-scope");
9
+ var _features = require("../../loaders/features/features");
10
+ const FEATURE_NAME = _features.FEATURE_NAMES.spa;
11
+ exports.FEATURE_NAME = FEATURE_NAME;
12
+ const INTERACTION_EVENTS = ['click', 'submit', 'keypress', 'keydown', 'keyup', 'change'];
13
+ exports.INTERACTION_EVENTS = INTERACTION_EVENTS;
14
+ const MAX_TIMER_BUDGET = 999;
15
+ exports.MAX_TIMER_BUDGET = MAX_TIMER_BUDGET;
16
+ const FN_START = 'fn-start';
17
+ exports.FN_START = FN_START;
18
+ const FN_END = 'fn-end';
19
+ exports.FN_END = FN_END;
20
+ const CB_START = 'cb-start';
21
+ exports.CB_START = CB_START;
22
+ const INTERACTION_API = 'api-ixn-';
23
+ exports.INTERACTION_API = INTERACTION_API;
24
+ const REMAINING = 'remaining';
25
+ exports.REMAINING = REMAINING;
26
+ const INTERACTION = 'interaction';
27
+ exports.INTERACTION = INTERACTION;
28
+ const SPA_NODE = 'spaNode';
29
+ exports.SPA_NODE = SPA_NODE;
30
+ const JSONP_NODE = 'jsonpNode';
31
+ exports.JSONP_NODE = JSONP_NODE;
32
+ const FETCH_START = 'fetch-start';
33
+ exports.FETCH_START = FETCH_START;
34
+ const FETCH_DONE = 'fetch-done';
35
+ exports.FETCH_DONE = FETCH_DONE;
36
+ const FETCH_BODY = 'fetch-body-';
37
+ exports.FETCH_BODY = FETCH_BODY;
38
+ const JSONP_END = 'jsonp-end';
39
+ exports.JSONP_END = JSONP_END;
40
+ const originalSetTimeout = _config.originals.ST;
41
+ exports.originalSetTimeout = originalSetTimeout;
42
+ const START = '-start';
43
+ exports.START = START;
44
+ const END = '-end';
45
+ exports.END = END;
46
+ const BODY = '-body';
47
+ exports.BODY = BODY;
48
+ const CB_END = 'cb' + END;
49
+ exports.CB_END = CB_END;
50
+ const JS_TIME = 'jsTime';
51
+ exports.JS_TIME = JS_TIME;
52
+ const FETCH = 'fetch';
53
+ exports.FETCH = FETCH;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Spa", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _index.Instrument;
10
+ }
11
+ });
12
+ var _index = require("./instrument/index");
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Instrument = void 0;
7
+ var _wrap = require("../../../common/wrap");
8
+ var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
9
+ var _instrumentBase = require("../../utils/instrument-base");
10
+ var _config = require("../../../common/config/config");
11
+ var _now = require("../../../common/timing/now");
12
+ var CONSTANTS = _interopRequireWildcard(require("../constants"));
13
+ var _globalScope = require("../../../common/util/global-scope");
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
+ 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
+ /*
17
+ * Copyright 2020 New Relic Corporation. All rights reserved.
18
+ * SPDX-License-Identifier: Apache-2.0
19
+ */
20
+
21
+ const {
22
+ FEATURE_NAME,
23
+ START,
24
+ END,
25
+ BODY,
26
+ CB_END,
27
+ JS_TIME,
28
+ FETCH,
29
+ FN_START,
30
+ CB_START,
31
+ FN_END
32
+ } = CONSTANTS;
33
+ class Instrument extends _instrumentBase.InstrumentBase {
34
+ static featureName = FEATURE_NAME;
35
+ constructor(agentIdentifier, aggregator, auto = true) {
36
+ super(agentIdentifier, aggregator, FEATURE_NAME, auto);
37
+ if (!_globalScope.isBrowserScope) return; // SPA not supported outside web env
38
+
39
+ if (!(0, _config.getRuntime)(agentIdentifier).xhrWrappable) return;
40
+ try {
41
+ this.removeOnAbort = new AbortController();
42
+ } catch (e) {}
43
+ let depth = 0;
44
+ let startHash;
45
+ const tracerEE = this.ee.get('tracer');
46
+ const jsonpEE = (0, _wrap.wrapJsonP)(this.ee);
47
+ const promiseEE = (0, _wrap.wrapPromise)(this.ee);
48
+ const timerEE = (0, _wrap.wrapTimer)(this.ee);
49
+ const xhrEE = (0, _wrap.wrapXhr)(this.ee);
50
+ const eventsEE = this.ee.get('events'); // wrapXhr will call wrapEvents
51
+ const fetchEE = (0, _wrap.wrapFetch)(this.ee);
52
+ const historyEE = (0, _wrap.wrapHistory)(this.ee);
53
+ const mutationEE = (0, _wrap.wrapMutation)(this.ee);
54
+ this.ee.on(FN_START, startTimestamp);
55
+ promiseEE.on(CB_START, startTimestamp);
56
+ jsonpEE.on(CB_START, startTimestamp);
57
+ this.ee.on(FN_END, endTimestamp);
58
+ promiseEE.on(CB_END, endTimestamp);
59
+ jsonpEE.on(CB_END, endTimestamp);
60
+ this.ee.buffer([FN_START, FN_END, 'xhr-resolved'], this.featureName);
61
+ eventsEE.buffer([FN_START], this.featureName);
62
+ timerEE.buffer(['setTimeout' + END, 'clearTimeout' + START, FN_START], this.featureName);
63
+ xhrEE.buffer([FN_START, 'new-xhr', 'send-xhr' + START], this.featureName);
64
+ fetchEE.buffer([FETCH + START, FETCH + '-done', FETCH + BODY + START, FETCH + BODY + END], this.featureName);
65
+ historyEE.buffer(['newURL'], this.featureName);
66
+ mutationEE.buffer([FN_START], this.featureName);
67
+ promiseEE.buffer(['propagate', CB_START, CB_END, 'executor-err', 'resolve' + START], this.featureName);
68
+ tracerEE.buffer([FN_START, 'no-' + FN_START], this.featureName);
69
+ jsonpEE.buffer(['new-jsonp', 'cb-start', 'jsonp-error', 'jsonp-end'], this.featureName);
70
+ timestamp(fetchEE, FETCH + START);
71
+ timestamp(fetchEE, FETCH + '-done');
72
+ timestamp(jsonpEE, 'new-jsonp');
73
+ timestamp(jsonpEE, 'jsonp-end');
74
+ timestamp(jsonpEE, 'cb-start');
75
+ historyEE.on('pushState-end', trackURLChange);
76
+ historyEE.on('replaceState-end', trackURLChange);
77
+ window.addEventListener('hashchange', trackURLChange, (0, _eventListenerOpts.eventListenerOpts)(true, this.removeOnAbort?.signal));
78
+ window.addEventListener('load', trackURLChange, (0, _eventListenerOpts.eventListenerOpts)(true, this.removeOnAbort?.signal));
79
+ window.addEventListener('popstate', function () {
80
+ trackURLChange(0, depth > 1);
81
+ }, (0, _eventListenerOpts.eventListenerOpts)(true, this.removeOnAbort?.signal));
82
+ function trackURLChange(unusedArgs, hashChangedDuringCb) {
83
+ historyEE.emit('newURL', ['' + window.location, hashChangedDuringCb]);
84
+ }
85
+ function startTimestamp() {
86
+ depth++;
87
+ startHash = window.location.hash;
88
+ this[FN_START] = (0, _now.now)();
89
+ }
90
+ function endTimestamp() {
91
+ depth--;
92
+ if (window.location.hash !== startHash) {
93
+ trackURLChange(0, true);
94
+ }
95
+ var time = (0, _now.now)();
96
+ this[JS_TIME] = ~~this[JS_TIME] + time - this[FN_START];
97
+ this[FN_END] = time;
98
+ }
99
+ function timestamp(ee, type) {
100
+ ee.on(type, function () {
101
+ this[type] = (0, _now.now)();
102
+ });
103
+ }
104
+ this.abortHandler = this.#abort;
105
+ this.importAggregator();
106
+ }
107
+
108
+ /** Restoration and resource release tasks to be done if SPA loader is being aborted. Unwind changes to globals and subscription to DOM events. */
109
+ #abort() {
110
+ this.removeOnAbort?.abort();
111
+ this.abortHandler = undefined; // weakly allow this abort op to run only once
112
+ }
113
+ }
114
+ exports.Instrument = Instrument;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AggregateBase = void 0;
7
+ var _featureBase = require("./feature-base");
8
+ class AggregateBase extends _featureBase.FeatureBase {
9
+ constructor(agentIdentifier, aggregator, featureName) {
10
+ super(agentIdentifier, aggregator, featureName);
11
+ }
12
+ }
13
+ exports.AggregateBase = AggregateBase;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FeatureBase = void 0;
7
+ var _config = require("../../common/config/config");
8
+ var _contextualEe = require("../../common/event-emitter/contextual-ee");
9
+ var _configure = require("../../loaders/configure/configure");
10
+ var _nreum = require("../../common/window/nreum");
11
+ class FeatureBase {
12
+ constructor(agentIdentifier, aggregator, featureName) {
13
+ /** @type {string} */
14
+ this.agentIdentifier = agentIdentifier;
15
+ /** @type {Aggregator} */
16
+ this.aggregator = aggregator;
17
+ /** @type {ContextualEE} */
18
+ this.ee = _contextualEe.ee.get(agentIdentifier, (0, _config.getRuntime)(this.agentIdentifier).isolatedBacklog);
19
+ /** @type {string} */
20
+ this.featureName = featureName;
21
+ /**
22
+ * Blocked can be used to prevent aggregation and harvest after inititalization time of the feature.
23
+ * This can currently happen if RUM response setToken flag is 0, which is tied to ingest account entitlement info.
24
+ * @type {boolean}
25
+ */
26
+ this.blocked = false;
27
+ this.checkConfiguration();
28
+ }
29
+
30
+ /**
31
+ * Checks for additional `jsAttributes` items to support backward compatibility with implementations of the agent where
32
+ * loader configurations may appear after the loader code is executed.
33
+ */
34
+ checkConfiguration() {
35
+ // NOTE: This check has to happen at aggregator load time, but could be moved to `AggregateBase`.
36
+ if (!(0, _config.isConfigured)(this.agentIdentifier)) {
37
+ let jsAttributes = {
38
+ ...(0, _nreum.gosCDN)().info?.jsAttributes
39
+ };
40
+ try {
41
+ jsAttributes = {
42
+ ...jsAttributes,
43
+ ...(0, _config.getInfo)(this.agentIdentifier)?.jsAttributes
44
+ };
45
+ } catch (err) {
46
+ // do nothing
47
+ }
48
+ (0, _configure.configure)(this.agentIdentifier, {
49
+ ...(0, _nreum.gosCDN)(),
50
+ info: {
51
+ ...(0, _nreum.gosCDN)().info,
52
+ jsAttributes
53
+ }
54
+ });
55
+ }
56
+ }
57
+ }
58
+ exports.FeatureBase = FeatureBase;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HandlerCache = void 0;
7
+ /**
8
+ * A class to defer callback execution until a decision can be reached
9
+ */
10
+ class HandlerCache {
11
+ /** @private @type {boolean | undefined} */
12
+ #decision = undefined;
13
+ /** @private @type {boolean} */
14
+ #shouldsettle = true;
15
+ /** @private @type {Function[]} */
16
+ #cache = [];
17
+ /** @private @type {Timeout} */
18
+ #settleTimer = setTimeout(() => this.#close(), 5000);
19
+
20
+ /**
21
+ * tell the handlerCache that its ok to immediately execute the callbacks that are triggered by the ee from this moment on
22
+ * and execute all the storage callbacks saved up in the handlerCache
23
+ * @private
24
+ */
25
+ #drain() {
26
+ this.#cache.forEach(h => h());
27
+ this.#cache = [];
28
+ clearTimeout(this.#settleTimer);
29
+ }
30
+
31
+ /**
32
+ * tell the handlerCache not to execute any of the storage callbacks
33
+ * and wipe out all the storage callbacks saved up in the handlerCache
34
+ * @private
35
+ */
36
+ #close() {
37
+ this.#shouldsettle = false;
38
+ this.#cache = [];
39
+ }
40
+
41
+ /**
42
+ * Wrap callback functions with this method to defer their execution until a decision has been reached
43
+ * @param {Function} handler
44
+ * @returns {void}
45
+ */
46
+ settle(handler) {
47
+ if (this.#decision === false || this.#shouldsettle === false) return;else if (this.#decision === undefined) this.#cache.push(handler);else handler();
48
+ }
49
+
50
+ /**
51
+ * Make a decision about what to do with the cache of callbacks.
52
+ * --- if true: tell the handlerCache that its ok to immediately execute the callbacks that are triggered by the ee from this moment on
53
+ * and execute all the storage callbacks saved up in the handlerCache ---
54
+ * --- if false: tell the handlerCache not to execute any of the storage callbacks
55
+ * and wipe out all the storage callbacks saved up in the handlerCache
56
+ * @param {boolean} decision
57
+ */
58
+ decide(decision) {
59
+ this.#decision = decision;
60
+ if (decision === false) this.#close();
61
+ if (decision === true) this.#drain();
62
+ }
63
+ }
64
+ exports.HandlerCache = HandlerCache;