@newrelic/browser-agent 0.0.9 → 0.1.229

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/README.md +84 -207
  2. package/dist/cjs/cdn/lite.js +14 -0
  3. package/dist/cjs/cdn/polyfills/lite.js +4 -0
  4. package/dist/cjs/cdn/polyfills/pro.js +4 -0
  5. package/dist/cjs/cdn/polyfills/spa.js +4 -0
  6. package/dist/cjs/cdn/polyfills.js +14 -0
  7. package/dist/cjs/cdn/pro.js +19 -0
  8. package/dist/cjs/cdn/spa.js +19 -0
  9. package/dist/cjs/cdn/worker.js +16 -0
  10. package/dist/cjs/common/aggregate/aggregator.js +168 -0
  11. package/dist/cjs/common/browser-version/firefox-version.js +17 -0
  12. package/dist/cjs/common/browser-version/ios-version.js +18 -0
  13. package/dist/cjs/common/config/config.js +76 -0
  14. package/dist/cjs/common/config/state/configurable.js +32 -0
  15. package/dist/cjs/common/config/state/info.js +50 -0
  16. package/dist/cjs/common/config/state/init.js +86 -0
  17. package/dist/cjs/common/config/state/loader-config.js +28 -0
  18. package/dist/cjs/common/config/state/originals.js +9 -0
  19. package/dist/cjs/common/config/state/runtime.js +50 -0
  20. package/dist/cjs/common/constants/environment-variables.js +20 -0
  21. package/dist/cjs/common/context/shared-context.js +25 -0
  22. package/dist/cjs/common/deny-list/deny-list.js +108 -0
  23. package/dist/cjs/common/drain/drain.js +126 -0
  24. package/dist/cjs/common/event-emitter/contextual-ee.js +149 -0
  25. package/dist/cjs/common/event-emitter/handle.js +24 -0
  26. package/dist/cjs/common/event-emitter/register-handler.js +24 -0
  27. package/dist/cjs/common/event-listener/event-listener-opts.js +46 -0
  28. package/dist/cjs/common/harvest/harvest-scheduler.js +111 -0
  29. package/dist/cjs/common/harvest/harvest.js +236 -0
  30. package/dist/cjs/common/ids/id.js +30 -0
  31. package/dist/cjs/common/ids/unique-id.js +84 -0
  32. package/dist/cjs/common/metrics/framework-detection.js +72 -0
  33. package/dist/cjs/common/metrics/paint-metrics.js +13 -0
  34. package/dist/cjs/common/serialize/bel-serializer.js +89 -0
  35. package/dist/cjs/common/timing/nav-timing.js +77 -0
  36. package/dist/cjs/common/timing/now.js +15 -0
  37. package/dist/cjs/common/unload/eol.js +69 -0
  38. package/dist/cjs/common/url/clean-url.js +16 -0
  39. package/dist/cjs/common/url/encode.js +79 -0
  40. package/dist/cjs/common/url/location.js +14 -0
  41. package/dist/cjs/common/url/parse-url.js +66 -0
  42. package/dist/cjs/common/url/protocol.js +25 -0
  43. package/dist/cjs/common/util/console.js +17 -0
  44. package/dist/cjs/common/util/data-size.js +25 -0
  45. package/dist/cjs/common/util/feature-flags.js +42 -0
  46. package/dist/cjs/common/util/get-or-set.js +39 -0
  47. package/dist/cjs/common/util/global-scope.js +56 -0
  48. package/dist/cjs/common/util/map-own.js +24 -0
  49. package/dist/cjs/common/util/obfuscate.js +76 -0
  50. package/dist/cjs/common/util/reduce.js +22 -0
  51. package/dist/cjs/common/util/s-hash.js +19 -0
  52. package/dist/cjs/common/util/single.js +23 -0
  53. package/dist/cjs/common/util/stringify.js +47 -0
  54. package/dist/cjs/common/util/submit-data.js +99 -0
  55. package/dist/cjs/common/util/traverse.js +41 -0
  56. package/dist/cjs/common/util/user-agent.js +57 -0
  57. package/dist/cjs/common/window/load.js +19 -0
  58. package/dist/cjs/common/window/nreum.js +107 -0
  59. package/dist/cjs/common/window/page-visibility.js +28 -0
  60. package/dist/cjs/common/window/session-storage.js +42 -0
  61. package/dist/cjs/common/window/supports-performance-observer.js +15 -0
  62. package/dist/cjs/common/window/top-level-callers.js +23 -0
  63. package/dist/cjs/common/wrap/index.js +68 -0
  64. package/dist/cjs/common/wrap/wrap-events.js +105 -0
  65. package/dist/cjs/common/wrap/wrap-fetch.js +114 -0
  66. package/dist/cjs/common/wrap/wrap-function.js +269 -0
  67. package/dist/cjs/common/wrap/wrap-history.js +56 -0
  68. package/dist/cjs/common/wrap/wrap-jsonp.js +129 -0
  69. package/dist/cjs/common/wrap/wrap-mutation.js +61 -0
  70. package/dist/cjs/common/wrap/wrap-promise.js +160 -0
  71. package/dist/cjs/common/wrap/wrap-raf.js +55 -0
  72. package/dist/cjs/common/wrap/wrap-timer.js +70 -0
  73. package/dist/cjs/common/wrap/wrap-xhr.js +206 -0
  74. package/dist/cjs/features/ajax/aggregate/index.js +226 -0
  75. package/dist/cjs/features/ajax/constants.js +9 -0
  76. package/dist/cjs/features/ajax/index.js +12 -0
  77. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +145 -0
  78. package/dist/cjs/features/ajax/instrument/index.js +338 -0
  79. package/dist/cjs/features/ajax/instrument/response-size.js +26 -0
  80. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +18 -0
  81. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +30 -0
  82. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +216 -0
  83. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +257 -0
  84. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.js +36 -0
  85. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +39 -0
  86. package/dist/cjs/features/jserrors/aggregate/index.js +267 -0
  87. package/dist/cjs/features/jserrors/aggregate/string-hash-code.js +23 -0
  88. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +26 -0
  89. package/dist/cjs/features/jserrors/constants.js +11 -0
  90. package/dist/cjs/features/jserrors/index.js +12 -0
  91. package/dist/cjs/features/jserrors/instrument/debug.js +40 -0
  92. package/dist/cjs/features/jserrors/instrument/index.js +158 -0
  93. package/dist/cjs/features/metrics/aggregate/index.js +136 -0
  94. package/dist/cjs/features/metrics/constants.js +17 -0
  95. package/dist/cjs/features/metrics/index.js +12 -0
  96. package/dist/cjs/features/metrics/instrument/index.js +20 -0
  97. package/dist/cjs/features/metrics/instrument/workers-helper.js +121 -0
  98. package/dist/cjs/features/page_action/aggregate/index.js +112 -0
  99. package/dist/cjs/features/page_action/constants.js +9 -0
  100. package/dist/cjs/features/page_action/index.js +12 -0
  101. package/dist/cjs/features/page_action/instrument/index.js +21 -0
  102. package/dist/cjs/features/page_view_event/aggregate/index.js +133 -0
  103. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +39 -0
  104. package/dist/cjs/features/page_view_event/constants.js +15 -0
  105. package/dist/cjs/features/page_view_event/index.js +12 -0
  106. package/dist/cjs/features/page_view_event/instrument/index.js +38 -0
  107. package/dist/cjs/features/page_view_timing/aggregate/index.js +265 -0
  108. package/dist/cjs/features/page_view_timing/constants.js +9 -0
  109. package/dist/cjs/features/page_view_timing/first-paint.js +50 -0
  110. package/dist/cjs/features/page_view_timing/index.js +12 -0
  111. package/dist/cjs/features/page_view_timing/instrument/index.js +36 -0
  112. package/dist/cjs/features/page_view_timing/long-tasks.js +75 -0
  113. package/dist/cjs/features/session_trace/aggregate/index.js +375 -0
  114. package/dist/cjs/features/session_trace/constants.js +32 -0
  115. package/dist/cjs/features/session_trace/index.js +12 -0
  116. package/dist/cjs/features/session_trace/instrument/index.js +133 -0
  117. package/dist/cjs/features/spa/aggregate/index.js +684 -0
  118. package/dist/cjs/features/spa/aggregate/interaction-node.js +84 -0
  119. package/dist/cjs/features/spa/aggregate/interaction-node.test.js +16 -0
  120. package/dist/cjs/features/spa/aggregate/interaction.js +98 -0
  121. package/dist/cjs/features/spa/aggregate/serializer.js +147 -0
  122. package/dist/cjs/features/spa/constants.js +53 -0
  123. package/dist/cjs/features/spa/index.js +12 -0
  124. package/dist/cjs/features/spa/instrument/index.js +114 -0
  125. package/dist/cjs/features/utils/aggregate-base.js +13 -0
  126. package/dist/cjs/features/utils/feature-base.js +58 -0
  127. package/dist/cjs/features/utils/handler-cache.js +64 -0
  128. package/dist/cjs/features/utils/instrument-base.js +71 -0
  129. package/dist/cjs/features/utils/lazy-loader.js +44 -0
  130. package/dist/cjs/index.js +81 -58
  131. package/dist/cjs/loaders/agent.js +86 -0
  132. package/dist/cjs/loaders/api/api.js +109 -0
  133. package/dist/cjs/loaders/api/apiAsync.js +94 -0
  134. package/dist/cjs/loaders/browser-agent.js +29 -0
  135. package/dist/cjs/loaders/configure/configure.js +47 -0
  136. package/dist/cjs/loaders/features/enabled-features.js +19 -0
  137. package/dist/cjs/loaders/features/featureDependencies.js +32 -0
  138. package/dist/cjs/loaders/features/features.js +33 -0
  139. package/dist/cjs/loaders/micro-agent.js +93 -0
  140. package/dist/cjs/loaders/worker-agent.js +24 -0
  141. package/dist/esm/cdn/lite.js +12 -0
  142. package/dist/esm/cdn/polyfills/lite.js +7 -0
  143. package/dist/esm/cdn/polyfills/pro.js +7 -0
  144. package/dist/esm/cdn/polyfills/spa.js +7 -0
  145. package/dist/esm/cdn/polyfills.js +17 -0
  146. package/dist/esm/cdn/pro.js +17 -0
  147. package/dist/esm/cdn/spa.js +17 -0
  148. package/dist/esm/cdn/worker.js +14 -0
  149. package/dist/esm/common/aggregate/aggregator.js +161 -0
  150. package/dist/esm/common/browser-version/firefox-version.js +10 -0
  151. package/dist/esm/common/browser-version/ios-version.js +10 -0
  152. package/dist/esm/common/config/config.js +11 -0
  153. package/dist/esm/common/config/state/configurable.js +25 -0
  154. package/dist/esm/common/config/state/info.js +42 -0
  155. package/dist/esm/common/config/state/init.js +78 -0
  156. package/dist/esm/common/config/state/loader-config.js +21 -0
  157. package/dist/esm/common/config/state/originals.js +2 -0
  158. package/dist/esm/common/config/state/runtime.js +41 -0
  159. package/dist/esm/common/constants/environment-variables.js +11 -0
  160. package/dist/esm/common/context/shared-context.js +18 -0
  161. package/dist/esm/common/deny-list/deny-list.js +101 -0
  162. package/dist/esm/common/drain/drain.js +119 -0
  163. package/dist/esm/common/event-emitter/contextual-ee.js +142 -0
  164. package/dist/esm/common/event-emitter/handle.js +16 -0
  165. package/dist/esm/common/event-emitter/register-handler.js +19 -0
  166. package/dist/esm/common/event-listener/event-listener-opts.js +39 -0
  167. package/dist/esm/common/harvest/harvest-scheduler.js +105 -0
  168. package/dist/esm/common/harvest/harvest.js +228 -0
  169. package/dist/esm/common/ids/id.js +23 -0
  170. package/dist/esm/common/ids/unique-id.js +75 -0
  171. package/dist/esm/common/metrics/framework-detection.js +66 -0
  172. package/dist/esm/common/metrics/paint-metrics.js +6 -0
  173. package/dist/esm/common/serialize/bel-serializer.js +80 -0
  174. package/dist/esm/common/timing/nav-timing.js +67 -0
  175. package/dist/esm/common/timing/now.js +9 -0
  176. package/dist/esm/common/unload/eol.js +62 -0
  177. package/dist/esm/common/url/clean-url.js +10 -0
  178. package/dist/esm/common/url/encode.js +71 -0
  179. package/dist/esm/common/url/location.js +8 -0
  180. package/dist/esm/common/url/parse-url.js +60 -0
  181. package/dist/esm/common/url/protocol.js +17 -0
  182. package/dist/esm/common/util/console.js +11 -0
  183. package/dist/esm/common/util/data-size.js +19 -0
  184. package/dist/esm/common/util/feature-flags.js +33 -0
  185. package/dist/esm/common/util/get-or-set.js +33 -0
  186. package/dist/esm/common/util/global-scope.js +44 -0
  187. package/dist/esm/common/util/map-own.js +18 -0
  188. package/dist/esm/common/util/obfuscate.js +67 -0
  189. package/dist/esm/common/util/reduce.js +16 -0
  190. package/dist/esm/common/util/s-hash.js +13 -0
  191. package/dist/esm/common/util/single.js +16 -0
  192. package/dist/esm/common/util/stringify.js +42 -0
  193. package/dist/esm/common/util/submit-data.js +91 -0
  194. package/dist/esm/common/util/traverse.js +35 -0
  195. package/dist/esm/common/util/user-agent.js +48 -0
  196. package/dist/esm/common/window/load.js +12 -0
  197. package/dist/esm/common/window/nreum.js +91 -0
  198. package/dist/esm/common/window/page-visibility.js +23 -0
  199. package/dist/esm/common/window/session-storage.js +36 -0
  200. package/dist/esm/common/window/supports-performance-observer.js +9 -0
  201. package/dist/esm/common/window/top-level-callers.js +17 -0
  202. package/dist/esm/common/wrap/index.js +14 -0
  203. package/dist/esm/common/wrap/wrap-events.js +97 -0
  204. package/dist/esm/common/wrap/wrap-fetch.js +105 -0
  205. package/dist/esm/common/wrap/wrap-function.js +257 -0
  206. package/dist/esm/common/wrap/wrap-history.js +48 -0
  207. package/dist/esm/common/wrap/wrap-jsonp.js +122 -0
  208. package/dist/esm/common/wrap/wrap-mutation.js +54 -0
  209. package/dist/esm/common/wrap/wrap-promise.js +153 -0
  210. package/dist/esm/common/wrap/wrap-raf.js +48 -0
  211. package/dist/esm/common/wrap/wrap-timer.js +63 -0
  212. package/dist/esm/common/wrap/wrap-xhr.js +199 -0
  213. package/dist/esm/features/ajax/aggregate/index.js +218 -0
  214. package/dist/esm/features/ajax/constants.js +2 -0
  215. package/dist/esm/features/ajax/index.js +1 -0
  216. package/dist/esm/features/ajax/instrument/distributed-tracing.js +137 -0
  217. package/dist/esm/features/ajax/instrument/index.js +330 -0
  218. package/dist/esm/features/ajax/instrument/response-size.js +19 -0
  219. package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +12 -0
  220. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +28 -0
  221. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +209 -0
  222. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +255 -0
  223. package/dist/esm/features/jserrors/aggregate/format-stack-trace.js +29 -0
  224. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +37 -0
  225. package/dist/esm/features/jserrors/aggregate/index.js +260 -0
  226. package/dist/esm/features/jserrors/aggregate/string-hash-code.js +17 -0
  227. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +24 -0
  228. package/dist/esm/features/jserrors/constants.js +3 -0
  229. package/dist/esm/features/jserrors/index.js +1 -0
  230. package/dist/esm/features/jserrors/instrument/debug.js +38 -0
  231. package/dist/esm/features/jserrors/instrument/index.js +150 -0
  232. package/dist/esm/features/metrics/aggregate/index.js +129 -0
  233. package/dist/esm/features/metrics/constants.js +6 -0
  234. package/dist/esm/features/metrics/index.js +1 -0
  235. package/dist/esm/features/metrics/instrument/index.js +13 -0
  236. package/dist/esm/features/metrics/instrument/workers-helper.js +116 -0
  237. package/dist/esm/features/page_action/aggregate/index.js +105 -0
  238. package/dist/esm/features/page_action/constants.js +2 -0
  239. package/dist/esm/features/page_action/index.js +1 -0
  240. package/dist/esm/features/page_action/instrument/index.js +14 -0
  241. package/dist/esm/features/page_view_event/aggregate/index.js +124 -0
  242. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +34 -0
  243. package/dist/esm/features/page_view_event/constants.js +5 -0
  244. package/dist/esm/features/page_view_event/index.js +1 -0
  245. package/dist/esm/features/page_view_event/instrument/index.js +29 -0
  246. package/dist/esm/features/page_view_timing/aggregate/index.js +258 -0
  247. package/dist/esm/features/page_view_timing/constants.js +2 -0
  248. package/dist/esm/features/page_view_timing/first-paint.js +43 -0
  249. package/dist/esm/features/page_view_timing/index.js +1 -0
  250. package/dist/esm/features/page_view_timing/instrument/index.js +28 -0
  251. package/dist/esm/features/page_view_timing/long-tasks.js +69 -0
  252. package/dist/esm/features/session_trace/aggregate/index.js +366 -0
  253. package/dist/esm/features/session_trace/constants.js +14 -0
  254. package/dist/esm/features/session_trace/index.js +1 -0
  255. package/dist/esm/features/session_trace/instrument/index.js +123 -0
  256. package/dist/esm/features/spa/aggregate/index.js +674 -0
  257. package/dist/esm/features/spa/aggregate/interaction-node.js +78 -0
  258. package/dist/esm/features/spa/aggregate/interaction-node.test.js +14 -0
  259. package/dist/esm/features/spa/aggregate/interaction.js +92 -0
  260. package/dist/esm/features/spa/aggregate/serializer.js +139 -0
  261. package/dist/esm/features/spa/constants.js +25 -0
  262. package/dist/esm/features/spa/index.js +1 -0
  263. package/dist/esm/features/spa/instrument/index.js +104 -0
  264. package/dist/esm/features/utils/aggregate-base.js +6 -0
  265. package/dist/esm/features/utils/feature-base.js +51 -0
  266. package/dist/esm/features/utils/handler-cache.js +57 -0
  267. package/dist/esm/features/utils/instrument-base.js +69 -0
  268. package/dist/esm/features/utils/lazy-loader.js +37 -0
  269. package/dist/esm/index.js +15 -0
  270. package/dist/esm/loaders/agent.js +77 -0
  271. package/dist/esm/loaders/api/api.js +104 -0
  272. package/dist/esm/loaders/api/apiAsync.js +88 -0
  273. package/dist/esm/loaders/browser-agent.js +23 -0
  274. package/dist/esm/loaders/configure/configure.js +41 -0
  275. package/dist/esm/loaders/features/enabled-features.js +13 -0
  276. package/dist/esm/loaders/features/featureDependencies.js +25 -0
  277. package/dist/esm/loaders/features/features.js +25 -0
  278. package/dist/esm/loaders/micro-agent.js +86 -0
  279. package/dist/esm/loaders/worker-agent.js +18 -0
  280. package/package.json +204 -71
  281. package/types.ts +221 -0
  282. package/dist/bundled/es5/index.js +0 -2
  283. package/dist/bundled/es5/index.js.map +0 -1
  284. package/dist/bundled/es6/index.js +0 -2
  285. package/dist/bundled/es6/index.js.map +0 -1
  286. package/dist/cjs/index.d.ts +0 -19
  287. package/dist/cjs/index.js.map +0 -1
  288. package/dist/cjs/types.d.ts +0 -94
  289. package/dist/cjs/types.js +0 -28
  290. package/dist/cjs/types.js.map +0 -1
  291. package/dist/cjs/utils/api/api.d.ts +0 -10
  292. package/dist/cjs/utils/api/api.js +0 -40
  293. package/dist/cjs/utils/api/api.js.map +0 -1
  294. package/dist/cjs/utils/config/build-configs.d.ts +0 -6
  295. package/dist/cjs/utils/config/build-configs.js +0 -68
  296. package/dist/cjs/utils/config/build-configs.js.map +0 -1
  297. package/dist/cjs/utils/features/features.d.ts +0 -5
  298. package/dist/cjs/utils/features/features.js +0 -14
  299. package/dist/cjs/utils/features/features.js.map +0 -1
  300. package/dist/cjs/utils/features/initialize.d.ts +0 -5
  301. package/dist/cjs/utils/features/initialize.js +0 -51
  302. package/dist/cjs/utils/features/initialize.js.map +0 -1
  303. package/dist/es/index.d.ts +0 -19
  304. package/dist/es/index.js +0 -55
  305. package/dist/es/index.js.map +0 -1
  306. package/dist/es/types.d.ts +0 -94
  307. package/dist/es/types.js +0 -24
  308. package/dist/es/types.js.map +0 -1
  309. package/dist/es/utils/api/api.d.ts +0 -10
  310. package/dist/es/utils/api/api.js +0 -36
  311. package/dist/es/utils/api/api.js.map +0 -1
  312. package/dist/es/utils/config/build-configs.d.ts +0 -6
  313. package/dist/es/utils/config/build-configs.js +0 -64
  314. package/dist/es/utils/config/build-configs.js.map +0 -1
  315. package/dist/es/utils/features/features.d.ts +0 -5
  316. package/dist/es/utils/features/features.js +0 -10
  317. package/dist/es/utils/features/features.js.map +0 -1
  318. package/dist/es/utils/features/initialize.d.ts +0 -5
  319. package/dist/es/utils/features/initialize.js +0 -24
  320. package/dist/es/utils/features/initialize.js.map +0 -1
  321. package/dist/umd/index.d.ts +0 -19
  322. package/dist/umd/index.js +0 -69
  323. package/dist/umd/index.js.map +0 -1
  324. package/dist/umd/types.d.ts +0 -94
  325. package/dist/umd/types.js +0 -38
  326. package/dist/umd/types.js.map +0 -1
  327. package/dist/umd/utils/api/api.d.ts +0 -10
  328. package/dist/umd/utils/api/api.js +0 -50
  329. package/dist/umd/utils/api/api.js.map +0 -1
  330. package/dist/umd/utils/config/build-configs.d.ts +0 -6
  331. package/dist/umd/utils/config/build-configs.js +0 -78
  332. package/dist/umd/utils/config/build-configs.js.map +0 -1
  333. package/dist/umd/utils/features/features.d.ts +0 -5
  334. package/dist/umd/utils/features/features.js +0 -24
  335. package/dist/umd/utils/features/features.js.map +0 -1
  336. package/dist/umd/utils/features/initialize.d.ts +0 -5
  337. package/dist/umd/utils/features/initialize.js +0 -63
  338. package/dist/umd/utils/features/initialize.js.map +0 -1
  339. package/dist/webpack-analysis.html +0 -38
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Aggregate = void 0;
7
+ var _handle = require("../../../common/event-emitter/handle");
8
+ var _features = require("../../../loaders/features/features");
9
+ var _iosVersion = require("../../../common/browser-version/ios-version");
10
+ var _webVitals = require("web-vitals");
11
+ var _mapOwn = require("../../../common/util/map-own");
12
+ var _encode = require("../../../common/url/encode");
13
+ var _navTiming = require("../../../common/timing/nav-timing");
14
+ var _stringify = require("../../../common/util/stringify");
15
+ var _paintMetrics = require("../../../common/metrics/paint-metrics");
16
+ var _submitData = require("../../../common/util/submit-data");
17
+ var _config = require("../../../common/config/config");
18
+ var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
19
+ var _aggregateBase = require("../../utils/aggregate-base");
20
+ var CONSTANTS = _interopRequireWildcard(require("../constants"));
21
+ var _initializedFeatures = require("./initialized-features");
22
+ var _globalScope = require("../../../common/util/global-scope");
23
+ var _drain = require("../../../common/drain/drain");
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
+ const jsonp = 'NREUM.setToken';
27
+ class Aggregate extends _aggregateBase.AggregateBase {
28
+ static featureName = CONSTANTS.FEATURE_NAME;
29
+ constructor(agentIdentifier, aggregator) {
30
+ super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME);
31
+ if (typeof PerformanceNavigationTiming !== 'undefined' && !_iosVersion.isiOS) {
32
+ this.alreadySent = false; // we don't support timings on BFCache restores
33
+ const agentRuntime = (0, _config.getRuntime)(agentIdentifier); // we'll store timing values on the runtime obj to be read by the aggregate module
34
+
35
+ /* Time To First Byte
36
+ This listener must record these values *before* PVE's aggregate sends RUM. */
37
+ (0, _webVitals.onTTFB)(({
38
+ value,
39
+ entries
40
+ }) => {
41
+ if (this.alreadySent) return;
42
+ this.alreadySent = true;
43
+ agentRuntime[CONSTANTS.TTFB] = Math.round(value); // this is our "backend" duration; web-vitals will ensure it's lower bounded at 0
44
+
45
+ // Similar to what vitals does for ttfb, we have to factor in activation-start when calculating relative timings:
46
+ const navEntry = entries[0];
47
+ const respOrActivStart = Math.max(navEntry.responseStart, navEntry.activationStart || 0);
48
+ agentRuntime[CONSTANTS.FBTWL] = Math.max(Math.round(navEntry.loadEventEnd - respOrActivStart), 0); // our "frontend" duration
49
+ (0, _handle.handle)('timing', ['load', Math.round(navEntry.loadEventEnd)], undefined, _features.FEATURE_NAMES.pageViewTiming, this.ee);
50
+ agentRuntime[CONSTANTS.FBTDC] = Math.max(Math.round(navEntry.domContentLoadedEventEnd - respOrActivStart), 0); // our "dom processing" duration
51
+
52
+ this.sendRum();
53
+ });
54
+ } else {
55
+ this.sendRum(); // timings either already in runtime from instrument or is meant to get 0'd.
56
+ }
57
+ }
58
+
59
+ getScheme() {
60
+ return (0, _config.getConfigurationValue)(this.agentIdentifier, 'ssl') === false ? 'http' : 'https';
61
+ }
62
+ sendRum() {
63
+ const info = (0, _config.getInfo)(this.agentIdentifier);
64
+ if (!info.beacon) return;
65
+ if (info.queueTime) this.aggregator.store('measures', 'qt', {
66
+ value: info.queueTime
67
+ });
68
+ if (info.applicationTime) this.aggregator.store('measures', 'ap', {
69
+ value: info.applicationTime
70
+ });
71
+ const agentRuntime = (0, _config.getRuntime)(this.agentIdentifier);
72
+
73
+ // These 3 values should've been recorded after load and before this func runs. They are part of the minimum required for PageView events to be created.
74
+ // Following PR #428, which demands that all agents send RUM call, these need to be sent even outside of the main window context where PerformanceTiming
75
+ // or PerformanceNavigationTiming do not exists. Hence, they'll be filled in by 0s instead in, for example, worker threads that still init the PVE module.
76
+ this.aggregator.store('measures', 'be', {
77
+ value: _globalScope.isBrowserScope ? agentRuntime[CONSTANTS.TTFB] : 0
78
+ });
79
+ this.aggregator.store('measures', 'fe', {
80
+ value: _globalScope.isBrowserScope ? agentRuntime[CONSTANTS.FBTWL] : 0
81
+ });
82
+ this.aggregator.store('measures', 'dc', {
83
+ value: _globalScope.isBrowserScope ? agentRuntime[CONSTANTS.FBTDC] : 0
84
+ });
85
+ var measuresMetrics = this.aggregator.get('measures');
86
+ var measuresQueryString = (0, _mapOwn.mapOwn)(measuresMetrics, function (metricName, measure) {
87
+ return '&' + metricName + '=' + measure.params.value;
88
+ }).join('');
89
+
90
+ // currently we only have one version of our protocol
91
+ // in the future we may add more
92
+ var protocol = '1';
93
+ var scheduler = new _harvestScheduler.HarvestScheduler('page_view_event', {}, this);
94
+ var chunksForQueryString = [scheduler.harvest.baseQueryString()];
95
+ chunksForQueryString.push(measuresQueryString);
96
+ chunksForQueryString.push((0, _encode.param)('tt', info.ttGuid));
97
+ chunksForQueryString.push((0, _encode.param)('us', info.user));
98
+ chunksForQueryString.push((0, _encode.param)('ac', info.account));
99
+ chunksForQueryString.push((0, _encode.param)('pr', info.product));
100
+ chunksForQueryString.push((0, _encode.param)('af', (0, _initializedFeatures.getActivatedFeaturesFlags)(this.agentIdentifier).join(',')));
101
+ if (_globalScope.globalScope.performance && typeof _globalScope.globalScope.performance.timing !== 'undefined') {
102
+ var navTimingApiData = {
103
+ timing: (0, _navTiming.addPT)(agentRuntime.offset, _globalScope.globalScope.performance.timing, {}),
104
+ navigation: (0, _navTiming.addPN)(_globalScope.globalScope.performance.navigation, {})
105
+ };
106
+ chunksForQueryString.push((0, _encode.param)('perf', (0, _stringify.stringify)(navTimingApiData)));
107
+ }
108
+ try {
109
+ // PVTiming sends these too, albeit using web-vitals and slightly different; it's unknown why they're duplicated, but PVT should be the truth
110
+ var entries = _globalScope.globalScope.performance.getEntriesByType('paint');
111
+ entries.forEach(function (entry) {
112
+ if (!entry.startTime || entry.startTime <= 0) return;
113
+ if (entry.name === 'first-paint') {
114
+ chunksForQueryString.push((0, _encode.param)('fp', String(Math.floor(entry.startTime))));
115
+ } else if (entry.name === 'first-contentful-paint') {
116
+ chunksForQueryString.push((0, _encode.param)('fcp', String(Math.floor(entry.startTime))));
117
+ }
118
+ _paintMetrics.paintMetrics[entry.name] = Math.floor(entry.startTime); // this is consumed by Spa module
119
+ });
120
+ } catch (e) {}
121
+ chunksForQueryString.push((0, _encode.param)('xx', info.extra));
122
+ chunksForQueryString.push((0, _encode.param)('ua', info.userAttributes));
123
+ chunksForQueryString.push((0, _encode.param)('at', info.atts));
124
+ var customJsAttributes = (0, _stringify.stringify)(info.jsAttributes);
125
+ chunksForQueryString.push((0, _encode.param)('ja', customJsAttributes === '{}' ? null : customJsAttributes));
126
+ var queryString = (0, _encode.fromArray)(chunksForQueryString, agentRuntime.maxBytes);
127
+ const isValidJsonp = _submitData.submitData.jsonp(this.getScheme() + '://' + info.beacon + '/' + protocol + '/' + info.licenseKey + queryString, jsonp);
128
+ // Usually `drain` is invoked automatically after processing feature flags contained in the JSONP callback from
129
+ // ingest (see `activateFeatures`), so when JSONP cannot execute (as with module workers), we drain manually.
130
+ if (!isValidJsonp) (0, _drain.drain)(this.agentIdentifier, CONSTANTS.FEATURE_NAME);
131
+ }
132
+ }
133
+ exports.Aggregate = Aggregate;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getActivatedFeaturesFlags = getActivatedFeaturesFlags;
7
+ var _features = require("../../../loaders/features/features");
8
+ /**
9
+ * Get an array of flags required by downstream (NR UI) based on the features initialized in this agent
10
+ * (aka what is running on the page).
11
+ * @param {String} agentId - the ID of the initialized agent on the page, mapping to the one under the global 'newrelic' object
12
+ * @returns {String[]} Up to 5 short strings corresponding to ingest mapping of features.
13
+ */
14
+ function getActivatedFeaturesFlags(agentId) {
15
+ const flagArr = [];
16
+ Object.keys(newrelic.initializedAgents[agentId].features).forEach(featName => {
17
+ switch (featName) {
18
+ case _features.FEATURE_NAMES.ajax:
19
+ flagArr.push('xhr');
20
+ break;
21
+ case _features.FEATURE_NAMES.jserrors:
22
+ flagArr.push('err');
23
+ break;
24
+ case _features.FEATURE_NAMES.pageAction:
25
+ flagArr.push('ins');
26
+ break;
27
+ case _features.FEATURE_NAMES.sessionTrace:
28
+ flagArr.push('stn');
29
+ break;
30
+ case _features.FEATURE_NAMES.spa:
31
+ flagArr.push('spa');
32
+ break;
33
+ }
34
+ });
35
+ return flagArr;
36
+ }
37
+
38
+ // Note: this module and the "af" param in src/features/page_view_event/aggregate/index.js can be removed in the future at such time
39
+ // that it's no longer being used. For the browser agent, this is an unused flag system.
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TTFB = exports.FEATURE_NAME = exports.FBTWL = exports.FBTDC = void 0;
7
+ var _features = require("../../loaders/features/features");
8
+ const FEATURE_NAME = _features.FEATURE_NAMES.pageViewEvent;
9
+ exports.FEATURE_NAME = FEATURE_NAME;
10
+ const TTFB = 'firstbyte';
11
+ exports.TTFB = TTFB;
12
+ const FBTDC = 'domcontent';
13
+ exports.FBTDC = FBTDC;
14
+ const FBTWL = 'windowload';
15
+ exports.FBTWL = FBTWL;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "PageViewEvent", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _index.Instrument;
10
+ }
11
+ });
12
+ var _index = require("./instrument/index");
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Instrument = void 0;
7
+ var _handle = require("../../../common/event-emitter/handle");
8
+ var _iosVersion = require("../../../common/browser-version/ios-version");
9
+ var _instrumentBase = require("../../utils/instrument-base");
10
+ var CONSTANTS = _interopRequireWildcard(require("../constants"));
11
+ var _features = require("../../../loaders/features/features");
12
+ var _config = require("../../../common/config/config");
13
+ var _load = require("../../../common/window/load");
14
+ var _now = require("../../../common/timing/now");
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+ class Instrument extends _instrumentBase.InstrumentBase {
18
+ static featureName = CONSTANTS.FEATURE_NAME;
19
+ constructor(agentIdentifier, aggregator, auto = true) {
20
+ super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME, auto);
21
+ if ((typeof PerformanceNavigationTiming === 'undefined' || _iosVersion.isiOS) && typeof PerformanceTiming !== 'undefined') {
22
+ // For majority browser versions in which PNT exists, we can get load timings later from the nav entry (in the aggregate portion). At minimum, PT should exist for main window.
23
+ // *cli Mar'23 - iOS 15.2 & 15.4 testing in Sauce still fails with onTTFB. Hence, all iOS will fallback to this for now. Unknown if this is similar in nature to iOS_below16 bug.
24
+ const agentRuntime = (0, _config.getRuntime)(agentIdentifier);
25
+ agentRuntime[CONSTANTS.TTFB] = Math.max(Date.now() - agentRuntime.offset, 0);
26
+ (0, _load.onDOMContentLoaded)(() => agentRuntime[CONSTANTS.FBTDC] = Math.max((0, _now.now)() - agentRuntime[CONSTANTS.TTFB], 0));
27
+ (0, _load.onWindowLoad)(() => {
28
+ const timeNow = (0, _now.now)();
29
+ agentRuntime[CONSTANTS.FBTWL] = Math.max(timeNow - agentRuntime[CONSTANTS.TTFB], 0);
30
+ (0, _handle.handle)('timing', ['load', timeNow], undefined, _features.FEATURE_NAMES.pageViewTiming, this.ee);
31
+ });
32
+ }
33
+ // Else, inference: inside worker or some other env where these events are irrelevant. They'll get filled in with 0s in RUM call.
34
+
35
+ this.importAggregator();
36
+ }
37
+ }
38
+ exports.Instrument = Instrument;
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Aggregate = void 0;
7
+ var _webVitals = require("web-vitals");
8
+ var _firstPaint = require("../first-paint");
9
+ var _longTasks = require("../long-tasks");
10
+ var _iosVersion = require("../../../common/browser-version/ios-version");
11
+ var _belSerializer = require("../../../common/serialize/bel-serializer");
12
+ var _mapOwn = require("../../../common/util/map-own");
13
+ var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
14
+ var _registerHandler = require("../../../common/event-emitter/register-handler");
15
+ var _cleanUrl = require("../../../common/url/clean-url");
16
+ var _handle = require("../../../common/event-emitter/handle");
17
+ var _config = require("../../../common/config/config");
18
+ var _aggregateBase = require("../../utils/aggregate-base");
19
+ var _constants = require("../constants");
20
+ var _drain = require("../../../common/drain/drain");
21
+ var _features = require("../../../loaders/features/features");
22
+ /*
23
+ * Copyright 2020 New Relic Corporation. All rights reserved.
24
+ * SPDX-License-Identifier: Apache-2.0
25
+ */
26
+
27
+ class Aggregate extends _aggregateBase.AggregateBase {
28
+ static featureName = _constants.FEATURE_NAME;
29
+ constructor(agentIdentifier, aggregator) {
30
+ super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
31
+ this.timings = [];
32
+ this.timingsSent = [];
33
+ this.curSessEndRecorded = false;
34
+ try {
35
+ // we (only) need to track cls state because it's attached to other timing events rather than reported on change...
36
+ this.clsSupported = PerformanceObserver.supportedEntryTypes.includes('layout-shift');
37
+ this.cls = 0;
38
+ } catch (e) {}
39
+
40
+ /*! This is the section that used to be in the loader portion: !*/
41
+ /* ------------------------------------------------------------ */
42
+ const pageStartedHidden = (0, _config.getRuntime)(agentIdentifier).initHidden; // our attempt at recapturing initial vis state since this code runs post-load time
43
+ this.alreadySent = new Set(); // since we don't support timings on BFCache restores, this tracks and helps cap metrics that web-vitals report more than once
44
+
45
+ /* PerformancePaintTiming API - BFC is not yet supported. */
46
+ (0, _firstPaint.onFirstPaint)(({
47
+ name,
48
+ value
49
+ }) => {
50
+ if (pageStartedHidden) return;
51
+ this.addTiming(name.toLowerCase(), Math.floor(value));
52
+ });
53
+
54
+ /* First Contentful Paint - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
55
+ if (_iosVersion.iOS_below16) {
56
+ try {
57
+ if (!pageStartedHidden) {
58
+ // see ios-version.js for detail on this following bug case; tldr: buffered flag doesn't work but getEntriesByType does
59
+ const paintEntries = performance.getEntriesByType('paint');
60
+ paintEntries.forEach(entry => {
61
+ if (entry.name === 'first-contentful-paint') {
62
+ this.addTiming('fcp', Math.floor(entry.startTime));
63
+ }
64
+ });
65
+ }
66
+ } catch (e) {}
67
+ } else {
68
+ (0, _webVitals.onFCP)(({
69
+ name,
70
+ value
71
+ }) => {
72
+ if (pageStartedHidden || this.alreadySent.has(name)) return;
73
+ this.alreadySent.add(name);
74
+ this.addTiming(name.toLowerCase(), value);
75
+ });
76
+ }
77
+
78
+ /* First Input Delay (+"First Interaction") - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
79
+ (0, _webVitals.onFID)(({
80
+ name,
81
+ value,
82
+ entries
83
+ }) => {
84
+ if (pageStartedHidden || this.alreadySent.has(name)) return;
85
+ this.alreadySent.add(name);
86
+
87
+ // CWV will only report one (THE) first-input entry to us; fid isn't reported if there are no user interactions occurs before the *first* page hiding.
88
+ const fiEntry = entries[0];
89
+ const attributes = {
90
+ type: fiEntry.name,
91
+ fid: Math.round(value)
92
+ };
93
+ this.addConnectionAttributes(attributes);
94
+ this.addTiming('fi', Math.round(fiEntry.startTime), attributes);
95
+ });
96
+
97
+ /* Largest Contentful Paint - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
98
+ (0, _webVitals.onLCP)(({
99
+ name,
100
+ value,
101
+ entries
102
+ }) => {
103
+ if (pageStartedHidden || this.alreadySent.has(name)) return;
104
+ this.alreadySent.add(name);
105
+
106
+ // CWV will only ever report one (THE) lcp entry to us; lcp is also only reported *once* on earlier(user interaction, page hidden).
107
+ const lcpEntry = entries[entries.length - 1]; // this looks weird if we only expect one, but this is how cwv-attribution gets it so to be sure...
108
+ const attrs = {
109
+ size: lcpEntry.size,
110
+ eid: lcpEntry.id
111
+ };
112
+ this.addConnectionAttributes(attrs);
113
+ if (lcpEntry.url) {
114
+ attrs['elUrl'] = (0, _cleanUrl.cleanURL)(lcpEntry.url);
115
+ }
116
+ if (lcpEntry.element && lcpEntry.element.tagName) {
117
+ attrs['elTag'] = lcpEntry.element.tagName;
118
+ }
119
+ this.addTiming(name.toLowerCase(), value, attrs);
120
+ });
121
+
122
+ /* Cumulative Layout Shift - We don't have to limit this callback since cls is stored as a state and only sent as attribute on other timings. */
123
+ (0, _webVitals.onCLS)(({
124
+ value
125
+ }) => this.cls = value);
126
+
127
+ /* Interaction-to-Next-Paint */
128
+ (0, _webVitals.onINP)(({
129
+ name,
130
+ value,
131
+ id
132
+ }) => this.addTiming(name.toLowerCase(), value, {
133
+ metricId: id
134
+ }));
135
+
136
+ /* PerformanceLongTaskTiming API */
137
+ if ((0, _config.getConfigurationValue)(this.agentIdentifier, 'page_view_timing.long_task') === true) {
138
+ (0, _longTasks.onLongTask)(({
139
+ name,
140
+ value,
141
+ info
142
+ }) => this.addTiming(name.toLowerCase(), value, info)); // lt context is passed as 'info'=attrs in the timing node
143
+ }
144
+ /* ------------------------------------End of ex-loader section */
145
+
146
+ /* It's important that CWV api, like "onLCP", is called before this scheduler is initialized. The reason is because they listen to the same
147
+ on vis change or pagehide events, and we'd want ex. onLCP to record the timing (win the race) before we try to send "final harvest". */
148
+ this.scheduler = new _harvestScheduler.HarvestScheduler('events', {
149
+ onFinished: (...args) => this.onHarvestFinished(...args),
150
+ getPayload: (...args) => this.prepareHarvest(...args)
151
+ }, this);
152
+ (0, _registerHandler.registerHandler)('timing', (name, value, attrs) => this.addTiming(name, value, attrs), this.featureName, this.ee); // notice CLS is added to all timings via 4th param
153
+ (0, _registerHandler.registerHandler)('docHidden', msTimestamp => this.endCurrentSession(msTimestamp), this.featureName, this.ee);
154
+ (0, _registerHandler.registerHandler)('winPagehide', msTimestamp => this.recordPageUnload(msTimestamp), this.featureName, this.ee);
155
+ const initialHarvestSeconds = (0, _config.getConfigurationValue)(this.agentIdentifier, 'page_view_timing.initialHarvestSeconds') || 10;
156
+ const harvestTimeSeconds = (0, _config.getConfigurationValue)(this.agentIdentifier, 'page_view_timing.harvestTimeSeconds') || 30;
157
+ // send initial data sooner, then start regular
158
+ this.ee.on(`drain-${this.featureName}`, () => {
159
+ this.scheduler.startTimer(harvestTimeSeconds, initialHarvestSeconds);
160
+ });
161
+ (0, _drain.drain)(this.agentIdentifier, this.featureName);
162
+ }
163
+
164
+ // takes an attributes object and appends connection attributes if available
165
+ addConnectionAttributes(attributes) {
166
+ var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; // to date, both window & worker shares the same support for connection
167
+ if (!connection) return;
168
+ if (connection.type) attributes['net-type'] = connection.type;
169
+ if (connection.effectiveType) attributes['net-etype'] = connection.effectiveType;
170
+ if (connection.rtt) attributes['net-rtt'] = connection.rtt;
171
+ if (connection.downlink) attributes['net-dlink'] = connection.downlink;
172
+ return attributes;
173
+ }
174
+
175
+ /**
176
+ * Add the time of _document visibilitychange to hidden_ to the next PVT harvest == NRDB pageHide attr.
177
+ * @param {number} timestamp
178
+ */
179
+ endCurrentSession(timestamp) {
180
+ if (!this.curSessEndRecorded) {
181
+ // TO DO: stage 2 - we don't want to capture this timing twice on page navigating away, but it should run again if we return to page and away *again*
182
+ this.addTiming('pageHide', timestamp, null);
183
+ this.curSessEndRecorded = true;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Add the time of _window pagehide event_ firing to the next PVT harvest == NRDB windowUnload attr.
189
+ */
190
+ recordPageUnload(timestamp) {
191
+ this.addTiming('unload', timestamp, null);
192
+ // Because window's pageHide commonly fires before vis change and the final harvest occurs on the earlier of the two, we also have to add that now or it won't make it into the last payload out.
193
+ this.endCurrentSession(timestamp);
194
+ }
195
+ addTiming(name, value, attrs) {
196
+ attrs = attrs || {};
197
+
198
+ // If CLS is supported, a cls value should exist and be reported, even at 0.
199
+ // *cli Mar'23 - At this time, it remains attached to all timings. See NEWRELIC-6143.
200
+ if (this.clsSupported) {
201
+ attrs['cls'] = this.cls;
202
+ }
203
+ this.timings.push({
204
+ name: name,
205
+ value: value,
206
+ attrs: attrs
207
+ });
208
+ (0, _handle.handle)('pvtAdded', [name, value, attrs], undefined, _features.FEATURE_NAMES.sessionTrace, this.ee);
209
+ }
210
+ onHarvestFinished(result) {
211
+ if (result.retry && this.timingsSent.length > 0) {
212
+ for (var i = 0; i < this.timingsSent.length; i++) {
213
+ this.timings.push(this.timingsSent[i]);
214
+ }
215
+ this.timingsSent = [];
216
+ }
217
+ }
218
+ appendGlobalCustomAttributes(timing) {
219
+ var timingAttributes = timing.attrs || {};
220
+ var customAttributes = (0, _config.getInfo)(this.agentIdentifier).jsAttributes || {};
221
+ var reservedAttributes = ['size', 'eid', 'cls', 'type', 'fid', 'elTag', 'elUrl', 'net-type', 'net-etype', 'net-rtt', 'net-dlink'];
222
+ (0, _mapOwn.mapOwn)(customAttributes, function (key, val) {
223
+ if (reservedAttributes.indexOf(key) < 0) {
224
+ timingAttributes[key] = val;
225
+ }
226
+ });
227
+ }
228
+
229
+ // serialize and return current timing data, clear and save current data for retry
230
+ prepareHarvest(options) {
231
+ if (this.timings.length === 0) return;
232
+ var payload = this.getPayload(this.timings);
233
+ if (options.retry) {
234
+ for (var i = 0; i < this.timings.length; i++) {
235
+ this.timingsSent.push(this.timings[i]);
236
+ }
237
+ }
238
+ this.timings = [];
239
+ return {
240
+ body: {
241
+ e: payload
242
+ }
243
+ };
244
+ }
245
+
246
+ // serialize array of timing data
247
+ getPayload(data) {
248
+ var addString = (0, _belSerializer.getAddStringContext)(this.agentIdentifier);
249
+ var payload = 'bel.6;';
250
+ for (var i = 0; i < data.length; i++) {
251
+ var timing = data[i];
252
+ payload += 'e,';
253
+ payload += addString(timing.name) + ',';
254
+ payload += (0, _belSerializer.nullable)(timing.value, _belSerializer.numeric, false) + ',';
255
+ this.appendGlobalCustomAttributes(timing);
256
+ var attrParts = (0, _belSerializer.addCustomAttributes)(timing.attrs, addString);
257
+ if (attrParts && attrParts.length > 0) {
258
+ payload += (0, _belSerializer.numeric)(attrParts.length) + ';' + attrParts.join(';');
259
+ }
260
+ if (i + 1 < data.length) payload += ';';
261
+ }
262
+ return payload;
263
+ }
264
+ }
265
+ exports.Aggregate = Aggregate;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FEATURE_NAME = void 0;
7
+ var _features = require("../../loaders/features/features");
8
+ const FEATURE_NAME = _features.FEATURE_NAMES.pageViewTiming;
9
+ exports.FEATURE_NAME = FEATURE_NAME;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.onFirstPaint = void 0;
7
+ /**
8
+ * Calls the `onReport` function when the 'first-paint' PerformancePaintTiming entry is observed.
9
+ * The argument supplied is an object similar to the Metric type used by web-vitals library.
10
+ *
11
+ * @param {Function} onReport - callback that accepts a `metric` object as the single parameter
12
+ */
13
+ const onFirstPaint = onReport => {
14
+ const handleEntries = entries => {
15
+ entries.forEach(entry => {
16
+ if (entry.name === 'first-paint') {
17
+ observer.disconnect();
18
+
19
+ /* Initial hidden state and pre-rendering not yet considered for first paint. See web-vitals onFCP for example. */
20
+ const metric = {
21
+ name: 'FP',
22
+ value: entry.startTime
23
+ };
24
+ onReport(metric);
25
+ }
26
+ });
27
+ };
28
+ let observer;
29
+ try {
30
+ if (PerformanceObserver.supportedEntryTypes.includes('paint')) {
31
+ observer = new PerformanceObserver(list => {
32
+ // Delay by a microtask to workaround a bug in Safari where the
33
+ // callback is invoked immediately, rather than in a separate task.
34
+ // See: https://github.com/GoogleChrome/web-vitals/issues/277
35
+ Promise.resolve().then(() => {
36
+ handleEntries(list.getEntries());
37
+ });
38
+ });
39
+ observer.observe({
40
+ type: 'paint',
41
+ buffered: true
42
+ });
43
+ }
44
+ } catch (e) {
45
+ // Do nothing.
46
+ }
47
+
48
+ /* BFCache restore not yet considered for first paint. See web-vitals onFCP for example. */
49
+ };
50
+ exports.onFirstPaint = onFirstPaint;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "PageViewTiming", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _index.Instrument;
10
+ }
11
+ });
12
+ var _index = require("./instrument/index");
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Instrument = void 0;
7
+ var _handle = require("../../../common/event-emitter/handle");
8
+ var _config = require("../../../common/config/config");
9
+ var _pageVisibility = require("../../../common/window/page-visibility");
10
+ var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
11
+ var _now = require("../../../common/timing/now");
12
+ var _instrumentBase = require("../../utils/instrument-base");
13
+ var _constants = require("../constants");
14
+ var _globalScope = require("../../../common/util/global-scope");
15
+ /*
16
+ * Copyright 2020 New Relic Corporation. All rights reserved.
17
+ * SPDX-License-Identifier: Apache-2.0
18
+ */
19
+
20
+ class Instrument extends _instrumentBase.InstrumentBase {
21
+ static featureName = _constants.FEATURE_NAME;
22
+ constructor(agentIdentifier, aggregator, auto = true) {
23
+ super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
24
+ if (!_globalScope.isBrowserScope) return; // CWV is irrelevant outside web context
25
+
26
+ // Document visibility state becomes hidden; this should run as soon as possible in page life.
27
+ // While we try to replicate web-vital's visibilitywatcher logic in an effort to defer that library to post-pageload, this isn't perfect and doesn't consider prerendering.
28
+ (0, _config.getRuntime)(agentIdentifier).initHidden = Boolean(document.visibilityState === 'hidden');
29
+ (0, _pageVisibility.subscribeToVisibilityChange)(() => (0, _handle.handle)('docHidden', [(0, _now.now)()], undefined, _constants.FEATURE_NAME, this.ee), true);
30
+
31
+ // Window fires its pagehide event (typically on navigation--this occurrence is a *subset* of vis change); don't defer this unless it's guarantee it cannot happen before load(?)
32
+ (0, _eventListenerOpts.windowAddEventListener)('pagehide', () => (0, _handle.handle)('winPagehide', [(0, _now.now)()], undefined, _constants.FEATURE_NAME, this.ee));
33
+ this.importAggregator();
34
+ }
35
+ }
36
+ exports.Instrument = Instrument;