@newrelic/browser-agent 0.1.229 → 0.1.230

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 (509) hide show
  1. package/README.md +40 -1
  2. package/dist/cjs/common/config/state/configurable.js +2 -1
  3. package/dist/cjs/common/config/state/runtime.js +1 -0
  4. package/dist/cjs/common/constants/environment-variables.js +1 -1
  5. package/dist/cjs/common/context/shared-context.js +2 -1
  6. package/dist/cjs/common/drain/drain.js +9 -3
  7. package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
  8. package/dist/cjs/common/harvest/harvest-scheduler.js +2 -1
  9. package/dist/cjs/common/harvest/harvest.js +13 -2
  10. package/dist/cjs/common/util/console.js +1 -1
  11. package/dist/cjs/common/util/map-own.js +21 -14
  12. package/dist/cjs/common/util/map-own.test.js +49 -0
  13. package/dist/cjs/common/util/submit-data.js +11 -3
  14. package/dist/cjs/common/window/page-visibility.js +2 -1
  15. package/dist/cjs/common/window/session-storage.js +56 -11
  16. package/dist/cjs/common/wrap/index.js +11 -4
  17. package/dist/cjs/common/wrap/wrap-console.js +54 -0
  18. package/dist/cjs/common/wrap/wrap-events.js +4 -1
  19. package/dist/cjs/common/wrap/wrap-fetch.js +0 -2
  20. package/dist/cjs/common/wrap/wrap-function.js +4 -18
  21. package/dist/cjs/common/wrap/wrap-promise.js +4 -1
  22. package/dist/cjs/features/ajax/instrument/index.js +2 -1
  23. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
  24. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +1 -2
  25. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +5 -4
  26. package/dist/cjs/features/jserrors/aggregate/index.js +32 -11
  27. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +5 -4
  28. package/dist/cjs/features/jserrors/instrument/index.js +7 -10
  29. package/dist/cjs/features/metrics/aggregate/index.js +11 -0
  30. package/dist/cjs/features/metrics/instrument/index.js +27 -1
  31. package/dist/cjs/features/metrics/instrument/workers-helper.js +4 -1
  32. package/dist/cjs/features/page_action/aggregate/index.js +11 -3
  33. package/dist/cjs/features/page_action/instrument/index.js +2 -1
  34. package/dist/cjs/features/page_view_event/aggregate/index.js +8 -4
  35. package/dist/cjs/features/page_view_event/instrument/index.js +2 -1
  36. package/dist/cjs/features/page_view_timing/aggregate/index.js +54 -35
  37. package/dist/cjs/features/page_view_timing/instrument/index.js +2 -1
  38. package/dist/cjs/features/session_trace/aggregate/index.js +53 -13
  39. package/dist/cjs/features/session_trace/instrument/index.js +2 -1
  40. package/dist/cjs/features/spa/instrument/index.js +2 -1
  41. package/dist/cjs/features/utils/instrument-base.js +2 -1
  42. package/dist/cjs/index.js +9 -9
  43. package/dist/cjs/loaders/agent.js +2 -1
  44. package/dist/cjs/loaders/api/api.js +86 -21
  45. package/dist/cjs/loaders/api/apiAsync.js +3 -3
  46. package/dist/cjs/loaders/configure/configure.js +13 -7
  47. package/dist/cjs/loaders/micro-agent.js +18 -13
  48. package/dist/esm/common/config/state/configurable.js +2 -1
  49. package/dist/esm/common/config/state/runtime.js +1 -0
  50. package/dist/esm/common/constants/environment-variables.js +1 -1
  51. package/dist/esm/common/context/shared-context.js +2 -1
  52. package/dist/esm/common/drain/drain.js +9 -3
  53. package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
  54. package/dist/esm/common/harvest/harvest-scheduler.js +2 -1
  55. package/dist/esm/common/harvest/harvest.js +13 -2
  56. package/dist/esm/common/util/console.js +1 -1
  57. package/dist/esm/common/util/map-own.js +19 -13
  58. package/dist/esm/common/util/map-own.test.js +47 -0
  59. package/dist/esm/common/util/submit-data.js +11 -3
  60. package/dist/esm/common/window/page-visibility.js +2 -1
  61. package/dist/esm/common/window/session-storage.js +54 -13
  62. package/dist/esm/common/wrap/index.js +5 -4
  63. package/dist/esm/common/wrap/wrap-console.js +46 -0
  64. package/dist/esm/common/wrap/wrap-events.js +5 -2
  65. package/dist/esm/common/wrap/wrap-fetch.js +1 -3
  66. package/dist/esm/common/wrap/wrap-function.js +4 -17
  67. package/dist/esm/common/wrap/wrap-history.js +1 -1
  68. package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
  69. package/dist/esm/common/wrap/wrap-promise.js +4 -1
  70. package/dist/esm/common/wrap/wrap-raf.js +1 -1
  71. package/dist/esm/common/wrap/wrap-timer.js +1 -1
  72. package/dist/esm/common/wrap/wrap-xhr.js +2 -2
  73. package/dist/esm/features/ajax/instrument/index.js +2 -1
  74. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
  75. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +1 -2
  76. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +5 -4
  77. package/dist/esm/features/jserrors/aggregate/index.js +32 -11
  78. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +5 -4
  79. package/dist/esm/features/jserrors/instrument/index.js +7 -10
  80. package/dist/esm/features/metrics/aggregate/index.js +11 -0
  81. package/dist/esm/features/metrics/instrument/index.js +27 -1
  82. package/dist/esm/features/metrics/instrument/workers-helper.js +4 -1
  83. package/dist/esm/features/page_action/aggregate/index.js +11 -3
  84. package/dist/esm/features/page_action/instrument/index.js +2 -1
  85. package/dist/esm/features/page_view_event/aggregate/index.js +8 -4
  86. package/dist/esm/features/page_view_event/instrument/index.js +2 -1
  87. package/dist/esm/features/page_view_timing/aggregate/index.js +54 -35
  88. package/dist/esm/features/page_view_timing/instrument/index.js +2 -1
  89. package/dist/esm/features/session_trace/aggregate/index.js +53 -13
  90. package/dist/esm/features/session_trace/instrument/index.js +2 -1
  91. package/dist/esm/features/spa/instrument/index.js +2 -1
  92. package/dist/esm/features/utils/instrument-base.js +2 -1
  93. package/dist/esm/index.js +4 -4
  94. package/dist/esm/loaders/agent.js +2 -1
  95. package/dist/esm/loaders/api/api.js +85 -21
  96. package/dist/esm/loaders/api/apiAsync.js +3 -3
  97. package/dist/esm/loaders/configure/configure.js +14 -8
  98. package/dist/esm/loaders/micro-agent.js +18 -13
  99. package/dist/types/cdn/lite.d.ts +2 -0
  100. package/dist/types/cdn/lite.d.ts.map +1 -0
  101. package/dist/types/cdn/polyfills/lite.d.ts +2 -0
  102. package/dist/types/cdn/polyfills/lite.d.ts.map +1 -0
  103. package/dist/types/cdn/polyfills/pro.d.ts +2 -0
  104. package/dist/types/cdn/polyfills/pro.d.ts.map +1 -0
  105. package/dist/types/cdn/polyfills/spa.d.ts +2 -0
  106. package/dist/types/cdn/polyfills/spa.d.ts.map +1 -0
  107. package/dist/types/cdn/polyfills.d.ts +2 -0
  108. package/dist/types/cdn/polyfills.d.ts.map +1 -0
  109. package/dist/types/cdn/pro.d.ts +2 -0
  110. package/dist/types/cdn/pro.d.ts.map +1 -0
  111. package/dist/types/cdn/spa.d.ts +2 -0
  112. package/dist/types/cdn/spa.d.ts.map +1 -0
  113. package/dist/types/cdn/worker.d.ts +2 -0
  114. package/dist/types/cdn/worker.d.ts.map +1 -0
  115. package/dist/types/common/aggregate/aggregator.d.ts +11 -0
  116. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -0
  117. package/dist/types/common/browser-version/firefox-version.d.ts +2 -0
  118. package/dist/types/common/browser-version/firefox-version.d.ts.map +1 -0
  119. package/dist/types/common/browser-version/ios-version.d.ts +3 -0
  120. package/dist/types/common/browser-version/ios-version.d.ts.map +1 -0
  121. package/dist/types/common/config/config.d.ts +13 -0
  122. package/dist/types/common/config/config.d.ts.map +1 -0
  123. package/dist/types/common/config/state/configurable.d.ts +4 -0
  124. package/dist/types/common/config/state/configurable.d.ts.map +1 -0
  125. package/dist/types/common/config/state/info.d.ts +4 -0
  126. package/dist/types/common/config/state/info.d.ts.map +1 -0
  127. package/dist/types/common/config/state/init.d.ts +4 -0
  128. package/dist/types/common/config/state/init.d.ts.map +1 -0
  129. package/dist/types/common/config/state/loader-config.d.ts +3 -0
  130. package/dist/types/common/config/state/loader-config.d.ts.map +1 -0
  131. package/dist/types/common/config/state/originals.d.ts +2 -0
  132. package/dist/types/common/config/state/originals.d.ts.map +1 -0
  133. package/dist/types/common/config/state/runtime.d.ts +3 -0
  134. package/dist/types/common/config/state/runtime.d.ts.map +1 -0
  135. package/dist/types/common/constants/environment-variables.d.ts +4 -0
  136. package/dist/types/common/constants/environment-variables.d.ts.map +1 -0
  137. package/dist/types/common/context/shared-context.d.ts +5 -0
  138. package/dist/types/common/context/shared-context.d.ts.map +1 -0
  139. package/dist/types/common/deny-list/deny-list.d.ts +12 -0
  140. package/dist/types/common/deny-list/deny-list.d.ts.map +1 -0
  141. package/dist/types/common/drain/drain.d.ts +17 -0
  142. package/dist/types/common/drain/drain.d.ts.map +1 -0
  143. package/dist/types/common/event-emitter/contextual-ee.d.ts +4 -0
  144. package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -0
  145. package/dist/types/common/event-emitter/handle.d.ts +3 -0
  146. package/dist/types/common/event-emitter/handle.d.ts.map +1 -0
  147. package/dist/types/common/event-emitter/register-handler.d.ts +8 -0
  148. package/dist/types/common/event-emitter/register-handler.d.ts.map +1 -0
  149. package/dist/types/common/event-listener/event-listener-opts.d.ts +10 -0
  150. package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -0
  151. package/dist/types/common/harvest/harvest-scheduler.d.ts +21 -0
  152. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -0
  153. package/dist/types/common/harvest/harvest.d.ts +58 -0
  154. package/dist/types/common/harvest/harvest.d.ts.map +1 -0
  155. package/dist/types/common/ids/id.d.ts +2 -0
  156. package/dist/types/common/ids/id.d.ts.map +1 -0
  157. package/dist/types/common/ids/unique-id.d.ts +5 -0
  158. package/dist/types/common/ids/unique-id.d.ts.map +1 -0
  159. package/dist/types/common/metrics/framework-detection.d.ts +2 -0
  160. package/dist/types/common/metrics/framework-detection.d.ts.map +1 -0
  161. package/dist/types/common/metrics/paint-metrics.d.ts +2 -0
  162. package/dist/types/common/metrics/paint-metrics.d.ts.map +1 -0
  163. package/dist/types/common/serialize/bel-serializer.d.ts +5 -0
  164. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -0
  165. package/dist/types/common/timing/nav-timing.d.ts +5 -0
  166. package/dist/types/common/timing/nav-timing.d.ts.map +1 -0
  167. package/dist/types/common/timing/now.d.ts +2 -0
  168. package/dist/types/common/timing/now.d.ts.map +1 -0
  169. package/dist/types/common/unload/eol.d.ts +8 -0
  170. package/dist/types/common/unload/eol.d.ts.map +1 -0
  171. package/dist/types/common/url/clean-url.d.ts +2 -0
  172. package/dist/types/common/url/clean-url.d.ts.map +1 -0
  173. package/dist/types/common/url/encode.d.ts +5 -0
  174. package/dist/types/common/url/encode.d.ts.map +1 -0
  175. package/dist/types/common/url/location.d.ts +2 -0
  176. package/dist/types/common/url/location.d.ts.map +1 -0
  177. package/dist/types/common/url/parse-url.d.ts +2 -0
  178. package/dist/types/common/url/parse-url.d.ts.map +1 -0
  179. package/dist/types/common/url/protocol.d.ts +7 -0
  180. package/dist/types/common/url/protocol.d.ts.map +1 -0
  181. package/dist/types/common/util/console.d.ts +8 -0
  182. package/dist/types/common/util/console.d.ts.map +1 -0
  183. package/dist/types/common/util/data-size.d.ts +2 -0
  184. package/dist/types/common/util/data-size.d.ts.map +1 -0
  185. package/dist/types/common/util/feature-flags.d.ts +3 -0
  186. package/dist/types/common/util/feature-flags.d.ts.map +1 -0
  187. package/dist/types/common/util/get-or-set.d.ts +2 -0
  188. package/dist/types/common/util/get-or-set.d.ts.map +1 -0
  189. package/dist/types/common/util/global-scope.d.ts +13 -0
  190. package/dist/types/common/util/global-scope.d.ts.map +1 -0
  191. package/dist/types/common/util/map-own.d.ts +3 -0
  192. package/dist/types/common/util/map-own.d.ts.map +1 -0
  193. package/dist/types/common/util/obfuscate.d.ts +8 -0
  194. package/dist/types/common/util/obfuscate.d.ts.map +1 -0
  195. package/dist/types/common/util/s-hash.d.ts +2 -0
  196. package/dist/types/common/util/s-hash.d.ts.map +1 -0
  197. package/dist/types/common/util/single.d.ts +2 -0
  198. package/dist/types/common/util/single.d.ts.map +1 -0
  199. package/dist/types/common/util/stringify.d.ts +8 -0
  200. package/dist/types/common/util/stringify.d.ts.map +1 -0
  201. package/dist/types/common/util/submit-data.d.ts +35 -0
  202. package/dist/types/common/util/submit-data.d.ts.map +1 -0
  203. package/dist/types/common/util/traverse.d.ts +2 -0
  204. package/dist/types/common/util/traverse.d.ts.map +1 -0
  205. package/dist/types/common/util/user-agent.d.ts +5 -0
  206. package/dist/types/common/util/user-agent.d.ts.map +1 -0
  207. package/dist/types/common/window/load.d.ts +3 -0
  208. package/dist/types/common/window/load.d.ts.map +1 -0
  209. package/dist/types/common/window/nreum.d.ts +14 -0
  210. package/dist/types/common/window/nreum.d.ts.map +1 -0
  211. package/dist/types/common/window/page-visibility.d.ts +7 -0
  212. package/dist/types/common/window/page-visibility.d.ts.map +1 -0
  213. package/dist/types/common/window/session-storage.d.ts +18 -0
  214. package/dist/types/common/window/session-storage.d.ts.map +1 -0
  215. package/dist/types/common/window/supports-performance-observer.d.ts +2 -0
  216. package/dist/types/common/window/supports-performance-observer.d.ts.map +1 -0
  217. package/dist/types/common/wrap/index.d.ts +12 -0
  218. package/dist/types/common/wrap/index.d.ts.map +1 -0
  219. package/dist/types/common/wrap/wrap-console.d.ts +16 -0
  220. package/dist/types/common/wrap/wrap-console.d.ts.map +1 -0
  221. package/dist/types/common/wrap/wrap-events.d.ts +17 -0
  222. package/dist/types/common/wrap/wrap-events.d.ts.map +1 -0
  223. package/dist/types/common/wrap/wrap-fetch.d.ts +18 -0
  224. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -0
  225. package/dist/types/common/wrap/wrap-function.d.ts +28 -0
  226. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -0
  227. package/dist/types/common/wrap/wrap-history.d.ts +16 -0
  228. package/dist/types/common/wrap/wrap-history.d.ts.map +1 -0
  229. package/dist/types/common/wrap/wrap-jsonp.d.ts +16 -0
  230. package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -0
  231. package/dist/types/common/wrap/wrap-mutation.d.ts +16 -0
  232. package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -0
  233. package/dist/types/common/wrap/wrap-promise.d.ts +17 -0
  234. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -0
  235. package/dist/types/common/wrap/wrap-raf.d.ts +16 -0
  236. package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -0
  237. package/dist/types/common/wrap/wrap-timer.d.ts +17 -0
  238. package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -0
  239. package/dist/types/common/wrap/wrap-xhr.d.ts +16 -0
  240. package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -0
  241. package/dist/types/features/ajax/aggregate/index.d.ts +16 -0
  242. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -0
  243. package/dist/types/features/ajax/constants.d.ts +2 -0
  244. package/dist/types/features/ajax/constants.d.ts.map +1 -0
  245. package/dist/types/features/ajax/index.d.ts +2 -0
  246. package/dist/types/features/ajax/index.d.ts.map +1 -0
  247. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +19 -0
  248. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -0
  249. package/dist/types/features/ajax/instrument/index.d.ts +9 -0
  250. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -0
  251. package/dist/types/features/ajax/instrument/response-size.d.ts +2 -0
  252. package/dist/types/features/ajax/instrument/response-size.d.ts.map +1 -0
  253. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +2 -0
  254. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -0
  255. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +22 -0
  256. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -0
  257. package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts +3 -0
  258. package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts.map +1 -0
  259. package/dist/types/features/jserrors/aggregate/index.d.ts +24 -0
  260. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -0
  261. package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts +2 -0
  262. package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts.map +1 -0
  263. package/dist/types/features/jserrors/constants.d.ts +3 -0
  264. package/dist/types/features/jserrors/constants.d.ts.map +1 -0
  265. package/dist/types/features/jserrors/index.d.ts +2 -0
  266. package/dist/types/features/jserrors/index.d.ts.map +1 -0
  267. package/dist/types/features/jserrors/instrument/debug.d.ts +2 -0
  268. package/dist/types/features/jserrors/instrument/debug.d.ts.map +1 -0
  269. package/dist/types/features/jserrors/instrument/index.d.ts +22 -0
  270. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -0
  271. package/dist/types/features/metrics/aggregate/index.d.ts +12 -0
  272. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -0
  273. package/dist/types/features/metrics/constants.d.ts +6 -0
  274. package/dist/types/features/metrics/constants.d.ts.map +1 -0
  275. package/dist/types/features/metrics/index.d.ts +2 -0
  276. package/dist/types/features/metrics/index.d.ts.map +1 -0
  277. package/dist/types/features/metrics/instrument/index.d.ts +7 -0
  278. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -0
  279. package/dist/types/features/metrics/instrument/workers-helper.d.ts +7 -0
  280. package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -0
  281. package/dist/types/features/page_action/aggregate/index.d.ts +24 -0
  282. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -0
  283. package/dist/types/features/page_action/constants.d.ts +2 -0
  284. package/dist/types/features/page_action/constants.d.ts.map +1 -0
  285. package/dist/types/features/page_action/index.d.ts +2 -0
  286. package/dist/types/features/page_action/index.d.ts.map +1 -0
  287. package/dist/types/features/page_action/instrument/index.d.ts +6 -0
  288. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -0
  289. package/dist/types/features/page_view_event/aggregate/index.d.ts +9 -0
  290. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -0
  291. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts +8 -0
  292. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -0
  293. package/dist/types/features/page_view_event/constants.d.ts +5 -0
  294. package/dist/types/features/page_view_event/constants.d.ts.map +1 -0
  295. package/dist/types/features/page_view_event/index.d.ts +2 -0
  296. package/dist/types/features/page_view_event/index.d.ts.map +1 -0
  297. package/dist/types/features/page_view_event/instrument/index.d.ts +6 -0
  298. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -0
  299. package/dist/types/features/page_view_timing/aggregate/index.d.ts +33 -0
  300. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -0
  301. package/dist/types/features/page_view_timing/constants.d.ts +2 -0
  302. package/dist/types/features/page_view_timing/constants.d.ts.map +1 -0
  303. package/dist/types/features/page_view_timing/first-paint.d.ts +2 -0
  304. package/dist/types/features/page_view_timing/first-paint.d.ts.map +1 -0
  305. package/dist/types/features/page_view_timing/index.d.ts +2 -0
  306. package/dist/types/features/page_view_timing/index.d.ts.map +1 -0
  307. package/dist/types/features/page_view_timing/instrument/index.d.ts +6 -0
  308. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -0
  309. package/dist/types/features/page_view_timing/long-tasks.d.ts +2 -0
  310. package/dist/types/features/page_view_timing/long-tasks.d.ts.map +1 -0
  311. package/dist/types/features/session_trace/aggregate/index.d.ts +77 -0
  312. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -0
  313. package/dist/types/features/session_trace/constants.d.ts +13 -0
  314. package/dist/types/features/session_trace/constants.d.ts.map +1 -0
  315. package/dist/types/features/session_trace/index.d.ts +2 -0
  316. package/dist/types/features/session_trace/index.d.ts.map +1 -0
  317. package/dist/types/features/session_trace/instrument/index.d.ts +11 -0
  318. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -0
  319. package/dist/types/features/spa/aggregate/index.d.ts +25 -0
  320. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -0
  321. package/dist/types/features/spa/aggregate/interaction-node.d.ts +15 -0
  322. package/dist/types/features/spa/aggregate/interaction-node.d.ts.map +1 -0
  323. package/dist/types/features/spa/aggregate/interaction.d.ts +20 -0
  324. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -0
  325. package/dist/types/features/spa/aggregate/serializer.d.ts +15 -0
  326. package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -0
  327. package/dist/types/features/spa/constants.d.ts +23 -0
  328. package/dist/types/features/spa/constants.d.ts.map +1 -0
  329. package/dist/types/features/spa/index.d.ts +2 -0
  330. package/dist/types/features/spa/index.d.ts.map +1 -0
  331. package/dist/types/features/spa/instrument/index.d.ts +8 -0
  332. package/dist/types/features/spa/instrument/index.d.ts.map +1 -0
  333. package/dist/types/features/utils/aggregate-base.d.ts +4 -0
  334. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -0
  335. package/dist/types/features/utils/feature-base.d.ts +23 -0
  336. package/dist/types/features/utils/feature-base.d.ts.map +1 -0
  337. package/dist/types/features/utils/handler-cache.d.ts +22 -0
  338. package/dist/types/features/utils/handler-cache.d.ts.map +1 -0
  339. package/dist/types/features/utils/instrument-base.d.ts +27 -0
  340. package/dist/types/features/utils/instrument-base.d.ts.map +1 -0
  341. package/dist/types/features/utils/lazy-loader.d.ts +13 -0
  342. package/dist/types/features/utils/lazy-loader.d.ts.map +1 -0
  343. package/dist/types/index.d.ts +12 -0
  344. package/dist/types/index.d.ts.map +1 -0
  345. package/dist/types/loaders/agent.d.ts +20 -0
  346. package/dist/types/loaders/agent.d.ts.map +1 -0
  347. package/dist/types/loaders/api/api.d.ts +17 -0
  348. package/dist/types/loaders/api/api.d.ts.map +1 -0
  349. package/dist/types/loaders/api/apiAsync.d.ts +2 -0
  350. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -0
  351. package/dist/types/loaders/browser-agent.d.ts +9 -0
  352. package/dist/types/loaders/browser-agent.d.ts.map +1 -0
  353. package/dist/types/loaders/configure/configure.d.ts +10 -0
  354. package/dist/types/loaders/configure/configure.d.ts.map +1 -0
  355. package/dist/types/loaders/features/enabled-features.d.ts +2 -0
  356. package/dist/types/loaders/features/enabled-features.d.ts.map +1 -0
  357. package/dist/types/loaders/features/featureDependencies.d.ts +3 -0
  358. package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -0
  359. package/dist/types/loaders/features/features.d.ts +18 -0
  360. package/dist/types/loaders/features/features.d.ts.map +1 -0
  361. package/dist/types/loaders/micro-agent.d.ts +25 -0
  362. package/dist/types/loaders/micro-agent.d.ts.map +1 -0
  363. package/dist/types/loaders/worker-agent.d.ts +8 -0
  364. package/dist/types/loaders/worker-agent.d.ts.map +1 -0
  365. package/package.json +61 -32
  366. package/src/cdn/lite.js +18 -0
  367. package/src/cdn/polyfills/lite.js +7 -0
  368. package/src/cdn/polyfills/pro.js +7 -0
  369. package/src/cdn/polyfills/spa.js +7 -0
  370. package/src/cdn/polyfills.js +17 -0
  371. package/src/cdn/pro.js +27 -0
  372. package/src/cdn/spa.js +28 -0
  373. package/src/cdn/worker.js +21 -0
  374. package/src/common/aggregate/aggregator.js +171 -0
  375. package/src/common/browser-version/firefox-version.js +10 -0
  376. package/src/common/browser-version/ios-version.js +10 -0
  377. package/src/common/config/config.js +12 -0
  378. package/src/common/config/state/configurable.js +26 -0
  379. package/src/common/config/state/info.js +49 -0
  380. package/src/common/config/state/init.js +56 -0
  381. package/src/common/config/state/loader-config.js +25 -0
  382. package/src/common/config/state/originals.js +3 -0
  383. package/src/common/config/state/runtime.js +45 -0
  384. package/src/common/constants/environment-variables.js +11 -0
  385. package/src/common/context/shared-context.js +21 -0
  386. package/src/common/deny-list/deny-list.js +116 -0
  387. package/src/common/drain/drain.js +119 -0
  388. package/src/common/event-emitter/contextual-ee.js +159 -0
  389. package/src/common/event-emitter/handle.js +17 -0
  390. package/src/common/event-emitter/register-handler.js +25 -0
  391. package/src/common/event-listener/event-listener-opts.js +41 -0
  392. package/src/common/harvest/harvest-scheduler.js +112 -0
  393. package/src/common/harvest/harvest.js +248 -0
  394. package/src/common/ids/id.js +23 -0
  395. package/src/common/ids/unique-id.js +81 -0
  396. package/src/common/metrics/framework-detection.js +71 -0
  397. package/src/common/metrics/paint-metrics.js +6 -0
  398. package/src/common/serialize/bel-serializer.js +93 -0
  399. package/src/common/timing/nav-timing.js +70 -0
  400. package/src/common/timing/now.js +9 -0
  401. package/src/common/unload/eol.js +63 -0
  402. package/src/common/url/clean-url.js +10 -0
  403. package/src/common/url/encode.js +75 -0
  404. package/src/common/url/location.js +8 -0
  405. package/src/common/url/parse-url.js +71 -0
  406. package/src/common/url/protocol.js +19 -0
  407. package/src/common/util/console.js +11 -0
  408. package/src/common/util/data-size.js +21 -0
  409. package/src/common/util/feature-flags.js +38 -0
  410. package/src/common/util/get-or-set.js +34 -0
  411. package/src/common/util/global-scope.js +48 -0
  412. package/src/common/util/map-own.js +22 -0
  413. package/src/common/util/map-own.test.js +52 -0
  414. package/src/common/util/obfuscate.js +73 -0
  415. package/src/common/util/s-hash.js +14 -0
  416. package/src/common/util/single.js +18 -0
  417. package/src/common/util/stringify.js +42 -0
  418. package/src/common/util/submit-data.js +101 -0
  419. package/src/common/util/traverse.js +36 -0
  420. package/src/common/util/user-agent.js +56 -0
  421. package/src/common/window/load.js +15 -0
  422. package/src/common/window/nreum.js +110 -0
  423. package/src/common/window/page-visibility.js +24 -0
  424. package/src/common/window/session-storage.js +75 -0
  425. package/src/common/window/supports-performance-observer.js +10 -0
  426. package/src/common/wrap/index.js +18 -0
  427. package/src/common/wrap/wrap-console.js +47 -0
  428. package/src/common/wrap/wrap-events.js +106 -0
  429. package/src/common/wrap/wrap-fetch.js +109 -0
  430. package/src/common/wrap/wrap-function.js +248 -0
  431. package/src/common/wrap/wrap-history.js +48 -0
  432. package/src/common/wrap/wrap-jsonp.js +134 -0
  433. package/src/common/wrap/wrap-mutation.js +55 -0
  434. package/src/common/wrap/wrap-promise.js +165 -0
  435. package/src/common/wrap/wrap-raf.js +50 -0
  436. package/src/common/wrap/wrap-timer.js +67 -0
  437. package/src/common/wrap/wrap-xhr.js +213 -0
  438. package/src/features/ajax/aggregate/index.js +248 -0
  439. package/src/features/ajax/constants.js +3 -0
  440. package/src/features/ajax/index.js +1 -0
  441. package/src/features/ajax/instrument/distributed-tracing.js +166 -0
  442. package/src/features/ajax/instrument/index.js +380 -0
  443. package/src/features/ajax/instrument/response-size.js +18 -0
  444. package/src/features/jserrors/aggregate/canonical-function-name.js +14 -0
  445. package/src/features/jserrors/aggregate/canonical-function-name.test.js +13 -0
  446. package/src/features/jserrors/aggregate/compute-stack-trace.js +231 -0
  447. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +297 -0
  448. package/src/features/jserrors/aggregate/format-stack-trace.js +30 -0
  449. package/src/features/jserrors/aggregate/format-stack-trace.test.js +39 -0
  450. package/src/features/jserrors/aggregate/index.js +310 -0
  451. package/src/features/jserrors/aggregate/string-hash-code.js +17 -0
  452. package/src/features/jserrors/aggregate/string-hash-code.test.js +12 -0
  453. package/src/features/jserrors/constants.js +4 -0
  454. package/src/features/jserrors/index.js +1 -0
  455. package/src/features/jserrors/instrument/debug.js +36 -0
  456. package/src/features/jserrors/instrument/index.js +149 -0
  457. package/src/features/metrics/aggregate/index.js +134 -0
  458. package/src/features/metrics/constants.js +7 -0
  459. package/src/features/metrics/index.js +1 -0
  460. package/src/features/metrics/instrument/index.js +44 -0
  461. package/src/features/metrics/instrument/workers-helper.js +110 -0
  462. package/src/features/page_action/aggregate/index.js +113 -0
  463. package/src/features/page_action/constants.js +3 -0
  464. package/src/features/page_action/index.js +1 -0
  465. package/src/features/page_action/instrument/index.js +15 -0
  466. package/src/features/page_view_event/aggregate/index.js +134 -0
  467. package/src/features/page_view_event/aggregate/initialized-features.js +31 -0
  468. package/src/features/page_view_event/constants.js +6 -0
  469. package/src/features/page_view_event/index.js +1 -0
  470. package/src/features/page_view_event/instrument/index.js +33 -0
  471. package/src/features/page_view_timing/aggregate/index.js +246 -0
  472. package/src/features/page_view_timing/constants.js +3 -0
  473. package/src/features/page_view_timing/first-paint.js +41 -0
  474. package/src/features/page_view_timing/index.js +1 -0
  475. package/src/features/page_view_timing/instrument/index.js +30 -0
  476. package/src/features/page_view_timing/long-tasks.js +60 -0
  477. package/src/features/session_trace/aggregate/index.js +410 -0
  478. package/src/features/session_trace/constants.js +15 -0
  479. package/src/features/session_trace/index.js +1 -0
  480. package/src/features/session_trace/instrument/index.js +126 -0
  481. package/src/features/spa/aggregate/index.js +738 -0
  482. package/src/features/spa/aggregate/interaction-node.js +85 -0
  483. package/src/features/spa/aggregate/interaction-node.test.js +17 -0
  484. package/src/features/spa/aggregate/interaction.js +112 -0
  485. package/src/features/spa/aggregate/serializer.js +198 -0
  486. package/src/features/spa/constants.js +36 -0
  487. package/src/features/spa/index.js +1 -0
  488. package/src/features/spa/instrument/index.js +112 -0
  489. package/src/features/utils/aggregate-base.js +7 -0
  490. package/src/features/utils/feature-base.js +51 -0
  491. package/src/features/utils/handler-cache.js +60 -0
  492. package/src/features/utils/instrument-base.js +68 -0
  493. package/src/features/utils/lazy-loader.js +37 -0
  494. package/src/index.js +15 -0
  495. package/src/loaders/agent.js +80 -0
  496. package/src/loaders/api/api.js +175 -0
  497. package/src/loaders/api/apiAsync.js +92 -0
  498. package/src/loaders/browser-agent.js +33 -0
  499. package/src/loaders/configure/configure.js +39 -0
  500. package/src/loaders/features/enabled-features.js +16 -0
  501. package/src/loaders/features/featureDependencies.js +26 -0
  502. package/src/loaders/features/features.js +25 -0
  503. package/src/loaders/micro-agent.js +84 -0
  504. package/src/loaders/worker-agent.js +24 -0
  505. package/dist/cjs/common/util/reduce.js +0 -22
  506. package/dist/cjs/common/window/top-level-callers.js +0 -23
  507. package/dist/esm/common/util/reduce.js +0 -16
  508. package/dist/esm/common/window/top-level-callers.js +0 -17
  509. package/types.ts +0 -221
