@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,48 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * @file Wraps `pushState` and `replaceState` methods of `window.history` object for instrumentation.
7
+ * This module is used by: session_trace, spa.
8
+ */
9
+ import { ee as globalEE } from '../event-emitter/contextual-ee';
10
+ import { createWrapperWithEmitter as wfn, unwrapFunction } from './wrap-function';
11
+ import { isBrowserScope } from '../util/global-scope';
12
+ const wrapped = {};
13
+ const HISTORY_FNS = ['pushState', 'replaceState'];
14
+
15
+ /**
16
+ * Wraps the `pushState` and `replaceState` methods of `window.history` and returns a corresponding event emitter
17
+ * scoped to the history object.
18
+ * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
19
+ * @returns {Object} Scoped event emitter with a debug ID of `history`.
20
+ */
21
+ export function wrapHistory(sharedEE) {
22
+ const ee = scopedEE(sharedEE);
23
+ if (!isBrowserScope || wrapped[ee.debugId]++)
24
+ // Notice if our wrapping never ran yet, the falsey NaN will not early return; but if it has,
25
+ {
26
+ return ee;
27
+ } // then we increment the count to track # of feats using this at runtime. (History API is only avail in browser DOM context.)
28
+ wrapped[ee.debugId] = 1;
29
+ var wrapFn = wfn(ee);
30
+ /*
31
+ * For objects that will be instantiated more than once, we wrap the object's prototype methods. The history object
32
+ * is instantiated only once, so we can wrap its methods directly--and we must wrap the history methods directly as
33
+ * long as [Chromium issue 783382](https://bugs.chromium.org/p/chromium/issues/detail?id=783382) remains unresolved.
34
+ */
35
+ wrapFn.inPlace(window.history, HISTORY_FNS, '-');
36
+ return ee;
37
+ }
38
+
39
+ /**
40
+ * Returns an event emitter scoped specifically for the `history` context. This scoping is a remnant from when all the
41
+ * features shared the same group in the event, to isolate events between features. It will likely be revisited.
42
+ * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
43
+ * Uses `ee` on the global scope if undefined).
44
+ * @returns {Object} Scoped event emitter with a debug ID of 'history'.
45
+ */
46
+ export function scopedEE(sharedEE) {
47
+ return (sharedEE || globalEE).get('history');
48
+ }
@@ -0,0 +1,122 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * @file Wraps DOM insertion methods which in turn wrap JSONP functions that show up in the DOM.
7
+ * This module is used by: spa.
8
+ */
9
+
10
+ import { eventListenerOpts } from '../event-listener/event-listener-opts';
11
+ import { ee as baseEE } from '../event-emitter/contextual-ee';
12
+ import { createWrapperWithEmitter as wfn, unwrapFunction } from './wrap-function';
13
+ import { isBrowserScope } from '../util/global-scope';
14
+ const wrapped = {};
15
+ const domInsertMethods = ['appendChild', 'insertBefore', 'replaceChild'];
16
+
17
+ /**
18
+ * Wraps DOM insertion methods to identify script elements containing JSONP callback functions and instruments those
19
+ * functions with custom events in the context of a new event emitter scoped only to JSONP.
20
+ * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
21
+ * @returns {Object} Scoped event emitter with a debug ID of `jsonp`.
22
+ */
23
+ export function wrapJsonP(sharedEE) {
24
+ const ee = scopedEE(sharedEE);
25
+ if (!isBrowserScope || wrapped[ee.debugId])
26
+ // JSONP deals with DOM tags so browser window env is req'd
27
+ {
28
+ return ee;
29
+ }
30
+ wrapped[ee.debugId] = true;
31
+ var wrapFn = wfn(ee);
32
+ var CALLBACK_REGEX = /[?&](?:callback|cb)=([^&#]+)/;
33
+ var PARENT_REGEX = /(.*)\.([^.]+)/;
34
+ var VALUE_REGEX = /^(\w+)(\.|$)(.*)$/;
35
+
36
+ // JSONP works by dynamically inserting <script> elements - wrap DOM methods for
37
+ // inserting elements to detect insertion of JSONP-specific elements.
38
+ wrapFn.inPlace(Node.prototype, domInsertMethods, 'dom-');
39
+ ee.on('dom-start', function (args) {
40
+ wrapElement(args[0]);
41
+ });
42
+
43
+ // subscribe to events on the JSONP <script> element and wrap the JSONP callback
44
+ // in order to track start and end of the interaction node
45
+ function wrapElement(el) {
46
+ var isScript = el && typeof el.nodeName === 'string' && el.nodeName.toLowerCase() === 'script';
47
+ if (!isScript) return;
48
+ var isValidElement = typeof el.addEventListener === 'function';
49
+ if (!isValidElement) return;
50
+ var callbackName = extractCallbackName(el.src);
51
+ if (!callbackName) return;
52
+ var callback = discoverParent(callbackName);
53
+ var validCallback = typeof callback.parent[callback.key] === 'function';
54
+ if (!validCallback) return;
55
+
56
+ // At this point we know that the element is a valid JSONP script element.
57
+ // The following events are emitted during the lifetime of a JSONP call:
58
+ // * immediately emit `new-jsonp` to notify start of the JSONP work
59
+ // * the wrapped callback will emit `cb-start` and `cb-end` during the execution
60
+ // of the callback, here we can inspect the response
61
+ // * when the element emits the `load` event (script loaded and executed),
62
+ // emit `jsonp-end` to notify end of the JSONP work
63
+ // * if the element emits the `error` event, in response emit `jsonp-error`
64
+ // (and `jsonp-end`). Note that the callback in this case will likely not get
65
+ // called.
66
+
67
+ var context = {};
68
+ wrapFn.inPlace(callback.parent, [callback.key], 'cb-', context);
69
+ el.addEventListener('load', onLoad, eventListenerOpts(false));
70
+ el.addEventListener('error', onError, eventListenerOpts(false));
71
+ ee.emit('new-jsonp', [el.src], context);
72
+ function onLoad() {
73
+ ee.emit('jsonp-end', [], context);
74
+ el.removeEventListener('load', onLoad, eventListenerOpts(false));
75
+ el.removeEventListener('error', onError, eventListenerOpts(false));
76
+ }
77
+ function onError() {
78
+ ee.emit('jsonp-error', [], context);
79
+ ee.emit('jsonp-end', [], context);
80
+ el.removeEventListener('load', onLoad, eventListenerOpts(false));
81
+ el.removeEventListener('error', onError, eventListenerOpts(false));
82
+ }
83
+ }
84
+ function extractCallbackName(src) {
85
+ var matches = src.match(CALLBACK_REGEX);
86
+ return matches ? matches[1] : null;
87
+ }
88
+ function discoverValue(longKey, obj) {
89
+ var matches = longKey.match(VALUE_REGEX);
90
+ var key = matches[1];
91
+ var remaining = matches[3];
92
+ if (!remaining) {
93
+ return obj[key];
94
+ }
95
+ return discoverValue(remaining, obj[key]);
96
+ }
97
+ function discoverParent(key) {
98
+ var matches = key.match(PARENT_REGEX);
99
+ if (matches && matches.length >= 3) {
100
+ return {
101
+ key: matches[2],
102
+ parent: discoverValue(matches[1], window)
103
+ };
104
+ }
105
+ return {
106
+ key: key,
107
+ parent: window
108
+ };
109
+ }
110
+ return ee;
111
+ }
112
+
113
+ /**
114
+ * Returns an event emitter scoped specifically for the `jsonp` context. This scoping is a remnant from when all the
115
+ * features shared the same group in the event, to isolate events between features. It will likely be revisited.
116
+ * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
117
+ * Uses `ee` on the global scope if undefined).
118
+ * @returns {Object} Scoped event emitter with a debug ID of 'jsonp'.
119
+ */
120
+ export function scopedEE(sharedEE) {
121
+ return (sharedEE || baseEE).get('jsonp');
122
+ }
@@ -0,0 +1,54 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * @file Wraps the window's DOM mutation observer for instrumentation.
7
+ * This module is used by: spa.
8
+ */
9
+
10
+ import { ee as baseEE } from '../event-emitter/contextual-ee';
11
+ import { createWrapperWithEmitter as wfn } from './wrap-function';
12
+ import { originals } from '../config/config';
13
+ import { isBrowserScope } from '../util/global-scope';
14
+ const wrapped = {};
15
+
16
+ /**
17
+ * In web environments only, wraps the `window.MutationObserver` function to emit events on start, end, and error, in
18
+ * the context of a new event emitter scoped only to mutations.
19
+ * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
20
+ * @returns {Object} Scoped event emitter with a debug ID of `mutation`.
21
+ */
22
+ export function wrapMutation(sharedEE) {
23
+ const ee = scopedEE(sharedEE);
24
+ if (!isBrowserScope || wrapped[ee.debugId])
25
+ // relates to the DOM tree (web env only)
26
+ {
27
+ return ee;
28
+ }
29
+ wrapped[ee.debugId] = true;
30
+ var wrapFn = wfn(ee);
31
+ var OriginalObserver = originals.MO;
32
+ if (OriginalObserver) {
33
+ window.MutationObserver = function WrappedMutationObserver(cb) {
34
+ if (this instanceof OriginalObserver) {
35
+ return new OriginalObserver(wrapFn(cb, 'fn-'));
36
+ } else {
37
+ return OriginalObserver.apply(this, arguments);
38
+ }
39
+ };
40
+ MutationObserver.prototype = OriginalObserver.prototype;
41
+ }
42
+ return ee;
43
+ }
44
+
45
+ /**
46
+ * Returns an event emitter scoped specifically for the `mutation` context. This scoping is a remnant from when all the
47
+ * features shared the same group in the event, to isolate events between features. It will likely be revisited.
48
+ * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
49
+ * Uses `ee` on the global scope if undefined).
50
+ * @returns {Object} Scoped event emitter with a debug ID of 'mutation'.
51
+ */
52
+ export function scopedEE(sharedEE) {
53
+ return (sharedEE || baseEE).get('mutation');
54
+ }
@@ -0,0 +1,153 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * @file Wraps the native Promise object for instrumentation.
7
+ * This module is used by: spa.
8
+ */
9
+
10
+ import { createWrapperWithEmitter as wrapFn, flag } from './wrap-function';
11
+ import { ee as baseEE, getOrSetContext } from '../event-emitter/contextual-ee';
12
+ import { originals } from '../config/config';
13
+ import { globalScope } from '../util/global-scope';
14
+ const wrapped = {};
15
+
16
+ /**
17
+ * Wraps the native Promise object so that it will emit events for start, end and error in the context of a new event
18
+ * emitter scoped only to promise methods. Also instruments various methods, such as `all`, `race`, `resolve`,
19
+ * `reject`, `then`, and `catch`.
20
+ * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
21
+ * @returns {Object} Scoped event emitter with a debug ID of `promise`.
22
+ */
23
+ export function wrapPromise(sharedEE) {
24
+ const promiseEE = scopedEE(sharedEE);
25
+ if (wrapped[promiseEE.debugId]) {
26
+ return promiseEE;
27
+ }
28
+ wrapped[promiseEE.debugId] = true;
29
+ var getContext = getOrSetContext;
30
+ var promiseWrapper = wrapFn(promiseEE);
31
+ var prevPromiseObj = originals.PR;
32
+ if (prevPromiseObj) {
33
+ // ensure there's a Promise API (native or otherwise) to even wrap
34
+ wrap();
35
+ }
36
+ function wrap() {
37
+ globalScope.Promise = WrappedPromise;
38
+
39
+ // Renamed from "WrappedPromise" back to "Promise" & toString() so that we appear "native" to TP libraries...
40
+ Object.defineProperty(WrappedPromise, 'name', {
41
+ value: 'Promise'
42
+ });
43
+ WrappedPromise.toString = function () {
44
+ return prevPromiseObj.toString();
45
+ };
46
+
47
+ /**
48
+ * This constitutes the global used when calling "Promise.staticMethod" or chaining off a "new Promise()" object.
49
+ * @param {Function} executor - to be executed by the original Promise constructor
50
+ * @returns A new WrappedPromise object prototyped off the original.
51
+ */
52
+ function WrappedPromise(executor) {
53
+ var ctx = promiseEE.context();
54
+ var wrappedExecutor = promiseWrapper(executor, 'executor-', ctx, null, false);
55
+ const newCustomPromiseInst = Reflect.construct(prevPromiseObj, [wrappedExecutor], WrappedPromise); // new Promises will use WrappedPromise.prototype as theirs prototype
56
+
57
+ promiseEE.context(newCustomPromiseInst).getCtx = function () {
58
+ return ctx;
59
+ };
60
+ return newCustomPromiseInst;
61
+ }
62
+
63
+ // Make WrappedPromise inherit statics from the orig Promise.
64
+ Object.setPrototypeOf(WrappedPromise, prevPromiseObj);
65
+ ['all', 'race'].forEach(function (method) {
66
+ const prevStaticFn = prevPromiseObj[method];
67
+ WrappedPromise[method] = function (subPromises) {
68
+ // use our own wrapped version of "Promise.all" and ".race" static fns
69
+ let finalized = false;
70
+ subPromises?.forEach(sub => {
71
+ // eslint-disable-next-line
72
+ this.resolve(sub).then(setNrId(method === 'all'), setNrId(false));
73
+ });
74
+ const origFnCallWithThis = prevStaticFn.apply(this, arguments);
75
+ return origFnCallWithThis;
76
+ function setNrId(overwrite) {
77
+ return function () {
78
+ promiseEE.emit('propagate', [null, !finalized], origFnCallWithThis, false, false);
79
+ finalized = finalized || !overwrite;
80
+ };
81
+ }
82
+ };
83
+ });
84
+ ['resolve', 'reject'].forEach(function (method) {
85
+ const prevStaticFn = prevPromiseObj[method];
86
+ WrappedPromise[method] = function (val) {
87
+ // and the same for ".resolve" and ".reject"
88
+ const origFnCallWithThis = prevStaticFn.apply(this, arguments);
89
+ if (val !== origFnCallWithThis) {
90
+ promiseEE.emit('propagate', [val, true], origFnCallWithThis, false, false);
91
+ }
92
+ return origFnCallWithThis;
93
+ };
94
+ });
95
+
96
+ /*
97
+ * Ideally, we create a new WrappedPromise.prototype chained off the original Promise's so that we don't alter it.
98
+ * However, there's no way to make the (native) promise returned from async functions use our WrappedPromise,
99
+ * so we have to modify the original prototype. This ensures that promises returned from async functions execute
100
+ * the same instance methods as promises created with "new Promise()", and also that instanceof async() is
101
+ * the global Promise (see GH issue #409). This also affects the promise returned from fetch().
102
+ */
103
+ WrappedPromise.prototype = prevPromiseObj.prototype;
104
+
105
+ // Note that this wrapping affects the same originals.PR (prototype) object.
106
+ const prevPromiseOrigThen = prevPromiseObj.prototype.then;
107
+ prevPromiseObj.prototype.then = function wrappedThen(...args) {
108
+ var originalThis = this;
109
+ var ctx = getContext(originalThis);
110
+ ctx.promise = originalThis;
111
+ args[0] = promiseWrapper(args[0], 'cb-', ctx, null, false);
112
+ args[1] = promiseWrapper(args[1], 'cb-', ctx, null, false);
113
+ const origFnCallWithThis = prevPromiseOrigThen.apply(this, args);
114
+ ctx.nextPromise = origFnCallWithThis;
115
+ promiseEE.emit('propagate', [originalThis, true], origFnCallWithThis, false, false);
116
+ return origFnCallWithThis;
117
+ };
118
+ prevPromiseObj.prototype.then[flag] = prevPromiseOrigThen;
119
+ promiseEE.on('executor-start', function (args) {
120
+ args[0] = promiseWrapper(args[0], 'resolve-', this, null, false);
121
+ args[1] = promiseWrapper(args[1], 'resolve-', this, null, false);
122
+ });
123
+ promiseEE.on('executor-err', function (args, originalThis, err) {
124
+ args[1](err);
125
+ });
126
+ promiseEE.on('cb-end', function (args, originalThis, result) {
127
+ promiseEE.emit('propagate', [result, true], this.nextPromise, false, false);
128
+ });
129
+ promiseEE.on('propagate', function (val, overwrite, trigger) {
130
+ if (!this.getCtx || overwrite) {
131
+ this.getCtx = function () {
132
+ // eslint-disable-next-line
133
+ if (val instanceof Promise) {
134
+ var store = promiseEE.context(val);
135
+ }
136
+ return store && store.getCtx ? store.getCtx() : this;
137
+ };
138
+ }
139
+ });
140
+ }
141
+ return promiseEE;
142
+ }
143
+
144
+ /**
145
+ * Returns an event emitter scoped specifically for the `promise` context. This scoping is a remnant from when all the
146
+ * features shared the same group in the event, to isolate events between features. It will likely be revisited.
147
+ * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
148
+ * Uses `ee` on the global scope if undefined).
149
+ * @returns {Object} Scoped event emitter with a debug ID of 'promise'.
150
+ */
151
+ export function scopedEE(sharedEE) {
152
+ return (sharedEE || baseEE).get('promise');
153
+ }
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * @file Wraps `window.requestAnimationFrame` for instrumentation.
7
+ * This module is used by: jserror, session_trace.
8
+ */
9
+
10
+ import { ee as baseEE } from '../event-emitter/contextual-ee';
11
+ import { createWrapperWithEmitter as wfn, unwrapFunction } from './wrap-function';
12
+ import { isBrowserScope } from '../util/global-scope';
13
+ const wrapped = {};
14
+ const RAF_NAME = 'requestAnimationFrame';
15
+
16
+ /**
17
+ * Wraps the `window.requestAnimationFrame` method to emit events on start, end, and error, in the context of a new
18
+ * event emitter ("raf") scoped only to requestAnimationFrame. Also wraps the callback passed to the method.
19
+ * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
20
+ * @returns {Object} Scoped event emitter with a debug ID of `raf`.
21
+ */
22
+ export function wrapRaf(sharedEE) {
23
+ const ee = scopedEE(sharedEE);
24
+ if (!isBrowserScope || wrapped[ee.debugId]++)
25
+ // Notice if our wrapping never ran yet, the falsey NaN will not early return; but if it has,
26
+ {
27
+ return ee;
28
+ } // then we increment the count to track # of feats using this at runtime. (RAF is only avail in browser DOM context.)
29
+ wrapped[ee.debugId] = 1;
30
+ var wrapFn = wfn(ee);
31
+ wrapFn.inPlace(window, [RAF_NAME], 'raf-');
32
+ ee.on('raf-start', function (args) {
33
+ // Wrap the callback handed to requestAnimationFrame
34
+ args[0] = wrapFn(args[0], 'fn-');
35
+ });
36
+ return ee;
37
+ }
38
+
39
+ /**
40
+ * Returns an event emitter scoped specifically for the `raf` context. This scoping is a remnant from when all the
41
+ * features shared the same group in the event, to isolate events between features. It will likely be revisited.
42
+ * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
43
+ * Uses `ee` on the global scope if undefined).
44
+ * @returns {Object} Scoped event emitter with a debug ID of 'raf'.
45
+ */
46
+ export function scopedEE(sharedEE) {
47
+ return (sharedEE || baseEE).get('raf');
48
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * @file Wraps native timeout and interval methods for instrumentation.
7
+ * This module is used by: jserrors, session_trace, spa.
8
+ */
9
+
10
+ import { ee as baseEE } from '../event-emitter/contextual-ee';
11
+ import { createWrapperWithEmitter as wfn, unwrapFunction } from './wrap-function';
12
+ import { globalScope } from '../util/global-scope';
13
+ const wrapped = {};
14
+ const SET_TIMEOUT = 'setTimeout';
15
+ const SET_INTERVAL = 'setInterval';
16
+ const CLEAR_TIMEOUT = 'clearTimeout';
17
+ const START = '-start';
18
+ const DASH = '-';
19
+ const TIMER_FNS = [SET_TIMEOUT, 'setImmediate', SET_INTERVAL, CLEAR_TIMEOUT, 'clearImmediate'];
20
+
21
+ /**
22
+ * Wraps the global `setTimeout`, `setImmediate`, `setInterval`, `clearTimeout`, and `clearImmediate` functions to emit
23
+ * events on start, end, and error, in the context of a new event emitter scoped only to timer functions. Also wraps
24
+ * the callbacks of `setTimeout` and `setInterval`.
25
+ * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
26
+ * @returns {Object} Scoped event emitter with a debug ID of `timer`.
27
+ */
28
+ //eslint-disable-next-line
29
+ export function wrapTimer(sharedEE) {
30
+ const ee = scopedEE(sharedEE);
31
+ if (wrapped[ee.debugId]++)
32
+ // Notice if our wrapping never ran yet, the falsey NaN will not early return; but if it has,
33
+ {
34
+ return ee;
35
+ } // then we increment the count to track # of feats using this at runtime.
36
+ wrapped[ee.debugId] = 1;
37
+ var wrapFn = wfn(ee);
38
+ wrapFn.inPlace(globalScope, TIMER_FNS.slice(0, 2), SET_TIMEOUT + DASH);
39
+ wrapFn.inPlace(globalScope, TIMER_FNS.slice(2, 3), SET_INTERVAL + DASH);
40
+ wrapFn.inPlace(globalScope, TIMER_FNS.slice(3), CLEAR_TIMEOUT + DASH);
41
+ ee.on(SET_INTERVAL + START, interval);
42
+ ee.on(SET_TIMEOUT + START, timer);
43
+ function interval(args, obj, type) {
44
+ args[0] = wrapFn(args[0], 'fn-', null, type);
45
+ }
46
+ function timer(args, obj, type) {
47
+ this.method = type;
48
+ this.timerDuration = isNaN(args[1]) ? 0 : +args[1];
49
+ args[0] = wrapFn(args[0], 'fn-', this, type);
50
+ }
51
+ return ee;
52
+ }
53
+
54
+ /**
55
+ * Returns an event emitter scoped specifically for the `timer` context. This scoping is a remnant from when all the
56
+ * features shared the same group in the event, to isolate events between features. It will likely be revisited.
57
+ * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
58
+ * Uses `ee` on the global scope if undefined).
59
+ * @returns {Object} Scoped event emitter with a debug ID of 'timer'.
60
+ */
61
+ export function scopedEE(sharedEE) {
62
+ return (sharedEE || baseEE).get('timer');
63
+ }