@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
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ var has = Object.prototype.hasOwnProperty
7
+
8
+ // Always returns the current value of obj[prop], even if it has to set it first
9
+ export function getOrSet (obj, prop, getVal) {
10
+ // If the value exists return it.
11
+ if (has.call(obj, prop)) return obj[prop]
12
+
13
+ var val = getVal()
14
+
15
+ // Attempt to set the property so it's not enumerable
16
+ if (Object.defineProperty && Object.keys) {
17
+ try {
18
+ Object.defineProperty(obj, prop, {
19
+ value: val, // old IE inherits non-write-ability
20
+ writable: true,
21
+ enumerable: false
22
+ })
23
+
24
+ return val
25
+ } catch (e) {
26
+ // Can't report internal errors,
27
+ // because GOS is a dependency of the reporting mechanisms
28
+ }
29
+ }
30
+
31
+ // fall back to setting normally
32
+ obj[prop] = val
33
+ return val
34
+ }
@@ -0,0 +1,48 @@
1
+ /* global globalThis, WorkerGlobalScope, WorkerNavigator */
2
+
3
+ export const isBrowserScope =
4
+ Boolean(typeof window !== 'undefined' && window.document)
5
+
6
+ export const isWorkerScope =
7
+ Boolean(typeof WorkerGlobalScope !== 'undefined' && self.navigator instanceof WorkerNavigator)
8
+
9
+ export let globalScope = (() => {
10
+ if (isBrowserScope) {
11
+ return window
12
+ } else if (isWorkerScope) {
13
+ if (typeof globalThis !== 'undefined' && globalThis instanceof WorkerGlobalScope) {
14
+ return globalThis
15
+ } else if (self instanceof WorkerGlobalScope) {
16
+ return self
17
+ }
18
+ }
19
+
20
+ throw new Error('New Relic browser agent shutting down due to error: Unable to locate global scope. This is possibly due to code redefining browser global variables like "self" and "window".')
21
+ })()
22
+
23
+ /**
24
+ * The below methods are only used for testing and should be removed once the
25
+ * reliant tests are moved to Jest.
26
+ * tests/browser/protocol.browser.js
27
+ * tests/browser/obfuscate.browser.js
28
+ */
29
+ export function setScope (obj) {
30
+ globalScope = { ...obj }
31
+ }
32
+ export function resetScope () {
33
+ if (isBrowserScope) {
34
+ globalScope = window
35
+ } else if (isWorkerScope) {
36
+ if (typeof globalThis !== 'undefined' && globalThis instanceof WorkerGlobalScope) {
37
+ globalScope = globalThis
38
+ } else if (self instanceof WorkerGlobalScope) {
39
+ globalScope = self
40
+ }
41
+ }
42
+ else {
43
+ throw new Error('New Relic browser agent shutting down due to error: Unable to locate global scope. This is possibly due to code redefining browser global variables like "self" and "window".')
44
+ }
45
+ }
46
+ export function getGlobalScope () {
47
+ return globalScope
48
+ }
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * @typedef {function} MapOwnCallback
8
+ * @param {string} key Object key
9
+ * @param {any} value Object value
10
+ * @returns {any}
11
+ */
12
+
13
+ /**
14
+ * Iterates the own enumerable properties of an object passing the key and value pair to a given
15
+ * callback function.
16
+ * @param {object} obj Input object to iterate over. If null or undefined, an empty array will be returned.
17
+ * @param {MapOwnCallback} fn A callback function called for each property. The callback should take the key
18
+ * and value from the object iteration and return some value.
19
+ * @returns {any[]} An array of values returned by the callback function.
20
+ */
21
+ export const mapOwn = (obj, fn) => Object.entries(obj || {})
22
+ .map(([key, value]) => fn(key, value))
@@ -0,0 +1,52 @@
1
+ import { mapOwn } from './map-own'
2
+
3
+ test('enumerates the object properties', () => {
4
+ const callback = jest.fn()
5
+ const input = { foo: 'bar' }
6
+
7
+ mapOwn(input, callback)
8
+
9
+ expect(callback).toHaveBeenCalledWith('foo', 'bar')
10
+ })
11
+
12
+ test('return array of results from callback invocation', () => {
13
+ const callback = jest.fn((key, value) => `${key}:${value}`)
14
+ const input = { foo: 'bar', biz: 'baz' }
15
+
16
+ const result = mapOwn(input, callback)
17
+
18
+ expect(result.length).toEqual(2)
19
+ expect(result).toContain('foo:bar')
20
+ expect(result).toContain('biz:baz')
21
+ })
22
+
23
+ test('does not iterate symbol properties', () => {
24
+ const callback = jest.fn((key, value) => `${key}:${value}`)
25
+ const input = { foo: 'bar', [Symbol.for('biz')]: 'baz' }
26
+
27
+ const result = mapOwn(input, callback)
28
+
29
+ expect(result.length).toEqual(1)
30
+ })
31
+
32
+ test('does not iterate inherited properties', () => {
33
+ function F () {}
34
+ F.prototype = { biz: 'baz' }
35
+
36
+ const callback = jest.fn((key, value) => `${key}:${value}`)
37
+ const input = new F()
38
+ input.foo = 'bar'
39
+
40
+ const result = mapOwn(input, callback)
41
+
42
+ expect(result.length).toEqual(1)
43
+ })
44
+
45
+ test.each([null, undefined])('returns empty array when passed object is null or undefined', (input) => {
46
+ const callback = jest.fn()
47
+ const result = mapOwn(input, callback)
48
+
49
+ expect(Array.isArray(result)).toEqual(true)
50
+ expect(result.length).toEqual(0)
51
+ expect(callback).toHaveBeenCalledTimes(0)
52
+ })
@@ -0,0 +1,73 @@
1
+ import { getConfigurationValue } from '../config/config'
2
+ import { SharedContext } from '../context/shared-context'
3
+ import { protocol } from '../url/protocol'
4
+ import { warn } from './console'
5
+
6
+ var fileProtocolRule = {
7
+ regex: /^file:\/\/(.*)/,
8
+ replacement: 'file://OBFUSCATED'
9
+ }
10
+ export class Obfuscator extends SharedContext {
11
+ constructor (parent) {
12
+ super(parent) // gets any allowed properties from the parent and stores them in `sharedContext`
13
+ }
14
+
15
+ shouldObfuscate () {
16
+ return getRules(this.sharedContext.agentIdentifier).length > 0
17
+ }
18
+
19
+ // applies all regex obfuscation rules to provided URL string and returns the result
20
+ obfuscateString (string) {
21
+ // if string is empty string, null or not a string, return unmodified
22
+ if (!string || typeof string !== 'string') return string
23
+
24
+ var rules = getRules(this.sharedContext.agentIdentifier)
25
+ var obfuscated = string
26
+
27
+ // apply every rule to URL string
28
+ for (var i = 0; i < rules.length; i++) {
29
+ var regex = rules[i].regex
30
+ var replacement = rules[i].replacement || '*'
31
+ obfuscated = obfuscated.replace(regex, replacement)
32
+ }
33
+ return obfuscated
34
+ }
35
+ }
36
+
37
+ // TO DO: this function should be inside the Obfuscator class since its context relates to agentID
38
+ export function getRules (agentIdentifier) {
39
+ var rules = []
40
+ var configRules = getConfigurationValue(agentIdentifier, 'obfuscate') || []
41
+
42
+ rules = rules.concat(configRules)
43
+
44
+ if (protocol.isFileProtocol()) rules.push(fileProtocolRule)
45
+ // could add additional runtime/environment-specific rules here
46
+
47
+ return rules
48
+ }
49
+
50
+ // takes array of rule objects, logs warning and returns false if any portion of rule is invalid
51
+ export function validateRules (rules) {
52
+ var invalidReplacementDetected = false
53
+ var invalidRegexDetected = false
54
+ for (var i = 0; i < rules.length; i++) {
55
+ if (!('regex' in rules[i])) {
56
+ warn('An obfuscation replacement rule was detected missing a "regex" value.')
57
+ invalidRegexDetected = true
58
+ } else if (typeof rules[i].regex !== 'string' && !(rules[i].regex.constructor === RegExp)) {
59
+ warn('An obfuscation replacement rule contains a "regex" value with an invalid type (must be a string or RegExp)')
60
+ invalidRegexDetected = true
61
+ }
62
+
63
+ var replacement = rules[i].replacement
64
+ if (replacement) {
65
+ if (typeof replacement !== 'string') {
66
+ warn('An obfuscation replacement rule contains a "replacement" value with an invalid type (must be a string)')
67
+ invalidReplacementDetected = true
68
+ }
69
+ }
70
+ }
71
+
72
+ return !invalidReplacementDetected && !invalidRegexDetected
73
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ export function sHash (s) {
7
+ var i
8
+ var h = 0
9
+
10
+ for (i = 0; i < s.length; i++) {
11
+ h += ((i + 1) * s.charCodeAt(i))
12
+ }
13
+ return Math.abs(h)
14
+ }
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import slice from 'lodash._slice'
7
+
8
+ export function single (fn) {
9
+ var called = false
10
+ var res
11
+
12
+ return function () {
13
+ if (called) return res
14
+ called = true
15
+ res = fn.apply(this, slice(arguments))
16
+ return res
17
+ }
18
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { ee } from '../event-emitter/contextual-ee'
7
+
8
+ /**
9
+ * Returns a function for use as a replacer parameter in JSON.stringify() to handle circular references.
10
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value MDN - Cyclical object value}
11
+ * @returns {Function} A function that filters out values it has seen before.
12
+ */
13
+ const getCircularReplacer = () => {
14
+ const seen = new WeakSet()
15
+ return (key, value) => {
16
+ if (typeof value === 'object' && value !== null) {
17
+ if (seen.has(value)) {
18
+ return
19
+ }
20
+ seen.add(value)
21
+ }
22
+ return value
23
+ }
24
+ }
25
+
26
+ /**
27
+ * The native JSON.stringify method augmented with a replacer function to handle circular references.
28
+ * Circular references will be excluded from the JSON output rather than triggering errors.
29
+ * @param {*} val - A value to be converted to a JSON string.
30
+ * @returns {string} A JSON string representation of the value, with circular references handled.
31
+ */
32
+ export function stringify (val) {
33
+ try {
34
+ return JSON.stringify(val, getCircularReplacer())
35
+ } catch (e) {
36
+ try {
37
+ ee.emit('internal-error', [e])
38
+ } catch (err) {
39
+ // do nothing
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { isWorkerScope } from './global-scope'
6
+ export const submitData = {}
7
+
8
+ /**
9
+ * Send via JSONP. Do NOT call this function outside of a guaranteed web window environment.
10
+ * @param {string} url
11
+ * @param {string} jsonp
12
+ * @returns {Element}
13
+ */
14
+ submitData.jsonp = function jsonp (url, jsonp) {
15
+ try {
16
+ if (isWorkerScope) {
17
+ try {
18
+ return importScripts(url + '&jsonp=' + jsonp)
19
+ } catch (e) {
20
+ // for now theres no other way to execute the callback from ingest without jsonp, or unsafe eval / new Function calls
21
+ // future work needs to be conducted to allow ingest to return a more traditional JSON API-like experience for the entitlement flags
22
+ submitData.xhrGet(url + '&jsonp=' + jsonp)
23
+ return false
24
+ }
25
+ } else {
26
+ var element = document.createElement('script')
27
+ element.type = 'text/javascript'
28
+ element.src = url + '&jsonp=' + jsonp
29
+ var firstScript = document.getElementsByTagName('script')[0]
30
+ firstScript.parentNode.insertBefore(element, firstScript)
31
+ return element
32
+ }
33
+ } catch (err) {
34
+ // do nothing
35
+ }
36
+ }
37
+
38
+ submitData.xhrGet = function xhrGet (url) {
39
+ return submitData.xhr(url, undefined, false, 'GET')
40
+ }
41
+
42
+ /**
43
+ * Send via XHR
44
+ * @param {string} url
45
+ * @param {string} body
46
+ * @param {boolean} sync
47
+ * @returns {XMLHttpRequest}
48
+ */
49
+ submitData.xhr = function xhr (url, body, sync, method = 'POST') {
50
+ var request = new XMLHttpRequest()
51
+
52
+ request.open(method, url, !sync)
53
+ try {
54
+ // Set cookie
55
+ if ('withCredentials' in request) request.withCredentials = true
56
+ } catch (e) {
57
+ // do nothing
58
+ }
59
+
60
+ request.setRequestHeader('content-type', 'text/plain')
61
+ request.send(body)
62
+ return request
63
+ }
64
+
65
+ /**
66
+ * Unused at the moment -- DEPRECATED
67
+ */
68
+ // submitData.xhrSync = function xhrSync (url, body) {
69
+ // return submitData.xhr(url, body, true)
70
+ // }
71
+
72
+ /**
73
+ * Send by appending an <img> element to the page. Do NOT call this function outside of a guaranteed web window environment.
74
+ * @param {string} url
75
+ * @returns {Element}
76
+ */
77
+ submitData.img = function img (url) {
78
+ var element = new Image()
79
+ element.src = url
80
+ return element
81
+ }
82
+
83
+ /**
84
+ * Send via sendBeacon. Do NOT call this function outside of a guaranteed web window environment.
85
+ * @param {string} url
86
+ * @param {string} body
87
+ * @returns {boolean}
88
+ */
89
+ submitData.beacon = function (url, body) {
90
+ // Navigator has to be bound to ensure it does not error in some browsers
91
+ // https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
92
+ const send = window.navigator.sendBeacon.bind(window.navigator)
93
+ try {
94
+ return send(url, body)
95
+ } catch (err) {
96
+ // if sendBeacon still trys to throw an illegal invocation error,
97
+ // we can catch here and return. The harvest module will fallback to use
98
+ // .img to try to send
99
+ return false
100
+ }
101
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ // traverses an object and applies a fn to property values of a certain type
7
+ export function applyFnToProps (obj, fn, type, ignoreKeys) {
8
+ if (!obj || typeof obj !== 'object') return obj
9
+ type = type || 'string'
10
+ ignoreKeys = ignoreKeys || []
11
+ return traverse(obj)
12
+ function traverse (obj) {
13
+ for (var property in obj) {
14
+ // eslint-disable-next-line
15
+ if (obj.hasOwnProperty(property)) {
16
+ if (typeof obj[property] === 'object') {
17
+ traverse(obj[property])
18
+ } else {
19
+ if (typeof obj[property] === type && !shouldIgnore(property)) obj[property] = fn(obj[property])
20
+ }
21
+ }
22
+ }
23
+ return obj
24
+ }
25
+
26
+ function shouldIgnore (key) {
27
+ var ignore = false
28
+ for (var i = 0; i < ignoreKeys.length; i++) {
29
+ if (ignoreKeys[i] === key) {
30
+ ignore = true
31
+ break
32
+ }
33
+ }
34
+ return ignore
35
+ }
36
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ // Feature-detection is much preferred over using User Agent to detect browser.
7
+ // However, there are cases where feature detection is not possible, for example
8
+ // when a specific version of a browser has a bug that requires a workaround in just
9
+ // that version.
10
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#Browser_Name
11
+ var agentName = null
12
+ var agentVersion = null
13
+ const safari = /Version\/(\S+)\s+Safari/
14
+
15
+ if (navigator.userAgent) {
16
+ var userAgent = navigator.userAgent
17
+ var parts = userAgent.match(safari)
18
+
19
+ if (parts && userAgent.indexOf('Chrome') === -1 &&
20
+ userAgent.indexOf('Chromium') === -1) {
21
+ agentName = 'Safari'
22
+ agentVersion = parts[1]
23
+ }
24
+ }
25
+
26
+ export { agentName as agent, agentVersion as version }
27
+
28
+ export function match (name, version) {
29
+ if (!agentName) {
30
+ return false
31
+ }
32
+
33
+ if (name !== agentName) {
34
+ return false
35
+ }
36
+
37
+ // version not provided, only match by name
38
+ if (!version) {
39
+ return true
40
+ }
41
+
42
+ // version provided, but not detected - not reliable match
43
+ if (!agentVersion) {
44
+ return false
45
+ }
46
+
47
+ var detectedParts = agentVersion.split('.')
48
+ var requestedParts = version.split('.')
49
+ for (var i = 0; i < requestedParts.length; i++) {
50
+ if (requestedParts[i] !== detectedParts[i]) {
51
+ return false
52
+ }
53
+ }
54
+
55
+ return true
56
+ }
@@ -0,0 +1,15 @@
1
+ import { windowAddEventListener, documentAddEventListener } from '../event-listener/event-listener-opts'
2
+
3
+ function checkState () {
4
+ return (typeof document === 'undefined' || document.readyState === 'complete')
5
+ }
6
+
7
+ export function onWindowLoad (cb, useCapture) {
8
+ if (checkState()) return cb()
9
+ windowAddEventListener('load', cb, useCapture)
10
+ }
11
+
12
+ export function onDOMContentLoaded (cb) {
13
+ if (checkState()) return cb()
14
+ documentAddEventListener('DOMContentLoaded', cb)
15
+ }
@@ -0,0 +1,110 @@
1
+
2
+ import { now } from '../timing/now'
3
+ import { globalScope } from '../util/global-scope'
4
+
5
+ export const defaults = {
6
+ beacon: 'bam.nr-data.net',
7
+ errorBeacon: 'bam.nr-data.net'
8
+ }
9
+
10
+ export function gosNREUM () {
11
+ if (!globalScope.NREUM) {
12
+ globalScope.NREUM = {}
13
+ }
14
+ if (typeof globalScope.newrelic === 'undefined') globalScope.newrelic = globalScope.NREUM
15
+ return globalScope.NREUM
16
+ }
17
+
18
+ export function gosNREUMInfo () {
19
+ let nr = gosNREUM()
20
+ const externallySupplied = nr.info || {}
21
+
22
+ nr.info = {
23
+ beacon: defaults.beacon,
24
+ errorBeacon: defaults.errorBeacon,
25
+ ...externallySupplied
26
+ }
27
+
28
+ return nr
29
+ }
30
+
31
+ export function gosNREUMLoaderConfig () {
32
+ let nr = gosNREUM()
33
+ const externallySupplied = nr.loader_config || {}
34
+
35
+ nr.loader_config = {
36
+ ...externallySupplied
37
+ }
38
+
39
+ return nr
40
+ }
41
+
42
+ export function gosNREUMInit () {
43
+ let nr = gosNREUM()
44
+ const externallySupplied = nr.init || {}
45
+
46
+ nr.init = {
47
+ ...externallySupplied
48
+ }
49
+
50
+ return nr
51
+ }
52
+
53
+ export function gosNREUMOriginals () {
54
+ let nr = gosNREUM()
55
+ if (!nr.o) {
56
+ nr.o = {
57
+ ST: globalScope.setTimeout,
58
+ SI: globalScope.setImmediate,
59
+ CT: globalScope.clearTimeout,
60
+ XHR: globalScope.XMLHttpRequest,
61
+ REQ: globalScope.Request,
62
+ EV: globalScope.Event,
63
+ PR: globalScope.Promise,
64
+ MO: globalScope.MutationObserver, // this'll be undefined if not in a web window
65
+ FETCH: globalScope.fetch
66
+ }
67
+ }
68
+ return nr
69
+ }
70
+
71
+ export function gosNREUMInitializedAgents (id, obj, target) {
72
+ let nr = gosNREUM()
73
+ const externallySupplied = nr.initializedAgents || {}
74
+ const curr = externallySupplied[id] || {}
75
+
76
+ if (!Object.keys(curr).length) {
77
+ curr.initializedAt = {
78
+ ms: now(),
79
+ date: new Date()
80
+ }
81
+ }
82
+
83
+ nr.initializedAgents = {
84
+ ...externallySupplied,
85
+ [id]: {
86
+ ...curr,
87
+ [target]: obj
88
+ }
89
+ }
90
+
91
+ return nr
92
+ }
93
+
94
+ export function addToNREUM (fnName, fn) {
95
+ let nr = gosNREUM()
96
+ nr[fnName] = fn
97
+ }
98
+
99
+ export function NREUMinitialized () {
100
+ const nr = gosNREUM()
101
+ nr.initialized = true
102
+ }
103
+
104
+ export function gosCDN () {
105
+ gosNREUMInfo()
106
+ gosNREUMInit()
107
+ gosNREUMOriginals()
108
+ gosNREUMLoaderConfig()
109
+ return gosNREUM()
110
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { documentAddEventListener } from '../event-listener/event-listener-opts'
7
+
8
+ /**
9
+ * @param {function} cb - called when a visibility change occurs with the vis state at that time
10
+ * @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
11
+ * @returns void
12
+ */
13
+ export function subscribeToVisibilityChange (cb, toHiddenOnly = false) {
14
+ documentAddEventListener('visibilitychange', handleVisibilityChange)
15
+ return
16
+
17
+ function handleVisibilityChange () {
18
+ if (toHiddenOnly) { // trigger cb on change to hidden state only
19
+ if (document.visibilityState == 'hidden') cb()
20
+ else return
21
+ }
22
+ cb(document.visibilityState)
23
+ }
24
+ }