package/README.md CHANGED
@@ -131,8 +131,47 @@ import { SessionTrace } from '@newrelic/browser-agent/features/session_trace';
131
131
  import { Spa } from '@newrelic/browser-agent/features/spa';
132
132
  ```
133
133
 
134
+ ## Supported Browsers
135
+
136
+ Our supported browser list can be accessed [here](https://docs.newrelic.com/docs/browser/new-relic-browser/getting-started/compatibility-requirements-browser-monitoring/#browser-types).
137
+
138
+ If you desire more control over how the agent is built, our package also includes the source code. The source code is written to target the latest ECMAScript standards (ES2022). Please note that if you import the browser agent source code instead of the transpiled distribution code, you may need to alter your project's build system to apply transformations to the browser agent source code. Without these transforms, the code produced by your project's build system may not be compatible with your desired target browsers. Below is an example of how to import the source code.
139
+
140
+ ```javascript
141
+ // Note the /src/ in the import paths below
142
+ import { Agent } from '@newrelic/browser-agent/src/loaders/agent'
143
+ import { Metrics } from '@newrelic/browser-agent/src/features/metrics'
144
+ import { PageViewEvent } from '@newrelic/browser-agent/src/features/page_view_event'
145
+ import { PageViewTiming } from '@newrelic/browser-agent/src/features/page_view_timing'
146
+
147
+ const options = {
148
+ info: { ... },
149
+ loader_config: { ... },
150
+ init: { ... }
151
+ }
152
+
153
+ new Agent({
154
+ ...options,
155
+ features: [
156
+ Metrics,
157
+ PageViewEvent,
158
+ PageViewTiming
159
+ ]
160
+ })
161
+ ```
162
+
163
+ Neither the browser agent development team nor the New Relic support teams can support the numerous build systems that exist in the JavaScript ecosystem. If you run into issues, you may be asked to revert to importing from the transpiled distribution code.
164
+
165
+ **DON'T** mix imports between the browser agent source code and transpiled distribution code. The below will break.
166
+
167
+ ```javascript
168
+ // THIS IS BAD - do not do this
169
+ import { Agent } from '@newrelic/browser-agent/loaders/agent'
170
+ import { Metrics } from '@newrelic/browser-agent/src/features/metrics'
171
+ ```
172
+
134
173
  ## License
135
174
 
136
175
  The Browser agent is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
137
176
 
138
- The Browser agent also uses source code from third-party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the [third-party notices document](THIRD_PARTY_NOTICES.md).
177
+ The Browser agent also uses source code from third-party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the [third-party notices document](THIRD_PARTY_NOTICES.md).
@@ -12,7 +12,8 @@ class Configurable {
12
12
  if (!obj || typeof obj !== 'object') return (0, _console.warn)('New setting a Configurable requires an object as input');
13
13
  if (!model || typeof model !== 'object') return (0, _console.warn)('Setting a Configurable requires a model to set its initial properties');
14
14
  Object.assign(this, model);
15
- Object.entries(obj).forEach(([key, value]) => {
15
+ Object.entries(obj).forEach(_ref => {
16
+ let [key, value] = _ref;
16
17
  const frozenAttrs = (0, _featureDependencies.getFrozenAttributes)(key);
17
18
  if (frozenAttrs.length && value && typeof value === 'object') {
18
19
  frozenAttrs.forEach(attr => {
@@ -17,6 +17,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
17
17
  const model = agentId => {
18
18
  return {
19
19
  buildEnv: _environmentVariables.BUILD_ENV,
20
+ bytesSent: {},
20
21
  customTransaction: undefined,
21
22
  disabled: false,
22
23
  distMethod: _environmentVariables.DIST_METHOD,
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
7
7
  // Webpack and NPM builds define `process.env.BUILD_VERSION` at build time based on variables supplied at build time.
8
8
  // VERSION as defined here ends up decorating: agent runtime configuration, harvest, and supportability metrics.
9
- const VERSION = typeof "0.1.229" !== 'undefined' && "0.1.229" || '';
9
+ const VERSION = typeof "0.1.230" !== 'undefined' && "0.1.230" || '';
10
10
 
11
11
  // process.env.BUILD_ENV is replaced during webpack -or- npm build with environment vars supplied at build time
12
12
  // LOCAL, PROD, DEV, etc
@@ -14,7 +14,8 @@ class SharedContext {
14
14
  if (typeof context !== 'object') return (0, _console.warn)('shared context requires an object as input');
15
15
  this.sharedContext = {};
16
16
  Object.assign(this.sharedContext, model);
17
- Object.entries(context).forEach(([key, value]) => {
17
+ Object.entries(context).forEach(_ref => {
18
+ let [key, value] = _ref;
18
19
  if (Object.keys(model).includes(key)) this.sharedContext[key] = value;
19
20
  });
20
21
  } catch (err) {
@@ -51,7 +51,9 @@ function curateRegistry(agentIdentifier) {
51
51
  * @param {string} agentIdentifier - A unique 16 character ID corresponding to an instantiated agent.
52
52
  * @param {string} featureName - A named group into which the feature's buffered events are bucketed.
53
53
  */
54
- function drain(agentIdentifier = '', featureName = 'feature') {
54
+ function drain() {
55
+ let agentIdentifier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
56
+ let featureName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'feature';
55
57
  curateRegistry(agentIdentifier);
56
58
 
57
59
  // If the feature for the specified agent is not in the registry, that means the instrument file was bypassed.
@@ -65,9 +67,13 @@ function drain(agentIdentifier = '', featureName = 'feature') {
65
67
  // Only when the event-groups for all features are ready to drain (staged) do we execute the drain. This has the effect
66
68
  // that the last feature to call drain triggers drain for all features.
67
69
  const items = Array.from(registry[agentIdentifier]);
68
- if (items.every(([key, values]) => values.staged)) {
70
+ if (items.every(_ref => {
71
+ let [key, values] = _ref;
72
+ return values.staged;
73
+ })) {
69
74
  items.sort((a, b) => a[1].priority - b[1].priority);
70
- items.forEach(([group]) => {
75
+ items.forEach(_ref2 => {
76
+ let [group] = _ref2;
71
77
  drainGroup(group);
72
78
  });
73
79
  }
@@ -37,10 +37,12 @@ function eventListenerOpts(useCapture, abortSignal) {
37
37
  }
38
38
 
39
39
  /** Do not use this within the worker context. */
40
- function windowAddEventListener(event, listener, capture = false) {
40
+ function windowAddEventListener(event, listener) {
41
+ let capture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
41
42
  window.addEventListener(event, listener, eventListenerOpts(capture));
42
43
  }
43
44
  /** Do not use this within the worker context. */
44
- function documentAddEventListener(event, listener, capture = false) {
45
+ function documentAddEventListener(event, listener) {
46
+ let capture = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
45
47
  document.addEventListener(event, listener, eventListenerOpts(capture));
46
48
  }
@@ -43,7 +43,8 @@ class HarvestScheduler extends _sharedContext.SharedContext {
43
43
  this.started = true;
44
44
  this.scheduleHarvest(initialDelay != null ? initialDelay : this.interval);
45
45
  }
46
- stopTimer(permanently = false) {
46
+ stopTimer() {
47
+ let permanently = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
47
48
  this.aborted = permanently; // stopping permanently is same as aborting, but this function also cleans up the setTimeout loop
48
49
  this.started = false;
49
50
  if (this.timeoutHandle) {
@@ -71,6 +71,7 @@ class Harvest extends _sharedContext.SharedContext {
71
71
  * @param {bool} opts.unload - Specify whether the call is a final harvest during page unload.
72
72
  */
73
73
  send(endpoint, singlePayload, opts, submitMethod, cbFinished) {
74
+ var _this = this;
74
75
  var makeBody = createAccumulator();
75
76
  var makeQueryString = createAccumulator();
76
77
  if (singlePayload.body) (0, _mapOwn.mapOwn)(singlePayload.body, makeBody);
@@ -79,11 +80,18 @@ class Harvest extends _sharedContext.SharedContext {
79
80
  body: makeBody(),
80
81
  qs: makeQueryString()
81
82
  };
82
- var caller = this.obfuscator.shouldObfuscate() ? (...args) => this.obfuscateAndSend(...args) : (...args) => this._send(...args);
83
+ var caller = this.obfuscator.shouldObfuscate() ? function () {
84
+ return _this.obfuscateAndSend(...arguments);
85
+ } : function () {
86
+ return _this._send(...arguments);
87
+ };
83
88
  return caller(endpoint, payload, opts, submitMethod, cbFinished);
84
89
  }
85
90
  obfuscateAndSend(endpoint, payload, opts, submitMethod, cbFinished) {
86
- (0, _traverse.applyFnToProps)(payload, (...args) => this.obfuscator.obfuscateString(...args), 'string', ['e']);
91
+ var _this2 = this;
92
+ (0, _traverse.applyFnToProps)(payload, function () {
93
+ return _this2.obfuscator.obfuscateString(...arguments);
94
+ }, 'string', ['e']);
87
95
  return this._send(endpoint, payload, opts, submitMethod, cbFinished);
88
96
  }
89
97
  _send(endpoint, payload, opts, submitMethod, cbFinished) {
@@ -117,6 +125,9 @@ class Harvest extends _sharedContext.SharedContext {
117
125
  fullUrl = url + (0, _encode.obj)(payload.body, agentRuntime.maxBytes);
118
126
  }
119
127
 
128
+ // Get bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
129
+ agentRuntime.bytesSent[endpoint] = (agentRuntime.bytesSent[endpoint] || 0) + body?.length || 0;
130
+
120
131
  /* Since workers don't support sendBeacon right now, or Image(), they can only use XHR method.
121
132
  Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
122
133
  we just make a BLOCKING request--trivial impact--with the remaining data as a temp fill-in for sendBeacon. */
@@ -11,7 +11,7 @@ exports.warn = warn;
11
11
  * @returns
12
12
  */
13
13
  function warn(message, secondary) {
14
- if (!console || !console.warn || typeof console.warn !== 'function') return;
14
+ if (typeof console.warn !== 'function') return;
15
15
  console.warn(`New Relic: ${message}`);
16
16
  if (secondary) console.warn(secondary);
17
17
  }
@@ -3,22 +3,29 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.mapOwn = mapOwn;
6
+ exports.mapOwn = void 0;
7
7
  /*
8
8
  * Copyright 2020 New Relic Corporation. All rights reserved.
9
9
  * SPDX-License-Identifier: Apache-2.0
10
10
  */
11
11
 
12
- var has = Object.prototype.hasOwnProperty;
13
- function mapOwn(obj, fn) {
14
- var results = [];
15
- var key = '';
16
- var i = 0;
17
- for (key in obj) {
18
- if (has.call(obj, key)) {
19
- results[i] = fn(key, obj[key]);
20
- i += 1;
21
- }
22
- }
23
- return results;
24
- }
12
+ /**
13
+ * @typedef {function} MapOwnCallback
14
+ * @param {string} key Object key
15
+ * @param {any} value Object value
16
+ * @returns {any}
17
+ */
18
+
19
+ /**
20
+ * Iterates the own enumerable properties of an object passing the key and value pair to a given
21
+ * callback function.
22
+ * @param {object} obj Input object to iterate over. If null or undefined, an empty array will be returned.
23
+ * @param {MapOwnCallback} fn A callback function called for each property. The callback should take the key
24
+ * and value from the object iteration and return some value.
25
+ * @returns {any[]} An array of values returned by the callback function.
26
+ */
27
+ const mapOwn = (obj, fn) => Object.entries(obj || {}).map(_ref => {
28
+ let [key, value] = _ref;
29
+ return fn(key, value);
30
+ });
31
+ exports.mapOwn = mapOwn;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _mapOwn = require("./map-own");
4
+ test('enumerates the object properties', () => {
5
+ const callback = jest.fn();
6
+ const input = {
7
+ foo: 'bar'
8
+ };
9
+ (0, _mapOwn.mapOwn)(input, callback);
10
+ expect(callback).toHaveBeenCalledWith('foo', 'bar');
11
+ });
12
+ test('return array of results from callback invocation', () => {
13
+ const callback = jest.fn((key, value) => `${key}:${value}`);
14
+ const input = {
15
+ foo: 'bar',
16
+ biz: 'baz'
17
+ };
18
+ const result = (0, _mapOwn.mapOwn)(input, callback);
19
+ expect(result.length).toEqual(2);
20
+ expect(result).toContain('foo:bar');
21
+ expect(result).toContain('biz:baz');
22
+ });
23
+ test('does not iterate symbol properties', () => {
24
+ const callback = jest.fn((key, value) => `${key}:${value}`);
25
+ const input = {
26
+ foo: 'bar',
27
+ [Symbol.for('biz')]: 'baz'
28
+ };
29
+ const result = (0, _mapOwn.mapOwn)(input, callback);
30
+ expect(result.length).toEqual(1);
31
+ });
32
+ test('does not iterate inherited properties', () => {
33
+ function F() {}
34
+ F.prototype = {
35
+ biz: 'baz'
36
+ };
37
+ const callback = jest.fn((key, value) => `${key}:${value}`);
38
+ const input = new F();
39
+ input.foo = 'bar';
40
+ const result = (0, _mapOwn.mapOwn)(input, callback);
41
+ expect(result.length).toEqual(1);
42
+ });
43
+ test.each([null, undefined])('returns empty array when passed object is null or undefined', input => {
44
+ const callback = jest.fn();
45
+ const result = (0, _mapOwn.mapOwn)(input, callback);
46
+ expect(Array.isArray(result)).toEqual(true);
47
+ expect(result.length).toEqual(0);
48
+ expect(callback).toHaveBeenCalledTimes(0);
49
+ });
@@ -53,7 +53,8 @@ submitData.xhrGet = function xhrGet(url) {
53
53
  * @param {boolean} sync
54
54
  * @returns {XMLHttpRequest}
55
55
  */
56
- submitData.xhr = function xhr(url, body, sync, method = 'POST') {
56
+ submitData.xhr = function xhr(url, body, sync) {
57
+ let method = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'POST';
57
58
  var request = new XMLHttpRequest();
58
59
  request.open(method, url, !sync);
59
60
  try {
@@ -94,6 +95,13 @@ submitData.img = function img(url) {
94
95
  submitData.beacon = function (url, body) {
95
96
  // Navigator has to be bound to ensure it does not error in some browsers
96
97
  // https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
97
- const send = window.navigator.sendBeacon.bind(navigator);
98
- return send(url, body);
98
+ const send = window.navigator.sendBeacon.bind(window.navigator);
99
+ try {
100
+ return send(url, body);
101
+ } catch (err) {
102
+ // if sendBeacon still trys to throw an illegal invocation error,
103
+ // we can catch here and return. The harvest module will fallback to use
104
+ // .img to try to send
105
+ return false;
106
+ }
99
107
  };
@@ -15,7 +15,8 @@ var _eventListenerOpts = require("../event-listener/event-listener-opts");
15
15
  * @param {boolean} [toHiddenOnly=false] - only execute the 'cb' when the vis is changing to the hidden state; no arg is passed to 'cb' if used
16
16
  * @returns void
17
17
  */
18
- function subscribeToVisibilityChange(cb, toHiddenOnly = false) {
18
+ function subscribeToVisibilityChange(cb) {
19
+ let toHiddenOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
19
20
  (0, _eventListenerOpts.documentAddEventListener)('visibilitychange', handleVisibilityChange);
20
21
  return;
21
22
  function handleVisibilityChange() {
@@ -3,9 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getAllStorageItemsOfGroup = getAllStorageItemsOfGroup;
6
7
  exports.getCurrentSessionIdOrMakeNew = getCurrentSessionIdOrMakeNew;
8
+ exports.putInBrowserStorage = putInBrowserStorage;
9
+ exports.removeFromBrowserStorage = removeFromBrowserStorage;
7
10
  var _uniqueId = require("../ids/unique-id");
8
- var _globalScope = require("../util/global-scope");
9
11
  /**
10
12
  * Interface for Agents' usage of the Window.sessionStorage as a replacement to third-party cookies.
11
13
  * (All agents on a tab|window will share the same sessionStorage.)
@@ -14,29 +16,72 @@ var _globalScope = require("../util/global-scope");
14
16
  * @environment Browser script
15
17
  */
16
18
 
17
- const SESS_ID = 'NRBA_SESSION_ID'; // prevents potential key collisions in session storage
19
+ const AGENT_PREFIX = 'NRBA/';
20
+
21
+ /**
22
+ * @param {string} key
23
+ * @param {string} value
24
+ * @returns true, if item was set successfully. false, if storage is full or setItem threw an exception.
25
+ */
26
+ function putInBrowserStorage(key, value) {
27
+ let subgroup = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
28
+ try {
29
+ window.sessionStorage.setItem(AGENT_PREFIX + subgroup + key, value);
30
+ return true;
31
+ } catch (ex) {
32
+ // Session storage may be full.
33
+ return false;
34
+ }
35
+ }
36
+ /**
37
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem}
38
+ * @param {string} key
39
+ */
40
+ function getFromBrowserStorage(key) {
41
+ let subgroup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
42
+ return window.sessionStorage.getItem(AGENT_PREFIX + subgroup + key);
43
+ }
44
+ function removeFromBrowserStorage(key) {
45
+ let subgroup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
46
+ try {
47
+ window.sessionStorage.removeItem(AGENT_PREFIX + subgroup + key);
48
+ } catch (e) {}
49
+ }
18
50
 
19
51
  /**
20
52
  * @returns {string} This tab|window's session identifier, or a new ID if not found in storage
21
53
  */
22
54
  function getCurrentSessionIdOrMakeNew() {
23
- if (!_globalScope.isBrowserScope) {
24
- return null;
25
- }
26
55
  try {
27
56
  let sessionId;
28
- if ((sessionId = window.sessionStorage.getItem(SESS_ID)) === null) {
57
+ if ((sessionId = getFromBrowserStorage('SESSION_ID')) === null) {
29
58
  // Generate a new one if storage is empty (no previous ID was created or currently exists)
30
59
  sessionId = (0, _uniqueId.generateRandomHexString)(16);
31
- window.sessionStorage.setItem(SESS_ID, sessionId);
60
+ putInBrowserStorage('SESSION_ID', sessionId);
32
61
  }
33
62
  return sessionId;
34
63
  } catch (ex) {
35
- // Session storage quota most likely 0mb and cannot be written to
36
- // OR the agent is running in a security context that does not allow
37
- // access to the browser sessionStorage
64
+ // The agent is running in a security context that does not allow access to the sessionStorage or is not in browser window context.
38
65
  return null;
39
66
  }
40
67
  }
41
68
 
42
- // In the future, we may expand sessionStorage to, say, auto-save some other agent data between page refreshes.
69
+ /**
70
+ * Look through the page's sessionStorage items and gather the ones that was set under some grouping label, if applicable.
71
+ * @param {string} [subgroup] - empty string by default, which will return all items set by browser agent
72
+ * @returns An object of the key-value items from putInBrowserStorage calls from agents with access to the same storage space.
73
+ */
74
+ function getAllStorageItemsOfGroup() {
75
+ let subgroup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
76
+ const prefixFilter = AGENT_PREFIX + subgroup;
77
+ const groupItems = {};
78
+ try {
79
+ for (let i = 0; i < window.sessionStorage.length; i++) {
80
+ let key = window.sessionStorage.key(i);
81
+ if (!key.startsWith(prefixFilter)) continue;else key = key.slice(prefixFilter.length); // this removes the "NRBA/<subgroup>" prefix so we get back the original key putInBrowserStorage
82
+
83
+ groupItems[key] = getFromBrowserStorage(key, subgroup);
84
+ }
85
+ } catch (ex) {}
86
+ return groupItems;
87
+ }
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "wrapConsole", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _wrapConsole.wrapConsole;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "wrapEvents", {
7
13
  enumerable: true,
8
14
  get: function () {
@@ -57,12 +63,13 @@ Object.defineProperty(exports, "wrapXhr", {
57
63
  return _wrapXhr.wrapXhr;
58
64
  }
59
65
  });
66
+ var _wrapConsole = require("./wrap-console");
67
+ var _wrapEvents = require("./wrap-events");
60
68
  var _wrapFetch = require("./wrap-fetch");
61
- var _wrapTimer = require("./wrap-timer");
62
- var _wrapRaf = require("./wrap-raf");
63
69
  var _wrapHistory = require("./wrap-history");
64
70
  var _wrapJsonp = require("./wrap-jsonp");
65
71
  var _wrapMutation = require("./wrap-mutation");
66
72
  var _wrapPromise = require("./wrap-promise");
67
- var _wrapXhr = require("./wrap-xhr");
68
- var _wrapEvents = require("./wrap-events");
73
+ var _wrapRaf = require("./wrap-raf");
74
+ var _wrapTimer = require("./wrap-timer");
75
+ var _wrapXhr = require("./wrap-xhr");
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.scopedEE = scopedEE;
7
+ exports.wrapConsole = wrapConsole;
8
+ var _contextualEe = require("../event-emitter/contextual-ee");
9
+ var _wrapFunction = require("./wrap-function");
10
+ var _globalScope = require("../util/global-scope");
11
+ /*
12
+ * Copyright 2020 New Relic Corporation. All rights reserved.
13
+ * SPDX-License-Identifier: Apache-2.0
14
+ */
15
+ /**
16
+ * @file Wraps `debug`, `error`, `info`, `log`, `trace, and `warn` methods of the global `console` object for instrumentation.
17
+ * This module is used by: metrics.
18
+ */
19
+
20
+ const wrapped = {};
21
+ const CONSOLE_METHODS = ['debug', 'error', 'info', 'log', 'trace', 'warn'];
22
+
23
+ /**
24
+ * Wraps the `debug`, `error`, `info`, `log`, `trace, and `warn` methods of global `console` object and returns a
25
+ * corresponding event emitter scoped to the console object.
26
+ * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
27
+ * @returns {Object} Scoped event emitter with a debug ID of `console`.
28
+ */
29
+ function wrapConsole(sharedEE) {
30
+ const ee = scopedEE(sharedEE);
31
+
32
+ // We want to wrap console once and only once for each agent instance (`ee.debugId`).
33
+ if (wrapped[ee.debugId]) {
34
+ return ee;
35
+ }
36
+ wrapped[ee.debugId] = true;
37
+ var functionWrapper = (0, _wrapFunction.createWrapperWithEmitter)(ee);
38
+ // Because the console object exists once on the global scope, we don't need to wrap the prototype's methods.
39
+ // We use the global scope instead of window to accomodate service workers.
40
+ // The leading hyphen on '-console-' tells `inPlace` to prefix emitted event names with the method name too.
41
+ functionWrapper.inPlace(_globalScope.globalScope.console, CONSOLE_METHODS, '-console-');
42
+ return ee;
43
+ }
44
+
45
+ /**
46
+ * Returns an event emitter scoped specifically for the `console` 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 'console'.
51
+ */
52
+ function scopedEE(sharedEE) {
53
+ return (sharedEE || _contextualEe.ee).get('console');
54
+ }
@@ -85,11 +85,14 @@ function wrapEvents(sharedEE) {
85
85
  * @param {Function} cb - the function to run on the ancestral object once found, accepts an object as a arg
86
86
  * @param {Array} rest - [optional] any additional arguments to pass to the cb
87
87
  */
88
- function findEventListenerProtoAndCb(object, cb, ...rest) {
88
+ function findEventListenerProtoAndCb(object, cb) {
89
89
  let step = object;
90
90
  while (typeof step === 'object' && !Object.prototype.hasOwnProperty.call(step, ADD_EVENT_LISTENER)) {
91
91
  step = Object.getPrototypeOf(step);
92
92
  }
93
+ for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
94
+ rest[_key - 2] = arguments[_key];
95
+ }
93
96
  if (step) cb(step, ...rest);
94
97
  }
95
98
 
@@ -95,10 +95,8 @@ function wrapFetch(sharedEE) {
95
95
  throw err;
96
96
  });
