@newrelic/browser-agent 1.237.1 → 1.239.0

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 (307) hide show
  1. package/dist/cjs/common/config/state/init.js +21 -13
  2. package/dist/cjs/common/config/state/runtime.js +0 -4
  3. package/dist/cjs/common/constants/env.cdn.js +1 -1
  4. package/dist/cjs/common/constants/env.npm.js +1 -1
  5. package/dist/cjs/common/constants/runtime.js +3 -3
  6. package/dist/cjs/common/constants/shared-channel.js +3 -1
  7. package/dist/cjs/common/deny-list/deny-list.js +3 -9
  8. package/dist/cjs/common/drain/drain.js +1 -1
  9. package/dist/cjs/common/event-emitter/contextual-ee.js +24 -32
  10. package/dist/cjs/common/event-emitter/event-context.js +12 -0
  11. package/dist/cjs/common/harvest/harvest-scheduler.js +2 -4
  12. package/dist/cjs/common/harvest/harvest.js +4 -7
  13. package/dist/cjs/common/ids/bundle-id.js +19 -0
  14. package/dist/cjs/common/serialize/bel-serializer.js +1 -1
  15. package/dist/cjs/common/session/session-entity.js +16 -12
  16. package/dist/cjs/common/storage/first-party-cookies.js +5 -4
  17. package/dist/cjs/common/storage/local-storage.js +3 -2
  18. package/dist/cjs/common/timer/interaction-timer.js +14 -6
  19. package/dist/cjs/common/timing/nav-timing.js +1 -1
  20. package/dist/cjs/common/unload/eol.js +4 -30
  21. package/dist/cjs/common/util/feature-flags.js +14 -15
  22. package/dist/cjs/common/util/invoke.js +3 -1
  23. package/dist/cjs/common/util/obfuscate.js +3 -5
  24. package/dist/cjs/common/util/traverse.js +1 -0
  25. package/dist/cjs/common/window/page-visibility.js +1 -2
  26. package/dist/cjs/common/wrap/wrap-events.js +3 -2
  27. package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
  28. package/dist/cjs/common/wrap/wrap-function.js +15 -46
  29. package/dist/cjs/common/wrap/wrap-jsonp.js +1 -1
  30. package/dist/cjs/common/wrap/wrap-mutation.js +1 -2
  31. package/dist/cjs/common/wrap/wrap-promise.js +2 -3
  32. package/dist/cjs/common/wrap/wrap-xhr.js +23 -27
  33. package/dist/cjs/features/ajax/aggregate/index.js +5 -7
  34. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +8 -12
  35. package/dist/cjs/features/ajax/instrument/index.js +66 -24
  36. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +0 -1
  37. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +4 -4
  38. package/dist/cjs/features/jserrors/aggregate/index.js +4 -5
  39. package/dist/cjs/features/metrics/aggregate/framework-detection.js +103 -7
  40. package/dist/cjs/features/metrics/aggregate/index.js +20 -37
  41. package/dist/cjs/features/metrics/instrument/index.js +0 -2
  42. package/dist/cjs/features/page_action/aggregate/index.js +17 -19
  43. package/dist/cjs/features/page_view_event/aggregate/index.js +1 -2
  44. package/dist/cjs/features/page_view_event/instrument/index.js +4 -2
  45. package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -7
  46. package/dist/cjs/features/session_replay/aggregate/index.js +5 -3
  47. package/dist/cjs/features/session_trace/aggregate/index.js +22 -16
  48. package/dist/cjs/features/spa/aggregate/index.js +14 -20
  49. package/dist/cjs/features/spa/aggregate/interaction.js +0 -2
  50. package/dist/cjs/features/spa/aggregate/serializer.js +1 -1
  51. package/dist/cjs/features/utils/aggregate-base.js +4 -0
  52. package/dist/cjs/features/utils/handler-cache.js +3 -1
  53. package/dist/cjs/features/utils/instrument-base.js +24 -6
  54. package/dist/cjs/loaders/agent-base.js +23 -0
  55. package/dist/cjs/loaders/agent.js +7 -7
  56. package/dist/cjs/loaders/api/api.js +34 -4
  57. package/dist/cjs/loaders/api/apiAsync.js +19 -20
  58. package/dist/cjs/loaders/api/interaction-types.js +11 -4
  59. package/dist/cjs/loaders/configure/configure.js +3 -0
  60. package/dist/cjs/loaders/micro-agent.js +20 -3
  61. package/dist/esm/common/config/state/init.js +21 -13
  62. package/dist/esm/common/config/state/runtime.js +0 -4
  63. package/dist/esm/common/constants/env.cdn.js +1 -1
  64. package/dist/esm/common/constants/env.npm.js +1 -1
  65. package/dist/esm/common/constants/runtime.js +1 -1
  66. package/dist/esm/common/constants/shared-channel.js +3 -1
  67. package/dist/esm/common/deny-list/deny-list.js +3 -9
  68. package/dist/esm/common/drain/drain.js +1 -1
  69. package/dist/esm/common/event-emitter/contextual-ee.js +22 -29
  70. package/dist/esm/common/event-emitter/event-context.js +5 -0
  71. package/dist/esm/common/harvest/harvest-scheduler.js +2 -4
  72. package/dist/esm/common/harvest/harvest.js +4 -7
  73. package/dist/esm/common/ids/bundle-id.js +13 -0
  74. package/dist/esm/common/serialize/bel-serializer.js +1 -1
  75. package/dist/esm/common/session/session-entity.js +16 -12
  76. package/dist/esm/common/storage/first-party-cookies.js +5 -4
  77. package/dist/esm/common/storage/local-storage.js +3 -2
  78. package/dist/esm/common/timer/interaction-timer.js +14 -6
  79. package/dist/esm/common/timing/nav-timing.js +1 -1
  80. package/dist/esm/common/unload/eol.js +5 -31
  81. package/dist/esm/common/util/feature-flags.js +14 -15
  82. package/dist/esm/common/util/invoke.js +3 -1
  83. package/dist/esm/common/util/obfuscate.js +3 -5
  84. package/dist/esm/common/util/traverse.js +1 -0
  85. package/dist/esm/common/window/page-visibility.js +1 -2
  86. package/dist/esm/common/wrap/wrap-events.js +4 -3
  87. package/dist/esm/common/wrap/wrap-fetch.js +2 -4
  88. package/dist/esm/common/wrap/wrap-function.js +15 -44
  89. package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
  90. package/dist/esm/common/wrap/wrap-mutation.js +2 -3
  91. package/dist/esm/common/wrap/wrap-promise.js +3 -4
  92. package/dist/esm/common/wrap/wrap-xhr.js +23 -27
  93. package/dist/esm/features/ajax/aggregate/index.js +5 -7
  94. package/dist/esm/features/ajax/instrument/distributed-tracing.js +8 -12
  95. package/dist/esm/features/ajax/instrument/index.js +67 -25
  96. package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +0 -1
  97. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +4 -4
  98. package/dist/esm/features/jserrors/aggregate/index.js +4 -5
  99. package/dist/esm/features/metrics/aggregate/framework-detection.js +103 -7
  100. package/dist/esm/features/metrics/aggregate/index.js +22 -39
  101. package/dist/esm/features/metrics/instrument/index.js +1 -3
  102. package/dist/esm/features/page_action/aggregate/index.js +17 -19
  103. package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
  104. package/dist/esm/features/page_view_event/instrument/index.js +4 -2
  105. package/dist/esm/features/page_view_timing/aggregate/index.js +7 -8
  106. package/dist/esm/features/session_replay/aggregate/index.js +4 -2
  107. package/dist/esm/features/session_trace/aggregate/index.js +22 -16
  108. package/dist/esm/features/spa/aggregate/index.js +14 -20
  109. package/dist/esm/features/spa/aggregate/interaction.js +0 -2
  110. package/dist/esm/features/spa/aggregate/serializer.js +1 -1
  111. package/dist/esm/features/utils/aggregate-base.js +4 -0
  112. package/dist/esm/features/utils/handler-cache.js +3 -1
  113. package/dist/esm/features/utils/instrument-base.js +24 -6
  114. package/dist/esm/loaders/agent-base.js +23 -0
  115. package/dist/esm/loaders/agent.js +7 -7
  116. package/dist/esm/loaders/api/api.js +34 -4
  117. package/dist/esm/loaders/api/apiAsync.js +19 -20
  118. package/dist/esm/loaders/api/interaction-types.js +11 -4
  119. package/dist/esm/loaders/configure/configure.js +3 -0
  120. package/dist/esm/loaders/features/enabled-features.js +1 -1
  121. package/dist/esm/loaders/micro-agent.js +21 -4
  122. package/dist/types/common/config/state/init.d.ts.map +1 -1
  123. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  124. package/dist/types/common/constants/runtime.d.ts +1 -1
  125. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  126. package/dist/types/common/event-emitter/contextual-ee.d.ts +22 -2
  127. package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -1
  128. package/dist/types/common/event-emitter/event-context.d.ts +5 -0
  129. package/dist/types/common/event-emitter/event-context.d.ts.map +1 -0
  130. package/dist/types/common/event-emitter/register-handler.d.ts +1 -1
  131. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  132. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  133. package/dist/types/common/ids/bundle-id.d.ts +5 -0
  134. package/dist/types/common/ids/bundle-id.d.ts.map +1 -0
  135. package/dist/types/common/session/session-entity.d.ts +12 -15
  136. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  137. package/dist/types/common/storage/first-party-cookies.d.ts +1 -1
  138. package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -1
  139. package/dist/types/common/storage/local-storage.d.ts.map +1 -1
  140. package/dist/types/common/timer/interaction-timer.d.ts +3 -0
  141. package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
  142. package/dist/types/common/unload/eol.d.ts +1 -2
  143. package/dist/types/common/unload/eol.d.ts.map +1 -1
  144. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  145. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  146. package/dist/types/common/util/traverse.d.ts.map +1 -1
  147. package/dist/types/common/window/nreum.d.ts +2 -2
  148. package/dist/types/common/window/page-visibility.d.ts.map +1 -1
  149. package/dist/types/common/wrap/wrap-events.d.ts.map +1 -1
  150. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  151. package/dist/types/common/wrap/wrap-function.d.ts +1 -19
  152. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
  153. package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
  154. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  155. package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
  156. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  157. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +1 -1
  158. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -1
  159. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  160. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
  161. package/dist/types/features/jserrors/aggregate/index.d.ts +1 -1
  162. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  163. package/dist/types/features/metrics/aggregate/framework-detection.d.ts.map +1 -1
  164. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  165. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  166. package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
  167. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  168. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  169. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  170. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  171. package/dist/types/features/session_trace/aggregate/index.d.ts +5 -0
  172. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  173. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  174. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  175. package/dist/types/features/utils/aggregate-base.d.ts +1 -0
  176. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  177. package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
  178. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  179. package/dist/types/loaders/agent-base.d.ts +15 -0
  180. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  181. package/dist/types/loaders/agent.d.ts +1 -1
  182. package/dist/types/loaders/agent.d.ts.map +1 -1
  183. package/dist/types/loaders/api/api.d.ts +7 -0
  184. package/dist/types/loaders/api/api.d.ts.map +1 -1
  185. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
  186. package/dist/types/loaders/api/interaction-types.d.ts +18 -7
  187. package/dist/types/loaders/api/interaction-types.d.ts.map +1 -1
  188. package/dist/types/loaders/configure/configure.d.ts +2 -0
  189. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  190. package/dist/types/loaders/features/features.d.ts +9 -9
  191. package/dist/types/loaders/micro-agent.d.ts +7 -1
  192. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  193. package/package.json +62 -38
  194. package/src/common/aggregate/aggregator.test.js +107 -0
  195. package/src/common/config/state/configurable.test.js +73 -0
  196. package/src/common/config/state/info.test.js +31 -0
  197. package/src/common/config/state/init.js +13 -12
  198. package/src/common/config/state/init.test.js +28 -0
  199. package/src/common/config/state/loader-config.test.js +21 -0
  200. package/src/common/config/state/runtime.js +0 -2
  201. package/src/common/config/state/runtime.test.js +21 -0
  202. package/src/common/constants/__mocks__/runtime.js +1 -1
  203. package/src/common/constants/runtime.js +1 -1
  204. package/src/common/constants/runtime.test.js +2 -2
  205. package/src/common/constants/shared-channel.js +1 -1
  206. package/src/common/deny-list/deny-list.js +3 -11
  207. package/src/common/deny-list/deny-list.test.js +103 -30
  208. package/src/common/drain/drain.js +1 -1
  209. package/src/common/drain/drain.test.js +74 -0
  210. package/src/common/event-emitter/{contextual-ee.test.js → contextual-ee.component-test.js} +15 -32
  211. package/src/common/event-emitter/contextual-ee.js +26 -37
  212. package/src/common/event-emitter/event-context.js +5 -0
  213. package/src/common/harvest/harvest-scheduler.js +2 -5
  214. package/src/common/harvest/harvest-scheduler.test.js +2 -6
  215. package/src/common/harvest/harvest.js +4 -7
  216. package/src/common/harvest/harvest.test.js +1 -3
  217. package/src/common/ids/__mocks__/bundle-id.js +2 -0
  218. package/src/common/ids/__mocks__/unique-id.js +17 -0
  219. package/src/common/ids/bundle-id.js +13 -0
  220. package/src/common/ids/id.test.js +6 -6
  221. package/src/common/serialize/bel-serializer.js +1 -1
  222. package/src/common/session/session-entity.component-test.js +3 -2
  223. package/src/common/session/session-entity.js +11 -9
  224. package/src/common/storage/first-party-cookies.js +5 -4
  225. package/src/common/storage/local-storage.js +3 -2
  226. package/src/common/timer/interaction-timer.component-test.js +52 -7
  227. package/src/common/timer/interaction-timer.js +15 -6
  228. package/src/common/timer/timer.test.js +0 -1
  229. package/src/common/timing/nav-timing.js +1 -1
  230. package/src/common/unload/eol.js +5 -31
  231. package/src/common/url/__mocks__/parse-url.js +15 -0
  232. package/src/common/url/{encode.component-test.js → encode.test.js} +1 -0
  233. package/src/common/util/__mocks__/get-or-set.js +5 -0
  234. package/src/common/util/__mocks__/invoke.js +1 -0
  235. package/src/common/util/data-size.test.js +0 -1
  236. package/src/common/util/feature-flags.js +15 -17
  237. package/src/common/util/feature-flags.test.js +4 -8
  238. package/src/common/util/invoke.js +1 -1
  239. package/src/common/util/obfuscate.js +3 -5
  240. package/src/common/util/submit-data.test.js +1 -1
  241. package/src/common/util/traverse.js +1 -0
  242. package/src/common/window/__mocks__/nreum.js +12 -0
  243. package/src/common/window/page-visibility.js +1 -2
  244. package/src/common/wrap/wrap-events.js +4 -3
  245. package/src/common/wrap/wrap-fetch.js +2 -4
  246. package/src/common/wrap/wrap-function.js +16 -44
  247. package/src/common/wrap/wrap-jsonp.js +1 -1
  248. package/src/common/wrap/wrap-mutation.js +2 -3
  249. package/src/common/wrap/{wrap-promise.test.js → wrap-promise.component-test.js} +2 -32
  250. package/src/common/wrap/wrap-promise.js +3 -4
  251. package/src/common/wrap/wrap-xhr.js +24 -28
  252. package/src/features/ajax/aggregate/index.js +5 -7
  253. package/src/features/ajax/instrument/distributed-tracing.js +8 -12
  254. package/src/features/ajax/instrument/distributed-tracing.test.js +375 -0
  255. package/src/features/ajax/instrument/index.js +62 -27
  256. package/src/features/jserrors/aggregate/canonical-function-name.js +0 -2
  257. package/src/features/jserrors/aggregate/compute-stack-trace.js +4 -4
  258. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
  259. package/src/features/jserrors/aggregate/index.js +4 -5
  260. package/src/features/metrics/aggregate/framework-detection.js +129 -8
  261. package/src/features/metrics/aggregate/framework-detection.test.js +213 -82
  262. package/src/features/metrics/aggregate/index.js +22 -45
  263. package/src/features/metrics/instrument/index.js +1 -3
  264. package/src/features/page_action/aggregate/index.js +12 -13
  265. package/src/features/page_view_event/aggregate/index.js +1 -2
  266. package/src/features/page_view_event/instrument/index.js +2 -2
  267. package/src/features/page_view_timing/aggregate/index.js +7 -8
  268. package/src/features/session_replay/aggregate/index.component-test.js +3 -15
  269. package/src/features/session_replay/aggregate/index.js +4 -2
  270. package/src/features/session_trace/aggregate/index.js +22 -16
  271. package/src/features/spa/aggregate/index.js +14 -20
  272. package/src/features/spa/aggregate/interaction.js +0 -2
  273. package/src/features/spa/aggregate/serializer.js +1 -1
  274. package/src/features/utils/aggregate-base.js +5 -0
  275. package/src/features/utils/aggregate-base.test.js +2 -1
  276. package/src/features/utils/handler-cache.js +3 -2
  277. package/src/features/utils/instrument-base.js +25 -6
  278. package/src/features/utils/instrument-base.test.js +2 -2
  279. package/src/loaders/agent-base.js +23 -0
  280. package/src/loaders/agent.js +7 -7
  281. package/src/loaders/api/api.component-test.js +45 -0
  282. package/src/loaders/api/api.js +34 -4
  283. package/src/loaders/api/api.test.js +85 -0
  284. package/src/loaders/api/apiAsync.js +19 -20
  285. package/src/loaders/api/apiAsync.test.js +17 -0
  286. package/src/loaders/api/interaction-types.js +11 -4
  287. package/src/loaders/configure/configure.js +3 -0
  288. package/src/loaders/features/enabled-features.js +1 -1
  289. package/src/loaders/micro-agent.js +22 -4
  290. package/dist/cjs/features/metrics/aggregate/endpoint-map.js +0 -14
  291. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.js +0 -14
  292. package/dist/cjs/features/metrics/aggregate/polyfill-detection.js +0 -53
  293. package/dist/esm/features/metrics/aggregate/endpoint-map.js +0 -7
  294. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
  295. package/dist/esm/features/metrics/aggregate/polyfill-detection.js +0 -47
  296. package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +0 -8
  297. package/dist/types/features/metrics/aggregate/endpoint-map.d.ts.map +0 -1
  298. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts +0 -6
  299. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts.map +0 -1
  300. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts +0 -7
  301. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +0 -1
  302. package/src/features/metrics/aggregate/endpoint-map.js +0 -7
  303. package/src/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
  304. package/src/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -16
  305. package/src/features/metrics/aggregate/polyfill-detection.js +0 -48
  306. package/src/features/metrics/aggregate/polyfill-detection.test.js +0 -163
  307. /package/src/common/url/{protocol.component-test.js → protocol.test.js} +0 -0
