@newrelic/browser-agent 1.232.0 → 1.233.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 (273) hide show
  1. package/dist/cjs/cdn/polyfills.js +5 -2
  2. package/dist/cjs/common/config/state/configurable.js +15 -26
  3. package/dist/cjs/common/config/state/info.js +1 -1
  4. package/dist/cjs/common/config/state/init.js +101 -56
  5. package/dist/cjs/common/config/state/loader-config.js +1 -1
  6. package/dist/cjs/common/config/state/runtime.js +1 -5
  7. package/dist/cjs/common/constants/env.cdn.js +1 -1
  8. package/dist/cjs/common/constants/env.npm.js +1 -1
  9. package/dist/cjs/common/drain/drain.js +1 -1
  10. package/dist/cjs/common/harvest/harvest-scheduler.js +30 -10
  11. package/dist/cjs/common/harvest/harvest.js +119 -55
  12. package/dist/cjs/common/session/session-entity.js +35 -22
  13. package/dist/cjs/common/session/session-entity.test.js +73 -49
  14. package/dist/cjs/common/timer/interaction-timer.js +9 -12
  15. package/dist/cjs/common/url/canonicalize-url.js +32 -0
  16. package/dist/cjs/common/url/canonicalize-url.test.js +42 -0
  17. package/dist/cjs/common/url/clean-url.js +10 -3
  18. package/dist/cjs/common/url/protocol.test.js +0 -1
  19. package/dist/cjs/common/util/feature-flags.js +2 -1
  20. package/dist/cjs/common/util/global-scope.js +4 -2
  21. package/dist/cjs/common/util/submit-data.js +57 -18
  22. package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
  23. package/dist/cjs/common/wrap/wrap-function.js +1 -3
  24. package/dist/cjs/common/wrap/wrap-promise.js +1 -1
  25. package/dist/cjs/features/ajax/aggregate/index.js +2 -2
  26. package/dist/cjs/features/ajax/instrument/index.js +1 -1
  27. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +12 -4
  28. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +93 -10
  29. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +164 -38
  30. package/dist/cjs/features/jserrors/aggregate/index.js +29 -48
  31. package/dist/cjs/features/jserrors/instrument/index.js +0 -2
  32. package/dist/cjs/features/metrics/aggregate/framework-detection.js +67 -0
  33. package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +137 -0
  34. package/dist/cjs/features/metrics/aggregate/index.js +7 -3
  35. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.js +14 -0
  36. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +17 -0
  37. package/dist/cjs/features/metrics/aggregate/polyfill-detection.js +53 -0
  38. package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +165 -0
  39. package/dist/cjs/features/page_action/aggregate/index.js +2 -2
  40. package/dist/cjs/features/page_view_event/aggregate/index.js +6 -3
  41. package/dist/cjs/features/page_view_timing/aggregate/index.js +2 -2
  42. package/dist/cjs/features/session_replay/aggregate/index.js +333 -0
  43. package/dist/cjs/features/session_replay/constants.js +9 -0
  44. package/dist/cjs/features/session_replay/index.js +12 -0
  45. package/dist/cjs/features/session_replay/instrument/index.js +29 -0
  46. package/dist/cjs/features/session_trace/aggregate/index.js +163 -164
  47. package/dist/cjs/features/session_trace/constants.js +2 -9
  48. package/dist/cjs/features/session_trace/instrument/index.js +24 -66
  49. package/dist/cjs/features/spa/aggregate/index.js +2 -2
  50. package/dist/cjs/features/utils/agent-session.js +1 -2
  51. package/dist/cjs/features/utils/aggregate-base.js +64 -0
  52. package/dist/cjs/features/utils/feature-base.js +0 -31
  53. package/dist/cjs/features/utils/handler-cache.js +3 -4
  54. package/dist/cjs/features/utils/instrument-base.js +42 -10
  55. package/dist/cjs/features/utils/{lazy-loader.js → lazy-feature-loader.js} +4 -2
  56. package/dist/cjs/loaders/agent.js +1 -1
  57. package/dist/cjs/loaders/api/apiAsync.js +3 -1
  58. package/dist/cjs/loaders/configure/configure.js +3 -3
  59. package/dist/cjs/loaders/features/featureDependencies.js +0 -12
  60. package/dist/cjs/loaders/features/features.js +3 -1
  61. package/dist/cjs/loaders/micro-agent.js +6 -6
  62. package/dist/esm/cdn/polyfills.js +5 -2
  63. package/dist/esm/common/config/state/configurable.js +14 -24
  64. package/dist/esm/common/config/state/info.js +2 -2
  65. package/dist/esm/common/config/state/init.js +102 -57
  66. package/dist/esm/common/config/state/loader-config.js +2 -2
  67. package/dist/esm/common/config/state/runtime.js +2 -4
  68. package/dist/esm/common/constants/env.cdn.js +1 -1
  69. package/dist/esm/common/constants/env.npm.js +1 -1
  70. package/dist/esm/common/drain/drain.js +1 -1
  71. package/dist/esm/common/harvest/harvest-scheduler.js +30 -10
  72. package/dist/esm/common/harvest/harvest.js +121 -56
  73. package/dist/esm/common/session/session-entity.js +35 -22
  74. package/dist/esm/common/session/session-entity.test.js +73 -49
  75. package/dist/esm/common/timer/interaction-timer.js +9 -12
  76. package/dist/esm/common/url/canonicalize-url.js +27 -0
  77. package/dist/esm/common/url/canonicalize-url.test.js +38 -0
  78. package/dist/esm/common/url/clean-url.js +10 -3
  79. package/dist/esm/common/url/protocol.test.js +0 -1
  80. package/dist/esm/common/util/feature-flags.js +2 -1
  81. package/dist/esm/common/util/global-scope.js +1 -0
  82. package/dist/esm/common/util/submit-data.js +57 -18
  83. package/dist/esm/common/wrap/wrap-fetch.js +1 -2
  84. package/dist/esm/common/wrap/wrap-function.js +1 -2
  85. package/dist/esm/common/wrap/wrap-promise.js +1 -1
  86. package/dist/esm/features/ajax/aggregate/index.js +2 -2
  87. package/dist/esm/features/ajax/instrument/index.js +1 -1
  88. package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +12 -4
  89. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +93 -10
  90. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +149 -25
  91. package/dist/esm/features/jserrors/aggregate/index.js +30 -48
  92. package/dist/esm/features/jserrors/instrument/index.js +0 -1
  93. package/dist/esm/features/metrics/aggregate/framework-detection.js +61 -0
  94. package/dist/esm/features/metrics/aggregate/framework-detection.test.js +133 -0
  95. package/dist/esm/features/metrics/aggregate/index.js +7 -3
  96. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.js +8 -0
  97. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +15 -0
  98. package/dist/esm/features/metrics/aggregate/polyfill-detection.js +47 -0
  99. package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +163 -0
  100. package/dist/esm/features/page_action/aggregate/index.js +2 -2
  101. package/dist/esm/features/page_view_event/aggregate/index.js +6 -3
  102. package/dist/esm/features/page_view_timing/aggregate/index.js +2 -2
  103. package/dist/esm/features/session_replay/aggregate/index.js +327 -0
  104. package/dist/esm/features/session_replay/constants.js +2 -0
  105. package/dist/esm/features/session_replay/index.js +12 -0
  106. package/dist/esm/features/session_replay/instrument/index.js +21 -0
  107. package/dist/esm/features/session_trace/aggregate/index.js +163 -163
  108. package/dist/esm/features/session_trace/constants.js +1 -5
  109. package/dist/esm/features/session_trace/instrument/index.js +24 -66
  110. package/dist/esm/features/spa/aggregate/index.js +2 -2
  111. package/dist/esm/features/utils/agent-session.js +1 -2
  112. package/dist/esm/features/utils/aggregate-base.js +57 -0
  113. package/dist/esm/features/utils/feature-base.js +1 -32
  114. package/dist/esm/features/utils/handler-cache.js +3 -4
  115. package/dist/esm/features/utils/instrument-base.js +42 -10
  116. package/dist/esm/features/utils/{lazy-loader.js → lazy-feature-loader.js} +3 -1
  117. package/dist/esm/loaders/agent.js +1 -1
  118. package/dist/esm/loaders/api/apiAsync.js +3 -1
  119. package/dist/esm/loaders/configure/configure.js +3 -3
  120. package/dist/esm/loaders/features/featureDependencies.js +0 -11
  121. package/dist/esm/loaders/features/features.js +3 -1
  122. package/dist/esm/loaders/micro-agent.js +6 -6
  123. package/dist/types/common/config/state/configurable.d.ts +1 -3
  124. package/dist/types/common/config/state/configurable.d.ts.map +1 -1
  125. package/dist/types/common/config/state/init.d.ts.map +1 -1
  126. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  127. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  128. package/dist/types/common/harvest/harvest.d.ts +37 -34
  129. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  130. package/dist/types/common/session/session-entity.d.ts +6 -3
  131. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  132. package/dist/types/common/timer/interaction-timer.d.ts +2 -1
  133. package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
  134. package/dist/types/common/url/canonicalize-url.d.ts +9 -0
  135. package/dist/types/common/url/canonicalize-url.d.ts.map +1 -0
  136. package/dist/types/common/url/clean-url.d.ts +7 -1
  137. package/dist/types/common/url/clean-url.d.ts.map +1 -1
  138. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  139. package/dist/types/common/util/global-scope.d.ts +1 -0
  140. package/dist/types/common/util/global-scope.d.ts.map +1 -1
  141. package/dist/types/common/util/submit-data.d.ts +40 -14
  142. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  143. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  144. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
  145. package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
  146. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  147. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +8 -1
  148. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
  149. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +48 -19
  150. package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -1
  151. package/dist/types/features/jserrors/aggregate/index.d.ts +14 -5
  152. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  153. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  154. package/dist/types/features/metrics/aggregate/framework-detection.d.ts.map +1 -0
  155. package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
  156. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  157. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts +6 -0
  158. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts.map +1 -0
  159. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts +7 -0
  160. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +1 -0
  161. package/dist/types/features/page_action/aggregate/index.d.ts +3 -3
  162. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  163. package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
  164. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  165. package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
  166. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  167. package/dist/types/features/session_replay/aggregate/index.d.ts +96 -0
  168. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -0
  169. package/dist/types/features/session_replay/constants.d.ts +2 -0
  170. package/dist/types/features/session_replay/constants.d.ts.map +1 -0
  171. package/dist/types/features/session_replay/index.d.ts +2 -0
  172. package/dist/types/features/session_replay/index.d.ts.map +1 -0
  173. package/dist/types/features/session_replay/instrument/index.d.ts +6 -0
  174. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -0
  175. package/dist/types/features/session_trace/aggregate/index.d.ts +8 -57
  176. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  177. package/dist/types/features/session_trace/constants.d.ts +0 -3
  178. package/dist/types/features/session_trace/constants.d.ts.map +1 -1
  179. package/dist/types/features/session_trace/instrument/index.d.ts +1 -3
  180. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  181. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  182. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  183. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  184. package/dist/types/features/utils/aggregate-base.d.ts +11 -0
  185. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -0
  186. package/dist/types/features/utils/feature-base.d.ts +0 -5
  187. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  188. package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
  189. package/dist/types/features/utils/instrument-base.d.ts +3 -1
  190. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  191. package/dist/types/features/utils/{lazy-loader.d.ts → lazy-feature-loader.d.ts} +2 -2
  192. package/dist/types/features/utils/lazy-feature-loader.d.ts.map +1 -0
  193. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  194. package/dist/types/loaders/features/featureDependencies.d.ts +0 -1
  195. package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
  196. package/dist/types/loaders/features/features.d.ts +1 -0
  197. package/dist/types/loaders/features/features.d.ts.map +1 -1
  198. package/package.json +31 -22
  199. package/src/cdn/polyfills.js +4 -1
  200. package/src/common/config/state/configurable.js +18 -24
  201. package/src/common/config/state/info.js +2 -2
  202. package/src/common/config/state/init.js +62 -28
  203. package/src/common/config/state/loader-config.js +2 -2
  204. package/src/common/config/state/runtime.js +2 -4
  205. package/src/common/drain/drain.js +1 -1
  206. package/src/common/harvest/harvest-scheduler.js +35 -10
  207. package/src/common/harvest/harvest.js +73 -50
  208. package/src/common/session/session-entity.js +34 -23
  209. package/src/common/session/session-entity.test.js +57 -51
  210. package/src/common/timer/interaction-timer.js +9 -12
  211. package/src/common/url/canonicalize-url.js +28 -0
  212. package/src/common/url/canonicalize-url.test.js +34 -0
  213. package/src/common/url/clean-url.js +10 -3
  214. package/src/common/url/protocol.test.js +0 -1
  215. package/src/common/util/feature-flags.js +2 -2
  216. package/src/common/util/global-scope.js +2 -0
  217. package/src/common/util/submit-data.js +28 -17
  218. package/src/common/wrap/wrap-fetch.js +1 -2
  219. package/src/common/wrap/wrap-function.js +1 -2
  220. package/src/common/wrap/wrap-promise.js +1 -1
  221. package/src/features/ajax/aggregate/index.js +2 -2
  222. package/src/features/ajax/instrument/index.js +1 -1
  223. package/src/features/jserrors/aggregate/canonical-function-name.js +12 -4
  224. package/src/features/jserrors/aggregate/compute-stack-trace.js +85 -11
  225. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +141 -24
  226. package/src/features/jserrors/aggregate/index.js +28 -52
  227. package/src/features/jserrors/instrument/index.js +0 -1
  228. package/src/features/metrics/aggregate/framework-detection.js +73 -0
  229. package/src/features/metrics/aggregate/framework-detection.test.js +201 -0
  230. package/src/features/metrics/aggregate/index.js +8 -3
  231. package/src/features/metrics/aggregate/polyfill-detection.es5.js +9 -0
  232. package/src/features/metrics/aggregate/polyfill-detection.es5.test.js +16 -0
  233. package/src/features/metrics/aggregate/polyfill-detection.js +48 -0
  234. package/src/features/metrics/aggregate/polyfill-detection.test.js +163 -0
  235. package/src/features/page_action/aggregate/index.js +2 -2
  236. package/src/features/page_view_event/aggregate/index.js +5 -5
  237. package/src/features/page_view_timing/aggregate/index.js +2 -2
  238. package/src/features/session_replay/aggregate/index.js +314 -0
  239. package/src/features/session_replay/constants.js +3 -0
  240. package/src/features/session_replay/index.js +12 -0
  241. package/src/features/session_replay/instrument/index.js +22 -0
  242. package/src/features/session_trace/aggregate/index.js +148 -188
  243. package/src/features/session_trace/constants.js +0 -4
  244. package/src/features/session_trace/instrument/index.js +17 -69
  245. package/src/features/spa/aggregate/index.js +2 -2
  246. package/src/features/utils/agent-session.js +1 -2
  247. package/src/features/utils/aggregate-base.js +51 -0
  248. package/src/features/utils/feature-base.js +1 -31
  249. package/src/features/utils/handler-cache.js +3 -4
  250. package/src/features/utils/instrument-base.js +40 -8
  251. package/src/features/utils/{lazy-loader.js → lazy-feature-loader.js} +3 -1
  252. package/src/loaders/agent.js +1 -1
  253. package/src/loaders/api/apiAsync.js +1 -1
  254. package/src/loaders/configure/configure.js +4 -3
  255. package/src/loaders/features/featureDependencies.js +0 -12
  256. package/src/loaders/features/features.js +3 -1
  257. package/src/loaders/micro-agent.js +4 -4
  258. package/dist/cjs/common/metrics/framework-detection.js +0 -72
  259. package/dist/cjs/common/util/user-agent.js +0 -57
  260. package/dist/cjs/common/window/supports-performance-observer.js +0 -15
  261. package/dist/esm/common/metrics/framework-detection.js +0 -66
  262. package/dist/esm/common/util/user-agent.js +0 -48
  263. package/dist/esm/common/window/supports-performance-observer.js +0 -9
  264. package/dist/types/common/metrics/framework-detection.d.ts.map +0 -1
  265. package/dist/types/common/util/user-agent.d.ts +0 -5
  266. package/dist/types/common/util/user-agent.d.ts.map +0 -1
  267. package/dist/types/common/window/supports-performance-observer.d.ts +0 -2
  268. package/dist/types/common/window/supports-performance-observer.d.ts.map +0 -1
  269. package/dist/types/features/utils/lazy-loader.d.ts.map +0 -1
  270. package/src/common/metrics/framework-detection.js +0 -71
  271. package/src/common/util/user-agent.js +0 -56
  272. package/src/common/window/supports-performance-observer.js +0 -10
  273. /package/dist/types/{common/metrics → features/metrics/aggregate}/framework-detection.d.ts +0 -0