97
97
  };
98
- target[name][_wrapFunction.flag] = fn; // track original similar to in wrap-function.js, so that they can be unwrapped with ease
99
98
  }
100
99
  }
101
-
102
100
  return ee;
103
101
  }
104
102
 
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createWrapperWithEmitter = createWrapperWithEmitter;
7
7
  exports.flag = exports.default = void 0;
8
- exports.unwrapFunction = unwrapFunction;
9
8
  exports.wrapFunction = wrapFunction;
10
9
  exports.wrapInPlace = wrapInPlace;
11
10
  var _contextualEe = require("../event-emitter/contextual-ee");
@@ -115,7 +114,8 @@ function createWrapperWithEmitter(emitter, always) {
115
114
  * Creates wrapper functions around each of an array of methods on a specified object.
116
115
  * @param {Object} obj - The object to which the specified methods belong.
117
116
  * @param {string[]} methods - An array of method names to be wrapped.
118
- * @param {string} [prefix=''] - A prefix to add to the names of emitted events.
117
+ * @param {string} [prefix=''] - A prefix to add to the names of emitted events. If `-` is the first character, also
118
+ * adds the method name before the prefix.
119
119
  * @param {function|object} [getContext] - The function or object that will serve as the 'this' context for handlers
120
120
  * of events emitted by this wrapper.
121
121
  * @param {boolean} [bubble=false] - If `true`, emitted events should also bubble up to the old emitter upon which
@@ -123,8 +123,7 @@ function createWrapperWithEmitter(emitter, always) {
123
123
  */
124
124
  function inPlace(obj, methods, prefix, getContext, bubble) {
125
125
  if (!prefix) prefix = '';
126
- // If prefix starts with '-' set this boolean to add the method name to
127
- // the prefix before passing each one to wrap.
126
+ // If prefix starts with '-' set this boolean to add the method name to the prefix before passing each one to wrap.
128
127
  var prependMethodPrefix = prefix.charAt(0) === '-';
129
128
  var fn;
130
129
  var method;
@@ -133,8 +132,7 @@ function createWrapperWithEmitter(emitter, always) {
133
132
  method = methods[i];
134
133
  fn = obj[method];
135
134
 
136
- // Unless fn is both wrappable and unwrapped bail,
137
- // so we don't add extra properties with undefined values.
135
+ // Unless fn is both wrappable and unwrapped, bail so we don't add extra properties with undefined values.
138
136
  if (notWrappable(fn)) continue;
139
137
  obj[method] = wrapFn(fn, prependMethodPrefix ? method + prefix : prefix, getContext, method, bubble);
140
138
  }
@@ -254,16 +252,4 @@ function wrapFunction(fn, wrapper) {
254
252
  function wrapInPlace(obj, fnName, wrapper) {
255
253
  var fn = obj[fnName];
256
254
  obj[fnName] = wrapFunction(fn, wrapper);
257
- }
258
-
259
- /**
260
- * If a function property on an object (e.g. window) was previously wrapped (by this module), removes the wrapper.
261
- * @param {Object} obj - The object on which the named function is a property.
262
- * @param {string} fnName - The name of the function to be unwrapped.
263
- */
264
- function unwrapFunction(obj, fnName) {
265
- if (obj?.[fnName]?.[flag]) {
266
- // previous state of the function property is stored under our wrapper's "flag"; we don't wrap properties that *were* undefined to begin with
267
- obj[fnName] = obj[fnName][flag];
268
- }
269
255
  }
@@ -111,10 +111,13 @@ function wrapPromise(sharedEE) {
111
111
 
112
112
  // Note that this wrapping affects the same originals.PR (prototype) object.
113
113
  const prevPromiseOrigThen = prevPromiseObj.prototype.then;
114
- prevPromiseObj.prototype.then = function wrappedThen(...args) {
114
+ prevPromiseObj.prototype.then = function wrappedThen() {
115
115
  var originalThis = this;
116
116
  var ctx = getContext(originalThis);
117
117
  ctx.promise = originalThis;
118
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
119
+ args[_key] = arguments[_key];
120
+ }
118
121
  args[0] = promiseWrapper(args[0], 'cb-', ctx, null, false);
119
122
  args[1] = promiseWrapper(args[1], 'cb-', ctx, null, false);
120
123
  const origFnCallWithThis = prevPromiseOrigThen.apply(this, args);
@@ -30,7 +30,8 @@ var origRequest = _config.originals.REQ;
30
30
  var origXHR = _globalScope.globalScope.XMLHttpRequest;
31
31
  class Instrument extends _instrumentBase.InstrumentBase {
32
32
  static featureName = _constants.FEATURE_NAME;
33
- constructor(agentIdentifier, aggregator, auto = true) {
33
+ constructor(agentIdentifier, aggregator) {
34
+ let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
34
35
  super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
35
36
 
36
37
  // Very unlikely, but in case the existing XMLHttpRequest.prototype object on the page couldn't be wrapped.
@@ -21,10 +21,11 @@ test.each([{
21
21
  input: '<anonymous>',
22
22
  expected: undefined,
23
23
  title: 'Return undefined ending is non-alphanumeric'
24
- }])('$title', ({
25
- input,
26
- expected
27
- }) => {
24
+ }])('$title', _ref => {
25
+ let {
26
+ input,
27
+ expected
28
+ } = _ref;
28
29
  const result = (0, _canonicalFunctionName.canonicalFunctionName)(input);
29
30
  expect(result).toEqual(expected);
30
31
  });