@@ -5,7 +5,9 @@
5
5
  */
6
6
 
7
7
  let onReplayReady;
8
- const sessionReplayInitialized = new Promise(resolve => onReplayReady = resolve);
8
+ const sessionReplayInitialized = new Promise(resolve => {
9
+ onReplayReady = resolve;
10
+ });
9
11
  export const sharedChannel = Object.freeze({
10
12
  onReplayReady,
11
13
  sessionReplayInitialized
@@ -57,7 +57,7 @@ export function setDenyList(denyListConfig) {
57
57
  host = url;
58
58
  pathname = '';
59
59
  }
60
- let [hostname, port] = host.split(':');
60
+ let [hostname] = host.split(':');
61
61
  denyList.push({
62
62
  hostname,
63
63
  pathname
@@ -74,10 +74,7 @@ function domainMatchesPattern(pattern, domain) {
74
74
  if (pattern.length > domain.length) {
75
75
  return false;
76
76
  }
77
- if (domain.indexOf(pattern) === domain.length - pattern.length) {
78
- return true;
79
- }
80
- return false;
77
+ return domain.indexOf(pattern) === domain.length - pattern.length;
81
78
  }
82
79
 
83
80
  /**
@@ -98,8 +95,5 @@ function comparePath(pattern, path) {
98
95
  if (pattern === '') {
99
96
  return true;
100
97
  }
101
- if (pattern === path) {
102
- return true;
103
- }
104
- return false;
98
+ return pattern === path;
105
99
  }
@@ -48,7 +48,6 @@ export function drain() {
48
48
  let agentIdentifier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
49
49
  let featureName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'feature';
50
50
  curateRegistry(agentIdentifier);
51
-
52
51
  // If the feature for the specified agent is not in the registry, that means the instrument file was bypassed.
53
52
  // This could happen in tests, or loaders that directly import the aggregator. In these cases it is safe to
54
53
  // drain the feature group immediately rather than waiting to drain all at once.
@@ -67,6 +66,7 @@ export function drain() {
67
66
  items.sort((a, b) => a[1].priority - b[1].priority);
68
67
  items.forEach(_ref2 => {
69
68
  let [group] = _ref2;
69
+ registry[agentIdentifier].delete(group);
70
70
  drainGroup(group);
71
71
  });
72
72
  }
@@ -5,21 +5,21 @@
5
5
 
6
6
  import { gosNREUM } from '../window/nreum';
7
7
  import { getOrSet } from '../util/get-or-set';
8
- import { mapOwn } from '../util/map-own';
9
8
  import { getRuntime } from '../config/config';
10
- var ctxId = 'nr@context';
9
+ import { EventContext } from './event-context';
10
+ import { bundleId } from '../ids/bundle-id';
11
11
 
12
+ // create a unique id to store event context data for the current agent bundle
13
+ const contextId = "nr@context:".concat(bundleId);
12
14
  // create global emitter instance that can be shared among bundles
13
- let nr = gosNREUM();
14
- var globalInstance;
15
- if (nr.ee) {
16
- globalInstance = nr.ee;
17
- } else {
18
- globalInstance = ee(undefined, 'globalEE');
15
+ const globalInstance = ee(undefined, 'globalEE');
16
+
17
+ // Only override the exposed event emitter if one has not already been exposed
18
+ const nr = gosNREUM();
19
+ if (!nr.ee) {
19
20
  nr.ee = globalInstance;
20
21
  }
21
- export { globalInstance as ee };
22
- function EventContext() {}
22
+ export { globalInstance as ee, contextId };
23
23
  function ee(old, debugId) {
24
24
  var handlers = {};
25
25
  var bufferGroupMap = {};
@@ -38,16 +38,16 @@ function ee(old, debugId) {
38
38
  }
39
39
  var emitter = {
40
40
  on: addEventListener,
41
- addEventListener: addEventListener,
42
- removeEventListener: removeEventListener,
43
- emit: emit,
41
+ addEventListener,
42
+ removeEventListener,
43
+ emit,
44
44
  get: getOrCreate,
45
- listeners: listeners,
46
- context: context,
45
+ listeners,
46
+ context,
47
47
  buffer: bufferEventsByGroup,
48
48
  abort,
49
49
  aborted: false,
50
- isBuffering: isBuffering,
50
+ isBuffering,
51
51
  debugId,
52
52
  backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {}
53
53
  };
@@ -56,9 +56,9 @@ function ee(old, debugId) {
56
56
  if (contextOrStore && contextOrStore instanceof EventContext) {
57
57
  return contextOrStore;
58
58
  } else if (contextOrStore) {
59
- return getOrSet(contextOrStore, ctxId, getNewContext);
59
+ return getOrSet(contextOrStore, contextId, () => new EventContext(contextId));
60
60
  } else {
61
- return getNewContext();
61
+ return new EventContext(contextId);
62
62
  }
63
63
  }
64
64
  function emit(type, args, contextOrStore, force, bubble) {
@@ -105,12 +105,13 @@ function ee(old, debugId) {
105
105
  return emitters[name] = emitters[name] || ee(emitter, name);
106
106
  }
107
107
  function bufferEventsByGroup(types, group) {
108
- var eventBuffer = getBuffer();
108
+ const eventBuffer = getBuffer();
109
+ group = group || 'feature';
109
110
 
110
111
  // do not buffer events if agent has been aborted
111
112
  if (emitter.aborted) return;
112
- mapOwn(types, function (i, type) {
113
- group = group || 'feature';
113
+ Object.entries(types || {}).forEach(_ref => {
114
+ let [_, type] = _ref;
114
115
  bufferGroupMap[type] = group;
115
116
  if (!(group in eventBuffer)) {
116
117
  eventBuffer[group] = [];
@@ -128,14 +129,6 @@ function ee(old, debugId) {
128
129
  return emitter.backlog;
129
130
  }
130
131
  }
131
-
132
- // get context object from store object, or create if does not exist
133
- export function getOrSetContext(obj) {
134
- return getOrSet(obj, ctxId, getNewContext);
135
- }
136
- function getNewContext() {
137
- return new EventContext();
138
- }
139
132
  function abort() {
140
133
  globalInstance.aborted = true;
141
134
  globalInstance.backlog = {};
@@ -0,0 +1,5 @@
1
+ export class EventContext {
2
+ constructor(contextId) {
3
+ this.contextId = contextId;
4
+ }
5
+ }
@@ -7,7 +7,6 @@ import * as submitData from '../util/submit-data';
7
7
  import { SharedContext } from '../context/shared-context';
8
8
  import { Harvest } from './harvest';
9
9
  import { subscribeToEOL } from '../unload/eol';
10
- import { getConfigurationValue } from '../config/config';
11
10
  import { SESSION_EVENTS } from '../session/session-entity';
12
11
 
13
12
  /**
@@ -36,7 +35,7 @@ export class HarvestScheduler extends SharedContext {
36
35
  this.harvest = new Harvest(this.sharedContext);
37
36
 
38
37
  // unload if EOL mechanism fires
39
- subscribeToEOL(this.unload.bind(this), getConfigurationValue(this.sharedContext.agentIdentifier, 'allow_bfcache')); // TO DO: remove feature flag after rls stable
38
+ subscribeToEOL(this.unload.bind(this));
40
39
 
41
40
  /* Flush all buffered data if session resets and give up retries. This should be synchronous to ensure that the correct `session` value is sent.
42
41
  Since session-reset generates a new session ID and the ID is grabbed at send-time, any delays or retries would cause the payload to be sent under
@@ -103,7 +102,7 @@ export class HarvestScheduler extends SharedContext {
103
102
  if (!submitMethod) return false;
104
103
  const retry = !opts?.unload && submitMethod === submitData.xhr;
105
104
  payload = this.opts.getPayload({
106
- retry: retry
105
+ retry
107
106
  });
108
107
  if (!payload) {
109
108
  if (this.started) {
@@ -139,7 +138,6 @@ export class HarvestScheduler extends SharedContext {
139
138
  if (this.started) {
140
139
  this.scheduleHarvest();
141
140
  }
142
- return;
143
141
  }
144
142
  onHarvestFinished(opts, result) {
145
143
  if (this.opts.onFinished) {
@@ -48,7 +48,8 @@ export class Harvest extends SharedContext {
48
48
  isFinalHarvest: spec.opts?.unload
49
49
  });
50
50
  const options = {
51
- retry: !spec.opts?.unload && submitMethod === submitData.xhr
51
+ retry: !spec.opts?.unload && submitMethod === submitData.xhr,
52
+ isFinalHarvest: spec.opts?.unload === true
52
53
  };
53
54
  const payload = this.createPayload(spec.endpoint, options);
54
55
  const caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
@@ -122,7 +123,8 @@ export class Harvest extends SharedContext {
122
123
  }
123
124
  return false;
124
125
  }
125
- let url = "".concat(this.getScheme(), "://").concat(info.errorBeacon).concat(endpoint !== 'rum' ? "/".concat(endpoint) : '', "/1/").concat(info.licenseKey);
126
+ const endpointURLPart = endpoint !== 'rum' ? "/".concat(endpoint) : '';
127
+ let url = "".concat(this.getScheme(), "://").concat(info.errorBeacon).concat(endpointURLPart, "/1/").concat(info.licenseKey);
126
128
  if (customUrl) url = customUrl;
127
129
  if (raw) url = "".concat(this.getScheme(), "://").concat(info.errorBeacon, "/").concat(endpoint);
128
130
  const baseParams = !raw && includeBaseParams ? this.baseQueryString() : '';
@@ -150,11 +152,6 @@ export class Harvest extends SharedContext {
150
152
  // If body is null, undefined, or an empty object or array, send an empty string instead
151
153
  body = '';
152
154
  }
153
-
154
- // Get bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
155
- agentRuntime.bytesSent[endpoint] = (agentRuntime.bytesSent[endpoint] || 0) + body?.length || 0;
156
- // Get query bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
157
- agentRuntime.queryBytesSent[endpoint] = (agentRuntime.queryBytesSent[endpoint] || 0) + fullUrl.split('?').slice(-1)[0]?.length || 0;
158
155
  const headers = [];
159
156
  headers.push({
160
157
  key: 'content-type',
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file Contains a unique identifier for the running agent bundle
3
+ * when loaded.
4
+ * @copyright 2023 New Relic Corporation. All rights reserved.
5
+ * @license Apache-2.0
6
+ */
7
+
8
+ import { generateUuid } from './unique-id';
9
+
10
+ /**
11
+ * Provides a unique id for the current agent bundle
12
+ */
13
+ export const bundleId = generateUuid();
@@ -25,7 +25,7 @@ export function getAddStringContext(agentIdentifier) {
25
25
  function addString(str) {
26
26
  if (typeof str === 'undefined' || str === '') return '';
27
27
  var obfuscator = new Obfuscator({
28
- agentIdentifier: agentIdentifier
28
+ agentIdentifier
29
29
  });
30
30
  str = String(str);
31
31
  if (obfuscator.shouldObfuscate()) str = obfuscator.obfuscateString(str);
@@ -40,33 +40,37 @@ export class SessionEntity {
40
40
  * expiresMs and inactiveMs are used to "expire" the session, but can be overridden in the constructor. Pass 0 to disable expiration timers.
41
41
  */
42
42
  constructor(opts) {
43
- this.setup(opts);
44
- }
45
- setup(_ref) {
46
- let {
43
+ const {
47
44
  agentIdentifier,
48
45
  key,
49
- storage,
50
- value = generateRandomHexString(16),
51
- expiresMs = DEFAULT_EXPIRES_MS,
52
- inactiveMs = DEFAULT_INACTIVE_MS
53
- } = _ref;
46
+ storage
47
+ } = opts;
54
48
  if (!agentIdentifier || !key || !storage) {
55
49
  throw new Error("Missing required field(s):".concat(!agentIdentifier ? ' agentID' : '').concat(!key ? ' key' : '').concat(!storage ? ' storage' : ''));
56
50
  }
57
51
  this.agentIdentifier = agentIdentifier;
58
52
  this.storage = storage;
59
53
  this.state = {};
60
- this.sync(model);
61
54
 
62
55
  // key is intended to act as the k=v pair
63
56
  this.key = key;
57
+ this.ee = ee.get(agentIdentifier);
58
+ wrapEvents(this.ee);
59
+ this.setup(opts);
60
+ }
61
+ setup(_ref) {
62
+ let {
63
+ value = generateRandomHexString(16),
64
+ expiresMs = DEFAULT_EXPIRES_MS,
65
+ inactiveMs = DEFAULT_INACTIVE_MS
66
+ } = _ref;
67
+ this.state = {};
68
+ this.sync(model);
69
+
64
70
  // value is intended to act as the primary value of the k=v pair
65
71
  this.state.value = value;
66
72
  this.expiresMs = expiresMs;
67
73
  this.inactiveMs = inactiveMs;
68
- this.ee = ee.get(agentIdentifier);
69
- wrapEvents(this.ee);
70
74
 
71
75
  // the first time the session entity class is instantiated, we check the storage API for an existing
72
76
  // object. If it exists, the values inside the object are used to inform the timers that run locally.
@@ -7,22 +7,23 @@ export class FirstPartyCookies {
7
7
  var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
8
8
  if (match) return match[2];
9
9
  } catch (err) {
10
+ // Error is ignored
10
11
  return '';
11
12
  }
12
13
  }
13
14
  set(key, value) {
14
15
  try {
15
- const cookie = "".concat(key, "=").concat(value, "; Domain=").concat(domain, "; Path=/");
16
+ const cookie = "".concat(key, "=").concat(value, "; Domain=").concat(this.domain, "; Path=/");
16
17
  document.cookie = cookie;
17
18
  } catch (err) {
18
- return;
19
+ // Error is ignored
19
20
  }
20
21
  }
21
22
  remove(key) {
22
23
  try {
23
- return document.cookie = "".concat(key, "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; Domain=").concat(domain, "; Path=/");
24
+ document.cookie = "".concat(key, "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; Domain=").concat(this.domain, "; Path=/");
24
25
  } catch (err) {
25
- return;
26
+ // Error is ignored
26
27
  }
27
28
  }
28
29
  }
@@ -5,6 +5,7 @@ export class LocalStorage {
5
5
  // Cast it back to undefined if it doesnt exist
6
6
  return localStorage.getItem(key) || undefined;
7
7
  } catch (err) {
8
+ // Error is ignored
8
9
  return '';
9
10
  }
10
11
  }
@@ -13,14 +14,14 @@ export class LocalStorage {
13
14
  if (value === undefined || value === null) return this.remove(key);
14
15
  return localStorage.setItem(key, value);
15
16
  } catch (err) {
16
- return;
17
+ // Error is ignored
17
18
  }
18
19
  }
19
20
  remove(key) {
20
21
  try {
21
22
  localStorage.removeItem(key);
22
23
  } catch (err) {
23
- return;
24
+ // Error is ignored
24
25
  }
25
26
  }
26
27
  }
@@ -21,14 +21,16 @@ export class InteractionTimer extends Timer {
21
21
  }
22
22
  if (isBrowserScope && opts.ee) {
23
23
  if (opts.ee) {
24
+ this.ee = opts.ee;
24
25
  const debouncedRefresh = debounce(this.refresh.bind(this), 500, {
25
26
  leading: true
26
27
  });
27
- opts.ee.on('fn-end', evts => {
28
+ this.refreshHandler = evts => {
28
29
  if (opts.refreshEvents.includes(evts?.[0]?.type)) {
29
30
  debouncedRefresh();
30
31
  }
31
- });
32
+ };
33
+ opts.ee.on('fn-end', this.refreshHandler);
32
34
  }
33
35
 
34
36
  // watch for the vis state changing. If the page is hidden, the local inactivity timer should be paused
@@ -42,22 +44,28 @@ export class InteractionTimer extends Timer {
42
44
  subscribeToVisibilityChange(state => {
43
45
  if (state === 'hidden') this.pause();
44
46
  // vis change --> visible is treated like a new interaction with the page
45
- else {
46
- this.refresh();
47
- this.onResume(); // emit resume event after state updated
48
- }
47
+ else this.resume();
49
48
  }, false, false, this.abortController?.signal);
50
49
  }
51
50
  }
52
51
  abort() {
53
52
  this.clear();
54
53
  this.abortController?.abort();
54
+ if (this.refreshHandler) {
55
+ this.ee.removeEventListener('fn-end', this.refreshHandler);
56
+ this.refreshHandler = this.ee = null;
57
+ }
55
58
  }
56
59
  pause() {
57
60
  this.onPause();
58
61
  clearTimeout(this.timer);
59
62
  this.remainingMs = this.initialMs - (Date.now() - this.startTimestamp);
60
63
  }
64
+ resume() {
65
+ this.refresh();
66
+ this.onResume(); // emit resume event after state updated
67
+ }
68
+
61
69
  refresh(cb, ms) {
62
70
  this.clear();
63
71
  this.timer = this.create(cb, ms);
@@ -26,7 +26,7 @@ var LOAD_EVENT = 'loadEvent';
26
26
  var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent';
27
27
  export var navTimingValues = [];
28
28
  function getPntType(type) {
29
- if (typeof type == 'number') return type;
29
+ if (typeof type === 'number') return type;
30
30
  const types = {
31
31
  navigate: undefined,
32
32
  reload: 1,
@@ -3,8 +3,7 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { windowAddEventListener } from '../event-listener/event-listener-opts';
6
- import { single } from '../util/invoke';
7
- import { ffVersion, globalScope, isWorkerScope, isBrowserScope } from '../constants/runtime';
6
+ import { globalScope, isWorkerScope, isBrowserScope } from '../constants/runtime';
8
7
  import { subscribeToVisibilityChange } from '../window/page-visibility';
9
8
  if (isWorkerScope) {
10
9
  globalScope.cleanupTasks = []; // create new list on WorkerGlobalScope to track funcs to run before exiting thread
@@ -23,37 +22,12 @@ if (isWorkerScope) {
23
22
  * Subscribes a provided callback to the time/event when the agent should treat it as end-of-life.
24
23
  * This is used, for example, to submit a final harvest and send all remaining data on best-effort.
25
24
  * @param {function} cb - func to run before or during the last reliable event or time of an env's life span
26
- * @param {boolean} allowBFCache - (temp) feature flag to gate new v1222 BFC support
27
25
  */
28
- export function subscribeToEOL(cb, allowBFCache) {
26
+ export function subscribeToEOL(cb) {
29
27
  if (isBrowserScope) {
30
- if (allowBFCache) {
31
- subscribeToVisibilityChange(cb, true); // when user switches tab or hides window, esp. mobile scenario
32
- windowAddEventListener('pagehide', cb); // when user navigates away, and because safari iOS v14.4- doesn't fully support vis change
33
- // --this ought to be removed once support for version below 14.5 phases out
34
- } else {
35
- var oneCall = single(cb);
36
-
37
- // Firefox has a bug wherein a slow-loading resource loaded from the 'pagehide'
38
- // or 'unload' event will delay the 'load' event firing on the next page load.
39
- // In Firefox versions that support sendBeacon, this doesn't matter, because
40
- // we'll use it instead of an image load for our final harvest.
41
- //
42
- // Some Safari versions never fire the 'unload' event for pages that are being
43
- // put into the WebKit page cache, so we *need* to use the pagehide event for
44
- // the final submission from Safari.
45
- //
46
- // Generally speaking, we will try to submit our final harvest from either
47
- // pagehide or unload, whichever comes first, but in Firefox, we need to avoid
48
- // attempting to submit from pagehide to ensure that we don't slow down loading
49
- // of the next page.
50
- if (!ffVersion || navigator.sendBeacon) {
51
- windowAddEventListener('pagehide', oneCall);
52
- } else {
53
- windowAddEventListener('beforeunload', oneCall);
54
- }
55
- windowAddEventListener('unload', oneCall);
56
- }
28
+ subscribeToVisibilityChange(cb, true); // when user switches tab or hides window, esp. mobile scenario
29
+ windowAddEventListener('pagehide', cb); // when user navigates away, and because safari iOS v14.4- doesn't fully support vis change
30
+ // --this ought to be removed once support for version below 14.5 phases out
57
31
  } else if (isWorkerScope) {
58
32
  globalScope.cleanupTasks.push(cb); // close() should run these tasks before quitting thread
59
33
  }
@@ -4,7 +4,6 @@
4
4
  */
5
5
  import { ee } from '../event-emitter/contextual-ee';
6
6
  import { handle } from '../event-emitter/handle';
7
- import { drain } from '../drain/drain';
8
7
  import { FEATURE_NAMES } from '../../loaders/features/features';
9
8
  const bucketMap = {
10
9
  stn: [FEATURE_NAMES.sessionTrace],
@@ -13,24 +12,24 @@ const bucketMap = {
13
12
  spa: [FEATURE_NAMES.spa],
14
13
  sr: [FEATURE_NAMES.sessionReplay, FEATURE_NAMES.sessionTrace]
15
14
  };
15
+ const sentIds = new Set();
16
16
 
17
17
  /** Note that this function only processes each unique flag ONCE, with the first occurrence of each flag and numeric value determining its switch on/off setting. */
18
18
  export function activateFeatures(flags, agentIdentifier) {
19
19
  const sharedEE = ee.get(agentIdentifier);
20
20
  if (!(flags && typeof flags === 'object')) return;
21
- Object.entries(flags).forEach(_ref => {
22
- let [flag, num] = _ref;
23
- if (activatedFeatures[flag] !== undefined) return;
24
- if (bucketMap[flag]) {
25
- bucketMap[flag].forEach(feat => {
26
- if (!num) handle('block-' + flag, [], undefined, feat, sharedEE);else handle('feat-' + flag, [], undefined, feat, sharedEE);
27
- handle('rumresp-' + flag, [Boolean(num)], undefined, feat, sharedEE); // this is a duplicate of feat-/block- but makes awaiting for 1 event easier than 2
28
- });
29
- } else if (num) handle('feat-' + flag, [], undefined, undefined, sharedEE); // not sure what other flags are overlooked, but there's a test for ones not in the map --
30
- // ^^^ THIS DOESN'T ACTUALLY DO ANYTHHING AS UNDEFINED/FEATURE GROUP ISN'T DRAINED
31
-
32
- activatedFeatures[flag] = Boolean(num);
33
- });
21
+ if (!sentIds.has(agentIdentifier)) {
22
+ Object.entries(flags).forEach(_ref => {
23
+ let [flag, num] = _ref;
24
+ if (bucketMap[flag]) {
25
+ bucketMap[flag].forEach(feat => {
26
+ if (!num) handle('block-' + flag, [], undefined, feat, sharedEE);else handle('feat-' + flag, [], undefined, feat, sharedEE);
27
+ handle('rumresp-' + flag, [Boolean(num)], undefined, feat, sharedEE); // this is a duplicate of feat-/block- but makes awaiting for 1 event easier than 2
28
+ });
29
+ } else if (num) handle('feat-' + flag, [], undefined, undefined, sharedEE); // not sure what other flags are overlooked, but there's a test for ones not in the map --
30
+ activatedFeatures[flag] = Boolean(num);
31
+ });
32
+ }
34
33
 
35
34
  // Let the features waiting on their respective flags know that RUM response was received and that any missing flags are interpreted as bad entitlement / "off".
36
35
  // Hence, those features will not be hanging forever if their flags aren't included in the response.
@@ -40,6 +39,6 @@ export function activateFeatures(flags, agentIdentifier) {
40
39
  activatedFeatures[flag] = false;
41
40
  }
42
41
  });
43
- drain(agentIdentifier, FEATURE_NAMES.pageViewEvent);
42
+ sentIds.add(agentIdentifier);
44
43
  }
45
44
  export const activatedFeatures = {};
@@ -32,7 +32,9 @@ export function debounce(func) {
32
32
  }
33
33
  if (leading && timer === undefined) {
34
34
  func.apply(_this, args);
35
- timer = setTimeout(() => timer = clearTimeout(timer), timeout);
35
+ timer = setTimeout(() => {
36
+ timer = clearTimeout(timer);
37
+ }, timeout);
36
38
  }
37
39
  if (!leading) {
38
40
  clearTimeout(timer);
@@ -52,11 +52,9 @@ export function validateRules(rules) {
52
52
  invalidRegexDetected = true;
53
53
  }
54
54
  var replacement = rules[i].replacement;
55
- if (replacement) {
56
- if (typeof replacement !== 'string') {
57
- warn('An obfuscation replacement rule contains a "replacement" value with an invalid type (must be a string)');
58
- invalidReplacementDetected = true;
59
- }
55
+ if (replacement && typeof replacement !== 'string') {
56
+ warn('An obfuscation replacement rule contains a "replacement" value with an invalid type (must be a string)');
57
+ invalidReplacementDetected = true;
60
58
  }
61
59
  }
62
60
  return !invalidReplacementDetected && !invalidRegexDetected;
@@ -20,6 +20,7 @@ export function applyFnToProps(obj, fn) {
20
20
  if (typeof obj[property] === 'object') {
21
21
  applyFnToProps(obj[property], fn, type, ignoreKeys);
22
22
  } else {
23
+ // eslint-disable-next-line valid-typeof
23
24
  if (typeof obj[property] === type && !ignoreKeys.includes(property)) obj[property] = fn(obj[property]);
24
25
  }
25
26
  });
@@ -15,11 +15,10 @@ export function subscribeToVisibilityChange(cb) {
15
15
  let capture = arguments.length > 2 ? arguments[2] : undefined;
16
16
  let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
17
17
  documentAddEventListener('visibilitychange', handleVisibilityChange, capture, abortSignal);
18
- return;
19
18
  function handleVisibilityChange() {
20
19
  if (toHiddenOnly) {
21
20
  // trigger cb on change to hidden state only
22
- if (document.visibilityState == 'hidden') cb();
21
+ if (document.visibilityState === 'hidden') cb();
23
22
  return;
24
23
  }
25
24
  cb(document.visibilityState);
@@ -7,14 +7,15 @@
7
7
  * This module is used directly by: session_trace.
8
8
  * It is also called by -> wrapXhr <-, so see "wrap-xhr.js" for features that use this indirectly.
9
9
  */
10
- import { ee as baseEE } from '../event-emitter/contextual-ee';
10
+ import { ee as baseEE, contextId } from '../event-emitter/contextual-ee';
11
11
  import { createWrapperWithEmitter as wfn } from './wrap-function';
12
12
  import { getOrSet } from '../util/get-or-set';
13
13
  import { globalScope, isBrowserScope } from '../constants/runtime';
14
14
  const wrapped = {};
15
- const XHR = XMLHttpRequest;
15
+ const XHR = globalScope.XMLHttpRequest;
16
16
  const ADD_EVENT_LISTENER = 'addEventListener';
17
17
  const REMOVE_EVENT_LISTENER = 'removeEventListener';
18
+ const flag = "nr@wrapped:".concat(contextId);
18
19
 
19
20
  /**
20
21
  * Wraps `addEventListener` and `removeEventListener` on: global scope; the prototype of `XMLHttpRequest`, and
@@ -43,7 +44,7 @@ export function wrapEvents(sharedEE) {
43
44
  if (originalListener === null || typeof originalListener !== 'function' && typeof originalListener !== 'object') {
44
45
  return;
45
46
  }
46
- var wrapped = getOrSet(originalListener, 'nr@wrapped', function () {
47
+ var wrapped = getOrSet(originalListener, flag, function () {
47
48
  var listener = {
48
49
  object: wrapHandleEvent,
49
50
  function: originalListener
@@ -6,16 +6,14 @@
6
6
  * @file Wraps `fetch` and related methods for instrumentation.
7
7
  * This module is used by: ajax, spa.
8
8
  */
9
- import { ee as baseEE } from '../event-emitter/contextual-ee';
9
+ import { ee as baseEE, contextId } from '../event-emitter/contextual-ee';
10
10
  import { globalScope } from '../constants/runtime';
11
- import { flag } from './wrap-function';
12
11
  var prefix = 'fetch-';
13
12
  var bodyPrefix = prefix + 'body-';
14
13
  var bodyMethods = ['arrayBuffer', 'blob', 'json', 'text', 'formData'];
15
14
  var Req = globalScope.Request;
16
15
  var Res = globalScope.Response;
17
16
  var proto = 'prototype';
18
- var ctxId = 'nr@context';
19
17
  const wrapped = {};
20
18
 
21
19
  /**
@@ -72,7 +70,7 @@ export function wrapFetch(sharedEE) {
72
70
  // we are wrapping args in an array so we can preserve the reference
73
71
  ee.emit(prefix + 'before-start', [args], ctx);
74
72
  var dtPayload;
75
- if (ctx[ctxId] && ctx[ctxId].dt) dtPayload = ctx[ctxId].dt;
73
+ if (ctx[contextId] && ctx[contextId].dt) dtPayload = ctx[contextId].dt;
76
74
  var origPromiseFromFetch = fn.apply(this, args);
77
75
  ee.emit(prefix + 'start', [args, dtPayload], origPromiseFromFetch);
78
76