@@ -6,93 +6,67 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Aggregate = void 0;
7
7
  var _registerHandler = require("../../../common/event-emitter/register-handler");
8
8
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
9
- var _mapOwn = require("../../../common/util/map-own");
10
9
  var _stringify = require("../../../common/util/stringify");
11
10
  var _parseUrl = require("../../../common/url/parse-url");
12
- var _supportsPerformanceObserver = require("../../../common/window/supports-performance-observer");
13
- var _lodash = _interopRequireDefault(require("lodash._slice"));
14
11
  var _config = require("../../../common/config/config");
15
12
  var _now = require("../../../common/timing/now");
16
13
  var _constants = require("../constants");
17
14
  var _drain = require("../../../common/drain/drain");
18
15
  var _handlerCache = require("../../utils/handler-cache");
19
- var _featureBase = require("../../utils/feature-base");
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ var _aggregateBase = require("../../utils/aggregate-base");
21
17
  /*
22
18
  * Copyright 2020 New Relic Corporation. All rights reserved.
23
19
  * SPDX-License-Identifier: Apache-2.0
24
20
  */
25
21
 
26
- class Aggregate extends _featureBase.FeatureBase {
22
+ const ignoredEvents = {
23
+ // we find that certain events make the data too noisy to be useful
24
+ global: {
25
+ mouseup: true,
26
+ mousedown: true
27
+ },
28
+ // certain events are present both in the window and in PVT metrics. PVT metrics are prefered so the window events should be ignored
29
+ window: {
30
+ load: true,
31
+ pagehide: true
32
+ },
33
+ // when ajax instrumentation is disabled, all XMLHttpRequest events will return with origin = xhrOriginMissing and should be ignored
34
+ xhrOriginMissing: {
35
+ ignoreAll: true
36
+ }
37
+ };
38
+ const toAggregate = {
39
+ typing: [1000, 2000],
40
+ scrolling: [100, 1000],
41
+ mousing: [1000, 2000],
42
+ touching: [1000, 2000]
43
+ };
44
+ const MAX_TRACE_DURATION = 15 * 60 * 1000; // 15 minutes
45
+
46
+ class Aggregate extends _aggregateBase.AggregateBase {
27
47
  static featureName = _constants.FEATURE_NAME;
28
- constructor(agentIdentifier, aggregator) {
48
+ constructor(agentIdentifier, aggregator, argsObj) {
29
49
  var _this;
30
50
  // Very unlikely, but in case the existing XMLHttpRequest.prototype object on the page couldn't be wrapped.
31
51
  super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
32
52
  _this = this;
33
53
  if (!(0, _config.getRuntime)(agentIdentifier).xhrWrappable) return;
34
- const handlerCache = new _handlerCache.HandlerCache();
54
+ this.resourceObserver = argsObj?.resourceObserver; // undefined if observer couldn't be created
35
55
  this.ptid = '';
36
- this.ignoredEvents = {
37
- // we find that certain events make the data too noisy to be useful
38
- global: {
39
- mouseup: true,
40
- mousedown: true
41
- },
42
- // certain events are present both in the window and in PVT metrics. PVT metrics are prefered so the window events should be ignored
43
- window: {
44
- load: true,
45
- pagehide: true
46
- },
47
- // when ajax instrumentation is disabled, all XMLHttpRequest events will return with origin = xhrOriginMissing and should be ignored
48
- xhrOriginMissing: {
49
- ignoreAll: true
50
- }
51
- };
52
- this.toAggregate = {
53
- typing: [1000, 2000],
54
- scrolling: [100, 1000],
55
- mousing: [1000, 2000],
56
- touching: [1000, 2000]
57
- };
58
- this.rename = {
59
- typing: {
60
- keydown: true,
61
- keyup: true,
62
- keypress: true
63
- },
64
- mousing: {
65
- mousemove: true,
66
- mouseenter: true,
67
- mouseleave: true,
68
- mouseover: true,
69
- mouseout: true
70
- },
71
- scrolling: {
72
- scroll: true
73
- },
74
- touching: {
75
- touchstart: true,
76
- touchmove: true,
77
- touchend: true,
78
- touchcancel: true,
79
- touchenter: true,
80
- touchleave: true
81
- }
82
- };
83
56
  this.trace = {};
84
57
  this.nodeCount = 0;
85
58
  this.sentTrace = null;
86
59
  this.harvestTimeSeconds = (0, _config.getConfigurationValue)(agentIdentifier, 'session_trace.harvestTimeSeconds') || 10;
87
60
  this.maxNodesPerHarvest = (0, _config.getConfigurationValue)(agentIdentifier, 'session_trace.maxNodesPerHarvest') || 1000;
88
61
  this.laststart = 0;
62
+ const handlerCache = new _handlerCache.HandlerCache();
89
63
  (0, _registerHandler.registerHandler)('feat-stn', () => {
90
64
  if (typeof PerformanceNavigationTiming !== 'undefined') {
91
- this.storeTiming(window.performance?.getEntriesByType('navigation')?.[0] || {});
65
+ this.storeTiming(window.performance.getEntriesByType('navigation')[0]);
92
66
  } else {
93
- this.storeTiming(window.performance?.timing);
67
+ this.storeTiming(window.performance.timing);
94
68
  }
95
- var scheduler = new _harvestScheduler.HarvestScheduler('resources', {
69
+ const scheduler = new _harvestScheduler.HarvestScheduler('resources', {
96
70
  onFinished: onHarvestFinished.bind(this),
97
71
  retryDelay: this.harvestTimeSeconds
98
72
  }, this);
@@ -100,38 +74,37 @@ class Aggregate extends _featureBase.FeatureBase {
100
74
  scheduler.runHarvest({
101
75
  needResponse: true
102
76
  }); // sends first stn harvest immediately
103
-
77
+ handlerCache.decide(true);
104
78
  function onHarvestFinished(result) {
105
- // start timer only if ptid was returned by server
106
79
  if (result.sent && result.responseText && !this.ptid) {
107
- this.ptid = result.responseText;
108
- (0, _config.getRuntime)(this.agentIdentifier).ptid = this.ptid;
80
+ // continue interval harvest only if ptid was returned by server on the first
81
+ (0, _config.getRuntime)(this.agentIdentifier).ptid = this.ptid = result.responseText;
109
82
  scheduler.startTimer(this.harvestTimeSeconds);
110
83
  }
111
84
  if (result.sent && result.retry && this.sentTrace) {
112
- (0, _mapOwn.mapOwn)(this.sentTrace, (name, nodes) => {
113
- this.mergeSTNs(name, nodes);
85
+ // merge previous trace back into buffer to retry for next harvest
86
+ Object.entries(this.sentTrace).forEach(_ref => {
87
+ let [name, listOfSTNodes] = _ref;
88
+ if (this.nodeCount >= this.maxNodesPerHarvest) return;
89
+ this.nodeCount += listOfSTNodes.length;
90
+ this.trace[name] = this.trace[name] ? listOfSTNodes.concat(this.trace[name]) : listOfSTNodes;
114
91
  });
115
92
  this.sentTrace = null;
116
93
  }
117
94
  }
118
95
  function prepareHarvest(options) {
119
- if ((0, _now.now)() > 15 * 60 * 1000) {
96
+ if ((0, _now.now)() > MAX_TRACE_DURATION) {
120
97
  // been collecting for over 15 min, empty trace object and bail
121
98
  scheduler.stopTimer();
122
99
  this.trace = {};
123
100
  return;
124
101
  }
125
-
126
- // only send when there are more than 30 nodes to send
102
+ // Only harvest when there are more than 30 nodes to send after the very first.
127
103
  if (this.ptid && this.nodeCount <= 30) return;
128
104
  return this.takeSTNs(options.retry);
129
105
  }
130
- handlerCache.decide(true);
131
- }, this.featureName, this.ee);
132
- (0, _registerHandler.registerHandler)('block-stn', () => {
133
- handlerCache.decide(false);
134
106
  }, this.featureName, this.ee);
107
+ (0, _registerHandler.registerHandler)('block-stn', () => handlerCache.decide(false), this.featureName, this.ee);
135
108
 
136
109
  // register the handlers immediately... but let the handlerCache decide if the data should actually get stored...
137
110
  (0, _registerHandler.registerHandler)('bst', function () {
@@ -184,19 +157,28 @@ class Aggregate extends _featureBase.FeatureBase {
184
157
  }, this.featureName, this.ee);
185
158
  (0, _drain.drain)(this.agentIdentifier, this.featureName);
186
159
  }
160
+
161
+ // PageViewTiming (FEATURE) events and metrics, such as 'load', 'lcp', etc. pipes into ST here.
187
162
  processPVT(name, value, attrs) {
188
- var t = {};
189
- t[name] = value;
190
- this.storeTiming(t);
191
- if (this.hasFID(name, attrs)) this.storeEvent({
163
+ this.storeTiming({
164
+ [name]: value
165
+ });
166
+ if (hasFID(name, attrs)) this.storeEvent({
192
167
  type: 'fid',
193
168
  target: 'document'
194
169
  }, 'document', value, value + attrs.fid);
170
+ function hasFID(name, attrs) {
171
+ return name === 'fi' && !!attrs && typeof attrs.fid === 'number';
172
+ }
195
173
  }
196
- storeTiming(_t) {
174
+
175
+ // This processes the aforementioned PVT and the first navigation entry of the page.
176
+ storeTiming(timingEntry) {
177
+ if (!timingEntry) return;
178
+
197
179
  // loop iterates through prototype also (for FF)
198
- for (let key in _t) {
199
- const val = _t[key];
180
+ for (let key in timingEntry) {
181
+ let val = timingEntry[key];
200
182
 
201
183
  // ignore size and status type nodes that do not map to timestamp metrics
202
184
  const lck = key.toLowerCase();
@@ -205,31 +187,33 @@ class Aggregate extends _featureBase.FeatureBase {
205
187
  // ignore inherited methods, meaningless 0 values, and bogus timestamps
206
188
  // that are in the future (Microsoft Edge seems to sometimes produce these)
207
189
  if (!(typeof val === 'number' && val >= 0)) continue;
208
- const timeOffset = Math.round(_t[key]);
190
+ val = Math.round(val);
209
191
  this.storeSTN({
210
192
  n: key,
211
- s: timeOffset,
212
- e: timeOffset,
193
+ s: val,
194
+ e: val,
213
195
  o: 'document',
214
196
  t: 'timing'
215
197
  });
216
198
  }
217
199
  }
200
+
201
+ // Tracks duration of native APIs wrapped by wrap-timer & wrap-raf.
218
202
  storeTimer(target, start, end, type) {
219
- var category = 'timer';
220
- if (type === 'requestAnimationFrame') category = type;
221
- var evt = {
203
+ const evt = {
222
204
  n: type,
223
205
  s: start,
224
206
  e: end,
225
207
  o: 'window',
226
- t: category
208
+ t: type === 'requestAnimationFrame' ? type : 'timer'
227
209
  };
228
210
  this.storeSTN(evt);
229
211
  }
212
+
213
+ // Tracks the events and their listener's duration on objects wrapped by wrap-events.
230
214
  storeEvent(currentEvent, target, start, end) {
231
- if (this.shouldIgnoreEvent(currentEvent, target)) return false;
232
- var evt = {
215
+ if (this.shouldIgnoreEvent(currentEvent, target)) return;
216
+ const evt = {
233
217
  n: this.evtName(currentEvent.type),
234
218
  s: start,
235
219
  e: end,
@@ -244,31 +228,60 @@ class Aggregate extends _featureBase.FeatureBase {
244
228
  }
245
229
  this.storeSTN(evt);
246
230
  }
231
+ shouldIgnoreEvent(event, target) {
232
+ const origin = this.evtOrigin(event.target, target);
233
+ if (event.type in ignoredEvents.global) return true;
234
+ if (!!ignoredEvents[origin] && ignoredEvents[origin].ignoreAll) return true;
235
+ if (!!ignoredEvents[origin] && event.type in ignoredEvents[origin]) return true;
236
+ return false;
237
+ }
247
238
  evtName(type) {
248
- var name = type;
249
- (0, _mapOwn.mapOwn)(this.rename, function (key, val) {
250
- if (type in val) name = key;
251
- });
252
- return name;
239
+ switch (type) {
240
+ case 'keydown':
241
+ case 'keyup':
242
+ case 'keypress':
243
+ return 'typing';
244
+ case 'mousemove':
245
+ case 'mouseenter':
246
+ case 'mouseleave':
247
+ case 'mouseover':
248
+ case 'mouseout':
249
+ return 'mousing';
250
+ case 'scroll':
251
+ return 'scrolling';
252
+ case 'touchstart':
253
+ case 'touchmove':
254
+ case 'touchend':
255
+ case 'touchcancel':
256
+ case 'touchenter':
257
+ case 'touchleave':
258
+ return 'touching';
259
+ default:
260
+ return type;
261
+ }
253
262
  }
254
263
  evtOrigin(t, target) {
255
- var origin = 'unknown';
264
+ let origin = 'unknown';
256
265
  if (t && t instanceof XMLHttpRequest) {
257
- var params = this.ee.context(t).params;
266
+ const params = this.ee.context(t).params;
258
267
  if (!params || !params.status || !params.method || !params.host || !params.pathname) return 'xhrOriginMissing';
259
268
  origin = params.status + ' ' + params.method + ': ' + params.host + params.pathname;
260
269
  } else if (t && typeof t.tagName === 'string') {
261
270
  origin = t.tagName.toLowerCase();
262
271
  if (t.id) origin += '#' + t.id;
263
- if (t.className) origin += '.' + (0, _lodash.default)(t.classList).join('.');
272
+ if (t.className) {
273
+ for (let i = 0; i < t.classList.length; i++) origin += '.' + t.classList[i];
274
+ }
264
275
  }
265
276
  if (origin === 'unknown') {
266
277
  if (typeof target === 'string') origin = target;else if (target === document) origin = 'document';else if (target === window) origin = 'window';else if (target instanceof FileReader) origin = 'FileReader';
267
278
  }
268
279
  return origin;
269
280
  }
281
+
282
+ // Tracks when the window history API specified by wrap-history is used.
270
283
  storeHist(path, old, time) {
271
- var node = {
284
+ const node = {
272
285
  n: 'history.pushState',
273
286
  s: time,
274
287
  e: time,
@@ -277,11 +290,15 @@ class Aggregate extends _featureBase.FeatureBase {
277
290
  };
278
291
  this.storeSTN(node);
279
292
  }
293
+
294
+ // Processes all the PerformanceResourceTiming entries captured (by observer).
280
295
  storeResources(resources) {
281
296
  if (!resources || resources.length === 0) return;
282
297
  resources.forEach(currentResource => {
283
- var parsed = (0, _parseUrl.parseUrl)(currentResource.name);
284
- var res = {
298
+ if ((currentResource.fetchStart | 0) <= this.laststart) return; // don't recollect already-seen resources
299
+
300
+ const parsed = (0, _parseUrl.parseUrl)(currentResource.name);
301
+ const res = {
285
302
  n: currentResource.initiatorType,
286
303
  s: currentResource.fetchStart | 0,
287
304
  e: currentResource.responseEnd | 0,
@@ -289,16 +306,15 @@ class Aggregate extends _featureBase.FeatureBase {
289
306
  // resource.name is actually a URL so it's the source
290
307
  t: currentResource.entryType
291
308
  };
292
-
293
- // don't recollect old resources
294
- if (res.s <= this.laststart) return;
295
309
  this.storeSTN(res);
296
310
  });
297
311
  this.laststart = resources[resources.length - 1].fetchStart | 0;
298
312
  }
313
+
314
+ // JavascriptError (FEATURE) events pipes into ST here.
299
315
  storeErrorAgg(type, name, params, metrics) {
300
- if (type !== 'err') return;
301
- var node = {
316
+ if (type !== 'err') return; // internal errors are purposefully ignored
317
+ const node = {
302
318
  n: 'error',
303
319
  s: metrics.time,
304
320
  e: metrics.time,
@@ -307,9 +323,11 @@ class Aggregate extends _featureBase.FeatureBase {
307
323
  };
308
324
  this.storeSTN(node);
309
325
  }
326
+
327
+ // Ajax (FEATURE) events--XML & fetches--pipes into ST here.
310
328
  storeXhrAgg(type, name, params, metrics) {
311
329
  if (type !== 'xhr') return;
312
- var node = {
330
+ const node = {
313
331
  n: 'Ajax',
314
332
  s: metrics.time,
315
333
  e: metrics.time + metrics.duration,
@@ -318,46 +336,46 @@ class Aggregate extends _featureBase.FeatureBase {
318
336
  };
319
337
  this.storeSTN(node);
320
338
  }
339
+
340
+ // Central function called by all the other store__ & addToTrace API to append a trace node.
321
341
  storeSTN(stn) {
322
- // limit the number of data that is stored
323
- if (this.nodeCount >= this.maxNodesPerHarvest) return;
324
- var traceArr = this.trace[stn.n];
325
- if (!traceArr) traceArr = this.trace[stn.n] = [];
326
- traceArr.push(stn);
342
+ if (this.nodeCount >= this.maxNodesPerHarvest) return; // limit the amount of data that is stored at once
343
+
344
+ if (this.trace[stn.n]) this.trace[stn.n].push(stn);else this.trace[stn.n] = [stn];
327
345
  this.nodeCount++;
328
346
  }
329
- mergeSTNs(key, nodes) {
330
- // limit the number of data that is stored
331
- if (this.nodeCount >= this.maxNodesPerHarvest) return;
332
- var traceArr = this.trace[key];
333
- if (!traceArr) traceArr = this.trace[key] = [];
334
- this.trace[key] = nodes.concat(traceArr);
335
- this.nodeCount += nodes.length;
336
- }
347
+
348
+ // Used by session trace's harvester to create the payload body.
337
349
  takeSTNs(retry) {
338
- // if the observer is not being used, this checks resourcetiming buffer every harvest
339
- if (!(0, _supportsPerformanceObserver.supportsPerformanceObserver)()) {
350
+ if (!this.resourceObserver) {
351
+ // if PO isn't supported, this checks resourcetiming buffer every harvest.
340
352
  this.storeResources(window.performance.getEntriesByType('resource'));
341
353
  }
342
- var stns = (0, _mapOwn.mapOwn)(this.trace, (name, nodes) => {
343
- if (!(name in this.toAggregate)) return nodes;
344
- return (0, _mapOwn.mapOwn)(nodes.sort(this.byStart).reduce(this.smearEvtsByOrigin(name), {}), this.val).reduce(this.flatten, []);
345
- }).reduce(this.flatten, []);
354
+ const stns = Object.entries(this.trace).flatMap(_ref2 => {
355
+ let [name, listOfSTNodes] = _ref2;
356
+ // basically take the "this.trace" map-obj and concat all the list-type values
357
+ if (!(name in toAggregate)) return listOfSTNodes;
358
+ // Special processing for event nodes dealing with user inputs:
359
+ const reindexByOriginFn = this.smearEvtsByOrigin(name);
360
+ const partitionListByOriginMap = listOfSTNodes.sort((a, b) => a.s - b.s).reduce(reindexByOriginFn, {});
361
+ return Object.values(partitionListByOriginMap).flat(); // join the partitions back into 1-D, now ordered by origin then start time
362
+ }, this);
346
363
  if (stns.length === 0) return {};
347
364
  if (retry) {
348
365
  this.sentTrace = this.trace;
349
366
  }
350
367
  this.trace = {};
351
368
  this.nodeCount = 0;
352
- var stnInfo = {
369
+ const stnInfo = {
353
370
  qs: {
354
- st: '' + (0, _config.getRuntime)(this.agentIdentifier).offset
371
+ st: String((0, _config.getRuntime)(this.agentIdentifier).offset)
355
372
  },
356
373
  body: {
357
374
  res: stns
358
375
  }
359
376
  };
360
377
  if (!this.ptid) {
378
+ // send custom and user attributes on the very first ST harvest only
361
379
  const {
362
380
  userAttributes,
363
381
  atts,
@@ -365,54 +383,35 @@ class Aggregate extends _featureBase.FeatureBase {
365
383
  } = (0, _config.getInfo)(this.agentIdentifier);
366
384
  stnInfo.qs.ua = userAttributes;
367
385
  stnInfo.qs.at = atts;
368
- var ja = (0, _stringify.stringify)(jsAttributes);
386
+ const ja = (0, _stringify.stringify)(jsAttributes);
369
387
  stnInfo.qs.ja = ja === '{}' ? null : ja;
370
388
  }
371
389
  return stnInfo;
372
390
  }
373
- byStart(a, b) {
374
- return a.s - b.s;
375
- }
376
391
  smearEvtsByOrigin(name) {
377
- var maxGap = this.toAggregate[name][0];
378
- var maxLen = this.toAggregate[name][1];
379
- var lastO = {};
380
- return (byOrigin, evt) => {
381
- var lastArr = byOrigin[evt.o];
382
- lastArr || (lastArr = byOrigin[evt.o] = []);
383
- var last = lastO[evt.o];
384
- if (name === 'scrolling' && !this.trivial(evt)) {
385
- lastO[evt.o] = null;
386
- evt.n = 'scroll';
387
- lastArr.push(evt);
388
- } else if (last && evt.s - last.s < maxLen && last.e > evt.s - maxGap) {
389
- last.e = evt.e;
392
+ const maxGap = toAggregate[name][0];
393
+ const maxLen = toAggregate[name][1];
394
+ const lastO = {};
395
+ return (byOrigin, evtNode) => {
396
+ let lastArr = byOrigin[evtNode.o];
397
+ if (!lastArr) lastArr = byOrigin[evtNode.o] = [];
398
+ const last = lastO[evtNode.o];
399
+ if (name === 'scrolling' && !trivial(evtNode)) {
400
+ lastO[evtNode.o] = null;
401
+ evtNode.n = 'scroll';
402
+ lastArr.push(evtNode);
403
+ } else if (last && evtNode.s - last.s < maxLen && last.e > evtNode.s - maxGap) {
404
+ last.e = evtNode.e;
390
405
  } else {
391
- lastO[evt.o] = evt;
392
- lastArr.push(evt);
406
+ lastO[evtNode.o] = evtNode;
407
+ lastArr.push(evtNode);
393
408
  }
394
409
  return byOrigin;
395
410
  };
396
- }
397
- val(key, value) {
398
- return value;
399
- }
400
- flatten(a, b) {
401
- return a.concat(b);
402
- }
403
- hasFID(name, attrs) {
404
- return name === 'fi' && !!attrs && typeof attrs.fid === 'number';
405
- }
406
- trivial(node) {
407
- var limit = 4;
408
- if (node && typeof node.e === 'number' && typeof node.s === 'number' && node.e - node.s < limit) return true;else return false;
409
- }
410
- shouldIgnoreEvent(event, target) {
411
- var origin = this.evtOrigin(event.target, target);
412
- if (event.type in this.ignoredEvents.global) return true;
413
- if (!!this.ignoredEvents[origin] && this.ignoredEvents[origin].ignoreAll) return true;
414
- if (!!this.ignoredEvents[origin] && event.type in this.ignoredEvents[origin]) return true;
415
- return false;
411
+ function trivial(node) {
412
+ const limit = 4;
413
+ if (node && typeof node.e === 'number' && typeof node.s === 'number' && node.e - node.s < limit) return true;else return false;
414
+ }
416
415
  }
417
416
  }
418
417
  exports.Aggregate = Aggregate;
@@ -3,13 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.START = exports.RESOURCE_TIMING_BUFFER_FULL = exports.RESOURCE = exports.PUSH_STATE = exports.ORIG_EVENT = exports.FN_START = exports.FN_END = exports.FEATURE_NAME = exports.END = exports.BST_TIMER = exports.BST_RESOURCE = exports.ADD_EVENT_LISTENER = void 0;
7
- var _config = require("../../common/config/config");
6
+ exports.START = exports.RESOURCE = exports.PUSH_STATE = exports.FN_START = exports.FN_END = exports.FEATURE_NAME = exports.END = exports.BST_TIMER = exports.BST_RESOURCE = void 0;
8
7
  var _features = require("../../loaders/features/features");
9
8
  const FEATURE_NAME = _features.FEATURE_NAMES.sessionTrace;
10
9
  exports.FEATURE_NAME = FEATURE_NAME;
11
- const RESOURCE_TIMING_BUFFER_FULL = 'resourcetimingbufferfull';
12
- exports.RESOURCE_TIMING_BUFFER_FULL = RESOURCE_TIMING_BUFFER_FULL;
13
10
  const BST_RESOURCE = 'bstResource';
14
11
  exports.BST_RESOURCE = BST_RESOURCE;
15
12
  const RESOURCE = 'resource';
@@ -25,8 +22,4 @@ exports.FN_END = FN_END;
25
22
  const BST_TIMER = 'bstTimer';
26
23
  exports.BST_TIMER = BST_TIMER;
27
24
  const PUSH_STATE = 'pushState';
28
- exports.PUSH_STATE = PUSH_STATE;
29
- const ORIG_EVENT = _config.originals.EV;
30
- exports.ORIG_EVENT = ORIG_EVENT;
31
- const ADD_EVENT_LISTENER = 'addEventListener';
32
- exports.ADD_EVENT_LISTENER = ADD_EVENT_LISTENER;
25
+ exports.PUSH_STATE = PUSH_STATE;
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Instrument = void 0;
7
7
  var _handle = require("../../../common/event-emitter/handle");
8
8
  var _wrap = require("../../../common/wrap");
9
- var _supportsPerformanceObserver = require("../../../common/window/supports-performance-observer");
10
- var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
11
9
  var _now = require("../../../common/timing/now");
12
10
  var _instrumentBase = require("../../utils/instrument-base");
13
11
  var CONSTANTS = _interopRequireWildcard(require("../constants"));
@@ -22,19 +20,15 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
22
20
 
23
21
  const {
24
22
  BST_RESOURCE,
23
+ RESOURCE,
25
24
  BST_TIMER,
25
+ START,
26
26
  END,
27
27
  FEATURE_NAME,
28
28
  FN_END,
29
29
  FN_START,
30
- ADD_EVENT_LISTENER,
31
- PUSH_STATE,
32
- RESOURCE,
33
- RESOURCE_TIMING_BUFFER_FULL,
34
- START,
35
- ORIG_EVENT: origEvent
30
+ PUSH_STATE
36
31
  } = CONSTANTS;
37
- const CRT = 'clearResourceTimings';
38
32
  class Instrument extends _instrumentBase.InstrumentBase {
39
33
  static featureName = FEATURE_NAME;
40
34
  constructor(agentIdentifier, aggregator) {
@@ -46,20 +40,14 @@ class Instrument extends _instrumentBase.InstrumentBase {
46
40
  this.timerEE = (0, _wrap.wrapTimer)(thisInstrumentEE);
47
41
  this.rafEE = (0, _wrap.wrapRaf)(thisInstrumentEE);
48
42
  (0, _wrap.wrapHistory)(thisInstrumentEE);
49
- (0, _wrap.wrapEvents)(thisInstrumentEE);
50
- thisInstrumentEE.on(FN_START, function (args, target) {
51
- var evt = args[0];
52
- if (evt instanceof origEvent) {
53
- this.bstStart = (0, _now.now)();
54
- }
43
+ this.eventsEE = (0, _wrap.wrapEvents)(thisInstrumentEE);
44
+ this.eventsEE.on(FN_START, function (args, target) {
45
+ this.bstStart = (0, _now.now)();
55
46
  });
56
- thisInstrumentEE.on(FN_END, function (args, target) {
57
- var evt = args[0];
58
- if (evt instanceof origEvent) {
59
- // ISSUE: when target is XMLHttpRequest, nr@context should have params so we can calculate event origin
60
- // When ajax is disabled, this may fail without making ajax a dependency of session_trace
61
- (0, _handle.handle)('bst', [evt, target, this.bstStart, (0, _now.now)()], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
62
- }
47
+ this.eventsEE.on(FN_END, function (args, target) {
48
+ // ISSUE: when target is XMLHttpRequest, nr@context should have params so we can calculate event origin
49
+ // When ajax is disabled, this may fail without making ajax a dependency of session_trace
50
+ (0, _handle.handle)('bst', [args[0], target, this.bstStart, (0, _now.now)()], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
63
51
  });
64
52
  this.timerEE.on(FN_START, function (args, obj, type) {
65
53
  this.bstStart = (0, _now.now)();
@@ -81,54 +69,24 @@ class Instrument extends _instrumentBase.InstrumentBase {
81
69
  thisInstrumentEE.on(PUSH_STATE + END, function (args) {
82
70
  (0, _handle.handle)('bstHist', [location.pathname + location.hash, this.startPath, this.time], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
83
71
  });
84
- if ((0, _supportsPerformanceObserver.supportsPerformanceObserver)()) {
85
- // capture initial resources, in case our observer missed anything
86
- (0, _handle.handle)(BST_RESOURCE, [window.performance.getEntriesByType('resource')], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
87
- observeResourceTimings();
88
- } else {
89
- // collect resource timings once when buffer is full
90
- if (window.performance[CRT] && window.performance[ADD_EVENT_LISTENER]) {
91
- window.performance.addEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, (0, _eventListenerOpts.eventListenerOpts)(false));
92
- }
93
- }
94
- function observeResourceTimings() {
95
- var observer = new PerformanceObserver((list, observer) => {
72
+ let observer;
73
+ try {
74
+ // Capture initial resources and watch for future ones. Don't defer this given there's a default cap on the number of buffered entries.
75
+ observer = new PerformanceObserver(list => {
96
76
  // eslint-disable-line no-undef
97
- var entries = list.getEntries();
77
+ const entries = list.getEntries();
98
78
  (0, _handle.handle)(BST_RESOURCE, [entries], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
99
79
  });
100
- try {
101
- observer.observe({
102
- entryTypes: ['resource']
103
- });
104
- } catch (e) {
105
- // do nothing
106
- }
107
- }
108
- document.addEventListener('scroll', this.noOp, (0, _eventListenerOpts.eventListenerOpts)(false));
109
- document.addEventListener('keypress', this.noOp, (0, _eventListenerOpts.eventListenerOpts)(false));
110
- document.addEventListener('click', this.noOp, (0, _eventListenerOpts.eventListenerOpts)(false));
111
- this.abortHandler = this.#abort;
112
- this.importAggregator();
113
- }
114
-
115
- /** Restoration and resource release tasks to be done if Session trace loader is being aborted. Unwind changes to globals. */
116
- #abort() {
117
- window.performance.removeEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, false);
118
- // The doc interaction noOp listeners are harmless--cannot buffer data into EE.
119
- this.abortHandler = undefined; // weakly allow this abort op to run only once
120
- }
121
-
122
- noOp(e) {/* no-op */}
123
- onResourceTimingBufferFull(evt) {
124
- (0, _handle.handle)(BST_RESOURCE, [window.performance.getEntriesByType(RESOURCE)], undefined, _features.FEATURE_NAMES.sessionTrace, this.ee);
125
-
126
- // stop recording once buffer is full
127
- if (window.performance[CRT]) {
128
- try {
129
- window.performance.removeEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, false);
130
- } catch (e) {}
80
+ observer.observe({
81
+ type: RESOURCE,
82
+ buffered: true
83
+ });
84
+ } catch (e) {
85
+ // Per NEWRELIC-8525, we don't have a fallback for capturing resources for older versions that don't support PO at this time.
131
86
  }
87
+ this.importAggregator({
88
+ resourceObserver: observer
89
+ });
132
90
  }
133
91
  }
134
92
  exports.Instrument = Instrument;