@newrelic/browser-agent 0.1.230 → 0.1.231

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 (221) hide show
  1. package/README.md +25 -1
  2. package/dist/cjs/common/browser-version/ios-version.js +4 -3
  3. package/dist/cjs/common/config/state/configurable.js +1 -1
  4. package/dist/cjs/common/config/state/info.js +1 -1
  5. package/dist/cjs/common/config/state/init.js +1 -1
  6. package/dist/cjs/common/config/state/loader-config.js +1 -1
  7. package/dist/cjs/common/config/state/runtime.js +5 -5
  8. package/dist/cjs/common/constants/env.cdn.js +29 -0
  9. package/dist/cjs/common/constants/env.js +32 -0
  10. package/dist/cjs/common/constants/env.npm.js +30 -0
  11. package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
  12. package/dist/cjs/common/event-emitter/handle.test.js +58 -0
  13. package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
  14. package/dist/cjs/common/harvest/harvest.js +2 -2
  15. package/dist/cjs/common/ids/id.js +14 -6
  16. package/dist/cjs/common/ids/id.test.js +85 -0
  17. package/dist/cjs/common/ids/unique-id.js +75 -51
  18. package/dist/cjs/common/ids/unique-id.test.js +49 -0
  19. package/dist/cjs/common/timing/nav-timing.js +51 -30
  20. package/dist/cjs/common/timing/nav-timing.test.js +192 -0
  21. package/dist/cjs/common/url/clean-url.test.js +9 -0
  22. package/dist/cjs/common/url/encode.test.js +74 -0
  23. package/dist/cjs/common/url/location.js +4 -0
  24. package/dist/cjs/common/url/location.test.js +13 -0
  25. package/dist/cjs/common/url/parse-url.test.js +111 -0
  26. package/dist/cjs/common/url/protocol.js +2 -12
  27. package/dist/cjs/common/url/protocol.test.js +16 -0
  28. package/dist/cjs/common/util/console.js +1 -1
  29. package/dist/cjs/common/util/map-own.test.js +3 -3
  30. package/dist/cjs/common/util/obfuscate.js +1 -1
  31. package/dist/cjs/common/window/page-visibility.js +2 -1
  32. package/dist/cjs/common/wrap/index.js +0 -7
  33. package/dist/cjs/common/wrap/wrap-events.js +6 -9
  34. package/dist/cjs/common/wrap/wrap-fetch.js +6 -6
  35. package/dist/cjs/common/wrap/wrap-history.js +7 -6
  36. package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
  37. package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
  38. package/dist/cjs/common/wrap/wrap-promise.js +7 -6
  39. package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
  40. package/dist/cjs/common/wrap/wrap-raf.js +6 -6
  41. package/dist/cjs/common/wrap/wrap-timer.js +6 -6
  42. package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
  43. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  44. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  45. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
  46. package/dist/cjs/features/jserrors/aggregate/index.js +3 -3
  47. package/dist/cjs/features/jserrors/instrument/index.js +2 -2
  48. package/dist/cjs/features/metrics/aggregate/index.js +6 -7
  49. package/dist/cjs/features/metrics/instrument/index.js +0 -25
  50. package/dist/cjs/features/metrics/instrument/workers-helper.js +5 -5
  51. package/dist/cjs/features/page_action/aggregate/index.js +1 -1
  52. package/dist/cjs/features/page_view_event/aggregate/index.js +17 -6
  53. package/dist/cjs/features/page_view_timing/aggregate/index.js +36 -26
  54. package/dist/cjs/features/session_trace/aggregate/index.js +16 -13
  55. package/dist/cjs/features/utils/instrument-base.js +6 -2
  56. package/dist/cjs/features/utils/lazy-loader.js +1 -1
  57. package/dist/cjs/loaders/agent.js +1 -1
  58. package/dist/cjs/loaders/api/api.js +8 -5
  59. package/dist/cjs/loaders/features/enabled-features.js +1 -1
  60. package/dist/cjs/loaders/micro-agent.js +2 -1
  61. package/dist/esm/common/browser-version/ios-version.js +4 -3
  62. package/dist/esm/common/config/state/configurable.js +1 -1
  63. package/dist/esm/common/config/state/info.js +1 -1
  64. package/dist/esm/common/config/state/init.js +1 -1
  65. package/dist/esm/common/config/state/loader-config.js +1 -1
  66. package/dist/esm/common/config/state/runtime.js +2 -2
  67. package/dist/esm/common/constants/env.cdn.js +20 -0
  68. package/dist/esm/common/constants/env.js +23 -0
  69. package/dist/esm/common/constants/env.npm.js +21 -0
  70. package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
  71. package/dist/esm/common/event-emitter/handle.test.js +54 -0
  72. package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
  73. package/dist/esm/common/harvest/harvest.js +1 -1
  74. package/dist/esm/common/ids/id.js +16 -6
  75. package/dist/esm/common/ids/id.test.js +81 -0
  76. package/dist/esm/common/ids/unique-id.js +75 -51
  77. package/dist/esm/common/ids/unique-id.test.js +44 -0
  78. package/dist/esm/common/timing/nav-timing.js +51 -29
  79. package/dist/esm/common/timing/nav-timing.test.js +190 -0
  80. package/dist/esm/common/url/clean-url.test.js +7 -0
  81. package/dist/esm/common/url/encode.test.js +70 -0
  82. package/dist/esm/common/url/location.js +4 -0
  83. package/dist/esm/common/url/location.test.js +11 -0
  84. package/dist/esm/common/url/parse-url.test.js +107 -0
  85. package/dist/esm/common/url/protocol.js +3 -12
  86. package/dist/esm/common/url/protocol.test.js +14 -0
  87. package/dist/esm/common/util/console.js +1 -1
  88. package/dist/esm/common/util/map-own.test.js +3 -3
  89. package/dist/esm/common/util/obfuscate.js +2 -2
  90. package/dist/esm/common/window/page-visibility.js +2 -1
  91. package/dist/esm/common/wrap/index.js +1 -2
  92. package/dist/esm/common/wrap/wrap-events.js +6 -9
  93. package/dist/esm/common/wrap/wrap-fetch.js +6 -6
  94. package/dist/esm/common/wrap/wrap-history.js +7 -6
  95. package/dist/esm/common/wrap/wrap-jsonp.js +7 -6
  96. package/dist/esm/common/wrap/wrap-mutation.js +7 -6
  97. package/dist/esm/common/wrap/wrap-promise.js +7 -6
  98. package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
  99. package/dist/esm/common/wrap/wrap-raf.js +6 -6
  100. package/dist/esm/common/wrap/wrap-timer.js +6 -6
  101. package/dist/esm/common/wrap/wrap-xhr.js +5 -6
  102. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  103. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
  104. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
  105. package/dist/esm/features/jserrors/aggregate/index.js +3 -3
  106. package/dist/esm/features/jserrors/instrument/index.js +2 -2
  107. package/dist/esm/features/metrics/aggregate/index.js +7 -8
  108. package/dist/esm/features/metrics/instrument/index.js +0 -25
  109. package/dist/esm/features/metrics/instrument/workers-helper.js +5 -5
  110. package/dist/esm/features/page_action/aggregate/index.js +1 -1
  111. package/dist/esm/features/page_view_event/aggregate/index.js +17 -6
  112. package/dist/esm/features/page_view_timing/aggregate/index.js +36 -26
  113. package/dist/esm/features/session_trace/aggregate/index.js +16 -13
  114. package/dist/esm/features/utils/instrument-base.js +1 -1
  115. package/dist/esm/features/utils/lazy-loader.js +1 -1
  116. package/dist/esm/loaders/agent.js +1 -1
  117. package/dist/esm/loaders/api/api.js +4 -4
  118. package/dist/esm/loaders/features/enabled-features.js +1 -1
  119. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  120. package/dist/types/common/constants/env.cdn.d.ts +18 -0
  121. package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
  122. package/dist/types/common/constants/env.d.ts +13 -0
  123. package/dist/types/common/constants/env.d.ts.map +1 -0
  124. package/dist/types/common/constants/env.npm.d.ts +19 -0
  125. package/dist/types/common/constants/env.npm.d.ts.map +1 -0
  126. package/dist/types/common/ids/id.d.ts +11 -1
  127. package/dist/types/common/ids/id.d.ts.map +1 -1
  128. package/dist/types/common/ids/unique-id.d.ts +24 -1
  129. package/dist/types/common/ids/unique-id.d.ts.map +1 -1
  130. package/dist/types/common/timing/nav-timing.d.ts +1 -2
  131. package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
  132. package/dist/types/common/unload/eol.d.ts.map +1 -1
  133. package/dist/types/common/url/location.d.ts +4 -0
  134. package/dist/types/common/url/location.d.ts.map +1 -1
  135. package/dist/types/common/url/parse-url.d.ts.map +1 -1
  136. package/dist/types/common/url/protocol.d.ts +1 -6
  137. package/dist/types/common/url/protocol.d.ts.map +1 -1
  138. package/dist/types/common/util/global-scope.d.ts.map +1 -1
  139. package/dist/types/common/wrap/index.d.ts +1 -2
  140. package/dist/types/common/wrap/index.d.ts.map +1 -1
  141. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  142. package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
  143. package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
  144. package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
  145. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  146. package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -1
  147. package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -1
  148. package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
  149. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  150. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  151. package/dist/types/features/metrics/instrument/index.d.ts +0 -1
  152. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  153. package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -1
  154. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  155. package/dist/types/features/page_view_timing/aggregate/index.d.ts +1 -2
  156. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  157. package/dist/types/features/session_trace/aggregate/index.d.ts +1 -1
  158. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  159. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  160. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  161. package/package.json +9 -30
  162. package/src/common/browser-version/ios-version.js +4 -3
  163. package/src/common/config/state/runtime.js +26 -24
  164. package/src/common/constants/env.cdn.js +20 -0
  165. package/src/common/constants/env.js +23 -0
  166. package/src/common/constants/env.npm.js +21 -0
  167. package/src/common/event-emitter/contextual-ee.test.js +310 -0
  168. package/src/common/event-emitter/handle.test.js +56 -0
  169. package/src/common/event-emitter/register-handler.test.js +61 -0
  170. package/src/common/harvest/harvest.js +2 -2
  171. package/src/common/ids/id.js +15 -6
  172. package/src/common/ids/id.test.js +92 -0
  173. package/src/common/ids/unique-id.js +77 -54
  174. package/src/common/ids/unique-id.test.js +58 -0
  175. package/src/common/timing/nav-timing.js +50 -30
  176. package/src/common/timing/nav-timing.test.js +161 -0
  177. package/src/common/unload/eol.js +1 -2
  178. package/src/common/url/clean-url.test.js +25 -0
  179. package/src/common/url/encode.test.js +80 -0
  180. package/src/common/url/location.js +4 -0
  181. package/src/common/url/location.test.js +15 -0
  182. package/src/common/url/parse-url.js +1 -2
  183. package/src/common/url/parse-url.test.js +110 -0
  184. package/src/common/url/protocol.js +3 -13
  185. package/src/common/url/protocol.test.js +18 -0
  186. package/src/common/util/global-scope.js +1 -2
  187. package/src/common/util/obfuscate.js +2 -2
  188. package/src/common/window/page-visibility.js +1 -1
  189. package/src/common/wrap/index.js +1 -2
  190. package/src/common/wrap/wrap-events.js +5 -5
  191. package/src/common/wrap/wrap-fetch.js +4 -3
  192. package/src/common/wrap/wrap-history.js +6 -3
  193. package/src/common/wrap/wrap-jsonp.js +5 -3
  194. package/src/common/wrap/wrap-mutation.js +6 -3
  195. package/src/common/wrap/wrap-promise.js +7 -6
  196. package/src/common/wrap/wrap-promise.test.js +140 -0
  197. package/src/common/wrap/wrap-raf.js +5 -3
  198. package/src/common/wrap/wrap-timer.js +5 -3
  199. package/src/common/wrap/wrap-xhr.js +4 -3
  200. package/src/features/ajax/instrument/index.js +1 -1
  201. package/src/features/jserrors/instrument/index.js +4 -2
  202. package/src/features/metrics/aggregate/index.js +3 -4
  203. package/src/features/metrics/instrument/index.js +0 -30
  204. package/src/features/metrics/instrument/workers-helper.js +9 -6
  205. package/src/features/page_view_event/aggregate/index.js +15 -6
  206. package/src/features/page_view_timing/aggregate/index.js +36 -25
  207. package/src/features/page_view_timing/long-tasks.js +10 -10
  208. package/src/features/session_trace/aggregate/index.js +15 -12
  209. package/src/features/session_trace/instrument/index.js +3 -2
  210. package/src/features/spa/instrument/index.js +4 -2
  211. package/src/loaders/api/api.js +1 -1
  212. package/dist/cjs/common/constants/environment-variables.js +0 -20
  213. package/dist/cjs/common/wrap/wrap-console.js +0 -54
  214. package/dist/esm/common/constants/environment-variables.js +0 -11
  215. package/dist/esm/common/wrap/wrap-console.js +0 -46
  216. package/dist/types/common/constants/environment-variables.d.ts +0 -4
  217. package/dist/types/common/constants/environment-variables.d.ts.map +0 -1
  218. package/dist/types/common/wrap/wrap-console.d.ts +0 -16
  219. package/dist/types/common/wrap/wrap-console.d.ts.map +0 -1
  220. package/src/common/constants/environment-variables.js +0 -11
  221. package/src/common/wrap/wrap-console.js +0 -47
@@ -89,12 +89,21 @@ export class Aggregate extends AggregateBase {
89
89
  chunksForQueryString.push(param('pr', info.product))
90
90
  chunksForQueryString.push(param('af', getActivatedFeaturesFlags(this.agentIdentifier).join(',')))
91
91
 
92
- if (globalScope.performance && typeof (globalScope.performance.timing) !== 'undefined') {
93
- var navTimingApiData = ({
94
- timing: addPT(agentRuntime.offset, globalScope.performance.timing, {}),
95
- navigation: addPN(globalScope.performance.navigation, {})
96
- })
97
- chunksForQueryString.push(param('perf', stringify(navTimingApiData)))
92
+ if (globalScope.performance) {
93
+ if (typeof PerformanceNavigationTiming !== 'undefined') { // Navigation Timing level 2 API that replaced PerformanceTiming & PerformanceNavigation
94
+ const navTimingEntry = globalScope?.performance?.getEntriesByType('navigation')?.[0]
95
+ const perf = ({
96
+ timing: addPT(agentRuntime.offset, navTimingEntry, {}),
97
+ navigation: addPN(navTimingEntry, {})
98
+ })
99
+ chunksForQueryString.push(param('perf', stringify(perf)))
100
+ } else if (typeof PerformanceTiming !== 'undefined') { // Safari pre-15 did not support level 2 timing
101
+ const perf = ({
102
+ timing: addPT(agentRuntime.offset, globalScope.performance.timing, {}, true),
103
+ navigation: addPN(globalScope.performance.navigation, {})
104
+ })
105
+ chunksForQueryString.push(param('perf', stringify(perf)))
106
+ }
98
107
  }
99
108
 
100
109
  try { // PVTiming sends these too, albeit using web-vitals and slightly different; it's unknown why they're duplicated, but PVT should be the truth
@@ -27,11 +27,7 @@ export class Aggregate extends AggregateBase {
27
27
  this.timings = []
28
28
  this.timingsSent = []
29
29
  this.curSessEndRecorded = false
30
-
31
- try { // we (only) need to track cls state because it's attached to other timing events rather than reported on change...
32
- this.clsSupported = PerformanceObserver.supportedEntryTypes.includes('layout-shift')
33
- this.cls = 0
34
- } catch (e) {}
30
+ this.cls = null // this should be null unless set to a numeric value by web-vitals so that we differentiate if CLS is supported
35
31
 
36
32
  /*! This is the section that used to be in the loader portion: !*/
37
33
  /* ------------------------------------------------------------ */
@@ -66,7 +62,7 @@ export class Aggregate extends AggregateBase {
66
62
 
67
63
  /* 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. */
68
64
  onFID(({ name, value, entries }) => {
69
- if (pageStartedHidden || this.alreadySent.has(name)) return
65
+ if (pageStartedHidden || this.alreadySent.has(name) || entries.length === 0) return
70
66
  this.alreadySent.add(name)
71
67
 
72
68
  // 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.
@@ -84,24 +80,28 @@ export class Aggregate extends AggregateBase {
84
80
  if (pageStartedHidden || this.alreadySent.has(name)) return
85
81
  this.alreadySent.add(name)
86
82
 
87
- // CWV will only ever report one (THE) lcp entry to us; lcp is also only reported *once* on earlier(user interaction, page hidden).
88
- 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...
89
- const attrs = {
90
- size: lcpEntry.size,
91
- eid: lcpEntry.id
92
- }
93
- this.addConnectionAttributes(attrs)
94
- if (lcpEntry.url) {
95
- attrs['elUrl'] = cleanURL(lcpEntry.url)
96
- }
97
- if (lcpEntry.element && lcpEntry.element.tagName) {
98
- attrs['elTag'] = lcpEntry.element.tagName
83
+ const attributes = {}
84
+ if (entries.length > 0) {
85
+ // CWV will only ever report one (THE) lcp entry to us; lcp is also only reported *once* on earlier(user interaction, page hidden).
86
+ 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...
87
+ attributes.size = lcpEntry.size
88
+ attributes.eid = lcpEntry.id
89
+
90
+ if (lcpEntry.url) {
91
+ attributes['elUrl'] = cleanURL(lcpEntry.url)
92
+ }
93
+ if (lcpEntry.element?.tagName) {
94
+ attributes['elTag'] = lcpEntry.element.tagName
95
+ }
99
96
  }
100
- this.addTiming(name.toLowerCase(), value, attrs)
97
+
98
+ this.addConnectionAttributes(attributes)
99
+ this.addTiming(name.toLowerCase(), value, attributes)
101
100
  })
102
101
 
103
- /* 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. */
104
- onCLS(({ value }) => this.cls = value)
102
+ /* 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.
103
+ reportAllChanges ensures our tracked cls has the most recent rolling value to attach to 'unload' and 'pagehide'. */
104
+ onCLS(({ value }) => this.cls = value, { reportAllChanges: true })
105
105
 
106
106
  /* Interaction-to-Next-Paint */
107
107
  onINP(({ name, value, id }) => this.addTiming(name.toLowerCase(), value, { metricId: id }))
@@ -160,16 +160,27 @@ export class Aggregate extends AggregateBase {
160
160
  */
161
161
  recordPageUnload (timestamp) {
162
162
  this.addTiming('unload', timestamp, null)
163
- // 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.
163
+ /*
164
+ Issue: Because window's pageHide commonly fires BEFORE vis change and "final" harvest would happen at the former in this case, we also have to add our vis-change event now or it may not be sent.
165
+ Affected: Safari < v14.1/.5 ; versions that don't support 'visiilitychange' event
166
+ Impact: For affected w/o this, NR 'pageHide' attribute may not be sent. For other browsers w/o this, NR 'pageHide' gets fragmented into its own harvest call on page unloading because of dual EoL logic.
167
+ Mitigation: NR 'unload' and 'pageHide' are both recorded when window pageHide fires, rather than only recording 'unload'.
168
+ Future: When EoL can become the singular subscribeToVisibilityChange, it's likely endCurrentSession isn't needed here as 'unload'-'pageHide' can be untangled.
169
+ */
164
170
  this.endCurrentSession(timestamp)
165
171
  }
166
172
 
167
173
  addTiming (name, value, attrs) {
168
174
  attrs = attrs || {}
169
175
 
170
- // If CLS is supported, a cls value should exist and be reported, even at 0.
171
- // *cli Mar'23 - At this time, it remains attached to all timings. See NEWRELIC-6143.
172
- if (this.clsSupported) {
176
+ // If cls was set to another value by `onCLS`, then it's supported and is attached onto any timing but is omitted until such time.
177
+ /*
178
+ *cli Apr'23 - Convert attach-to-all -> attach-if-not-null. See NEWRELIC-6143.
179
+ Issue: Because NR 'pageHide' was only sent once with what is considered the "final" CLS value, in the case that 'pageHide' fires before 'load' happens, we incorrectly a final CLS of 0 for that page.
180
+ Mitigation: We've set initial CLS to null so that it's omitted from timings like 'pageHide' in that edge case. It should only be included if onCLS callback was executed at least once.
181
+ Future: onCLS value changes should be reported directly & CLS separated into its own timing node so it's not beholden to 'pageHide' firing. It'd also be possible to report the real final CLS.
182
+ */
183
+ if (this.cls !== null) {
173
184
  attrs['cls'] = this.cls
174
185
  }
175
186
 
@@ -15,21 +15,21 @@ export const onLongTask = (onReport) => {
15
15
  const metric = {
16
16
  name: 'LT',
17
17
  value: entry.duration,
18
- info: { // this property deviates from CWV std interface but will hold the custom context to send to NRDB
19
- ltFrame: entry.name, // MDN: the browsing context or frame that can be attributed to the long task
20
- ltStart: entry.startTime, // MDN: a double representing the time (millisec) when the task started
21
- ltCtr: entry.attribution[0].containerType // MDN: type of frame container: 'iframe', 'embed', or 'object' ... but this can also be 'window'
18
+ info: { // this property deviates from CWV std interface but will hold the custom context to send to NRDB
19
+ ltFrame: entry.name, // MDN: the browsing context or frame that can be attributed to the long task
20
+ ltStart: entry.startTime, // MDN: a double representing the time (millisec) when the task started
21
+ ltCtr: entry.attribution[0].containerType // MDN: type of frame container: 'iframe', 'embed', or 'object' ... but this can also be 'window'
22
22
  }
23
23
  }
24
- if (metric.info.ltCtr !== 'window') { // the following properties are only of relevance & appended for html elements
24
+ if (metric.info.ltCtr !== 'window') { // the following properties are only of relevance & appended for html elements
25
25
  Object.assign(metric.info, {
26
- ltCtrSrc: entry.attribution[0].containerSrc, // MDN: container's 'src' attribute
27
- ltCtrId: entry.attribution[0].containerId, // MDN: container's 'id' attribute
28
- ltCtrName: entry.attribution[0].containerName // MDN: container's 'name' attribute
26
+ ltCtrSrc: entry.attribution[0].containerSrc, // MDN: container's 'src' attribute
27
+ ltCtrId: entry.attribution[0].containerId, // MDN: container's 'id' attribute
28
+ ltCtrName: entry.attribution[0].containerName // MDN: container's 'name' attribute
29
29
  })
30
30
  }
31
31
 
32
- onReport(metric) // report every long task observed unconditionally
32
+ onReport(metric) // report every long task observed unconditionally
33
33
  })
34
34
  }
35
35
 
@@ -53,7 +53,7 @@ export const onLongTask = (onReport) => {
53
53
  if (observer) {
54
54
  subscribeToEOL(() => {
55
55
  handleEntries(observer.takeRecords())
56
- }, true) // this bool is a temp arg under staged BFCache work that runs the func under the new page session logic -- tb removed w/ the feature flag later
56
+ }, true) // this bool is a temp arg under staged BFCache work that runs the func under the new page session logic -- tb removed w/ the feature flag later
57
57
 
58
58
  /* No work needed on BFCache restore for long task. */
59
59
  }
@@ -75,7 +75,11 @@ export class Aggregate extends AggregateBase {
75
75
  this.laststart = 0
76
76
 
77
77
  registerHandler('feat-stn', () => {
78
- this.storeTiming(window.performance.timing)
78
+ if (typeof PerformanceNavigationTiming !== 'undefined') {
79
+ this.storeTiming(window.performance?.getEntriesByType('navigation')?.[0] || {})
80
+ } else {
81
+ this.storeTiming(window.performance?.timing)
82
+ }
79
83
 
80
84
  var scheduler = new HarvestScheduler('resources', {
81
85
  onFinished: onHarvestFinished.bind(this),
@@ -135,25 +139,24 @@ export class Aggregate extends AggregateBase {
135
139
  processPVT (name, value, attrs) {
136
140
  var t = {}
137
141
  t[name] = value
138
- this.storeTiming(t, true)
142
+ this.storeTiming(t)
139
143
  if (this.hasFID(name, attrs)) this.storeEvent({ type: 'fid', target: 'document' }, 'document', value, value + attrs.fid)
140
144
  }
141
145
 
142
- storeTiming (_t, ignoreOffset) {
143
- var key
144
- var val
145
- var timeOffset
146
- var dateNow = Date.now()
147
-
146
+ storeTiming (_t) {
148
147
  // loop iterates through prototype also (for FF)
149
- for (key in _t) {
150
- val = _t[key]
148
+ for (let key in _t) {
149
+ const val = _t[key]
150
+
151
+ // ignore size and status type nodes that do not map to timestamp metrics
152
+ const lck = key.toLowerCase()
153
+ if (lck.indexOf('size') >= 0 || lck.indexOf('status') >= 0) continue
151
154
 
152
155
  // ignore inherited methods, meaningless 0 values, and bogus timestamps
153
156
  // that are in the future (Microsoft Edge seems to sometimes produce these)
154
- if (!(typeof (val) === 'number' && val > 0 && val < dateNow)) continue
157
+ if (!(typeof (val) === 'number' && val >= 0)) continue
155
158
 
156
- timeOffset = !ignoreOffset ? _t[key] - getRuntime(this.agentIdentifier).offset : _t[key]
159
+ const timeOffset = Math.round(_t[key])
157
160
 
158
161
  this.storeSTN({
159
162
  n: key,
@@ -78,8 +78,9 @@ export class Instrument extends InstrumentBase {
78
78
  observeResourceTimings()
79
79
  } else {
80
80
  // collect resource timings once when buffer is full
81
- if (window.performance[CRT] && window.performance[ADD_EVENT_LISTENER])
82
- { window.performance.addEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, eventListenerOpts(false)) }
81
+ if (window.performance[CRT] && window.performance[ADD_EVENT_LISTENER]) {
82
+ window.performance.addEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, eventListenerOpts(false))
83
+ }
83
84
  }
84
85
 
85
86
  function observeResourceTimings () {
@@ -24,8 +24,10 @@ export class Instrument extends InstrumentBase {
24
24
 
25
25
  if (!getRuntime(agentIdentifier).xhrWrappable) return
26
26
 
27
- try { this.removeOnAbort = new AbortController() }
28
- catch (e) {}
27
+ try {
28
+ this.removeOnAbort = new AbortController()
29
+ } catch (e) {}
30
+
29
31
  let depth = 0
30
32
  let startHash
31
33
 
@@ -35,7 +35,7 @@ export function setTopLevelCallers () {
35
35
  returnVals.push(val.api[fnName](...args))
36
36
  }
37
37
  })
38
- return returnVals.length > 1 ? returnsVals : returnVals[0]
38
+ return returnVals.length > 1 ? returnVals : returnVals[0]
39
39
  }
40
40
  }
41
41
 
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.VERSION = exports.DIST_METHOD = exports.BUILD_ENV = void 0;
7
- // Webpack and NPM builds define `process.env.BUILD_VERSION` at build time based on variables supplied at build time.
8
- // VERSION as defined here ends up decorating: agent runtime configuration, harvest, and supportability metrics.
9
- const VERSION = typeof "0.1.230" !== 'undefined' && "0.1.230" || '';
10
-
11
- // process.env.BUILD_ENV is replaced during webpack -or- npm build with environment vars supplied at build time
12
- // LOCAL, PROD, DEV, etc
13
- exports.VERSION = VERSION;
14
- const BUILD_ENV = typeof "NPM" !== 'undefined' && "NPM" || '';
15
-
16
- // process.env.DIST_METHOD is replaced during webpack -or- npm build with environment vars supplied at build time
17
- // CDN, NPM etc
18
- exports.BUILD_ENV = BUILD_ENV;
19
- const DIST_METHOD = typeof "NPM" !== 'undefined' && "NPM" || '';
20
- exports.DIST_METHOD = DIST_METHOD;
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.scopedEE = scopedEE;
7
- exports.wrapConsole = wrapConsole;
8
- var _contextualEe = require("../event-emitter/contextual-ee");
9
- var _wrapFunction = require("./wrap-function");
10
- var _globalScope = require("../util/global-scope");
11
- /*
12
- * Copyright 2020 New Relic Corporation. All rights reserved.
13
- * SPDX-License-Identifier: Apache-2.0
14
- */
15
- /**
16
- * @file Wraps `debug`, `error`, `info`, `log`, `trace, and `warn` methods of the global `console` object for instrumentation.
17
- * This module is used by: metrics.
18
- */
19
-
20
- const wrapped = {};
21
- const CONSOLE_METHODS = ['debug', 'error', 'info', 'log', 'trace', 'warn'];
22
-
23
- /**
24
- * Wraps the `debug`, `error`, `info`, `log`, `trace, and `warn` methods of global `console` object and returns a
25
- * corresponding event emitter scoped to the console object.
26
- * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
27
- * @returns {Object} Scoped event emitter with a debug ID of `console`.
28
- */
29
- function wrapConsole(sharedEE) {
30
- const ee = scopedEE(sharedEE);
31
-
32
- // We want to wrap console once and only once for each agent instance (`ee.debugId`).
33
- if (wrapped[ee.debugId]) {
34
- return ee;
35
- }
36
- wrapped[ee.debugId] = true;
37
- var functionWrapper = (0, _wrapFunction.createWrapperWithEmitter)(ee);
38
- // Because the console object exists once on the global scope, we don't need to wrap the prototype's methods.
39
- // We use the global scope instead of window to accomodate service workers.
40
- // The leading hyphen on '-console-' tells `inPlace` to prefix emitted event names with the method name too.
41
- functionWrapper.inPlace(_globalScope.globalScope.console, CONSOLE_METHODS, '-console-');
42
- return ee;
43
- }
44
-
45
- /**
46
- * Returns an event emitter scoped specifically for the `console` context. This scoping is a remnant from when all the
47
- * features shared the same group in the event, to isolate events between features. It will likely be revisited.
48
- * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
49
- * Uses `ee` on the global scope if undefined).
50
- * @returns {Object} Scoped event emitter with a debug ID of 'console'.
51
- */
52
- function scopedEE(sharedEE) {
53
- return (sharedEE || _contextualEe.ee).get('console');
54
- }
@@ -1,11 +0,0 @@
1
- // Webpack and NPM builds define `process.env.BUILD_VERSION` at build time based on variables supplied at build time.
2
- // VERSION as defined here ends up decorating: agent runtime configuration, harvest, and supportability metrics.
3
- export const VERSION = typeof "0.1.230" !== 'undefined' && "0.1.230" || '';
4
-
5
- // process.env.BUILD_ENV is replaced during webpack -or- npm build with environment vars supplied at build time
6
- // LOCAL, PROD, DEV, etc
7
- export const BUILD_ENV = typeof "NPM" !== 'undefined' && "NPM" || '';
8
-
9
- // process.env.DIST_METHOD is replaced during webpack -or- npm build with environment vars supplied at build time
10
- // CDN, NPM etc
11
- export const DIST_METHOD = typeof "NPM" !== 'undefined' && "NPM" || '';
@@ -1,46 +0,0 @@
1
- /*
2
- * Copyright 2020 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- /**
6
- * @file Wraps `debug`, `error`, `info`, `log`, `trace, and `warn` methods of the global `console` object for instrumentation.
7
- * This module is used by: metrics.
8
- */
9
- import { ee as globalEE } from '../event-emitter/contextual-ee';
10
- import { createWrapperWithEmitter } from './wrap-function';
11
- import { globalScope } from '../util/global-scope';
12
- const wrapped = {};
13
- const CONSOLE_METHODS = ['debug', 'error', 'info', 'log', 'trace', 'warn'];
14
-
15
- /**
16
- * Wraps the `debug`, `error`, `info`, `log`, `trace, and `warn` methods of global `console` object and returns a
17
- * corresponding event emitter scoped to the console object.
18
- * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
19
- * @returns {Object} Scoped event emitter with a debug ID of `console`.
20
- */
21
- export function wrapConsole(sharedEE) {
22
- const ee = scopedEE(sharedEE);
23
-
24
- // We want to wrap console once and only once for each agent instance (`ee.debugId`).
25
- if (wrapped[ee.debugId]) {
26
- return ee;
27
- }
28
- wrapped[ee.debugId] = true;
29
- var functionWrapper = createWrapperWithEmitter(ee);
30
- // Because the console object exists once on the global scope, we don't need to wrap the prototype's methods.
31
- // We use the global scope instead of window to accomodate service workers.
32
- // The leading hyphen on '-console-' tells `inPlace` to prefix emitted event names with the method name too.
33
- functionWrapper.inPlace(globalScope.console, CONSOLE_METHODS, '-console-');
34
- return ee;
35
- }
36
-
37
- /**
38
- * Returns an event emitter scoped specifically for the `console` context. This scoping is a remnant from when all the
39
- * features shared the same group in the event, to isolate events between features. It will likely be revisited.
40
- * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
41
- * Uses `ee` on the global scope if undefined).
42
- * @returns {Object} Scoped event emitter with a debug ID of 'console'.
43
- */
44
- export function scopedEE(sharedEE) {
45
- return (sharedEE || globalEE).get('console');
46
- }
@@ -1,4 +0,0 @@
1
- export const VERSION: string;
2
- export const BUILD_ENV: string;
3
- export const DIST_METHOD: string;
4
- //# sourceMappingURL=environment-variables.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"environment-variables.d.ts","sourceRoot":"","sources":["../../../../src/common/constants/environment-variables.js"],"names":[],"mappings":"AAEA,6BAA0G;AAI1G,+BAAoG;AAIpG,iCAA0G"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Wraps the `debug`, `error`, `info`, `log`, `trace, and `warn` methods of global `console` object and returns a
3
- * corresponding event emitter scoped to the console object.
4
- * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
5
- * @returns {Object} Scoped event emitter with a debug ID of `console`.
6
- */
7
- export function wrapConsole(sharedEE: Object): Object;
8
- /**
9
- * Returns an event emitter scoped specifically for the `console` context. This scoping is a remnant from when all the
10
- * features shared the same group in the event, to isolate events between features. It will likely be revisited.
11
- * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
12
- * Uses `ee` on the global scope if undefined).
13
- * @returns {Object} Scoped event emitter with a debug ID of 'console'.
14
- */
15
- export function scopedEE(sharedEE: Object): Object;
16
- //# sourceMappingURL=wrap-console.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrap-console.d.ts","sourceRoot":"","sources":["../../../../src/common/wrap/wrap-console.js"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,sCAHW,MAAM,GACJ,MAAM,CAgBlB;AAED;;;;;;GAMG;AACH,mCAJW,MAAM,GAEJ,MAAM,CAIlB"}
@@ -1,11 +0,0 @@
1
- // Webpack and NPM builds define `process.env.BUILD_VERSION` at build time based on variables supplied at build time.
2
- // VERSION as defined here ends up decorating: agent runtime configuration, harvest, and supportability metrics.
3
- export const VERSION = typeof process.env.BUILD_VERSION !== 'undefined' && process.env.BUILD_VERSION || ''
4
-
5
- // process.env.BUILD_ENV is replaced during webpack -or- npm build with environment vars supplied at build time
6
- // LOCAL, PROD, DEV, etc
7
- export const BUILD_ENV = typeof process.env.BUILD_ENV !== 'undefined' && process.env.BUILD_ENV || ''
8
-
9
- // process.env.DIST_METHOD is replaced during webpack -or- npm build with environment vars supplied at build time
10
- // CDN, NPM etc
11
- export const DIST_METHOD = typeof process.env.DIST_METHOD !== 'undefined' && process.env.DIST_METHOD || ''
@@ -1,47 +0,0 @@
1
- /*
2
- * Copyright 2020 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
- /**
6
- * @file Wraps `debug`, `error`, `info`, `log`, `trace, and `warn` methods of the global `console` object for instrumentation.
7
- * This module is used by: metrics.
8
- */
9
- import { ee as globalEE } from '../event-emitter/contextual-ee'
10
- import { createWrapperWithEmitter } from './wrap-function'
11
- import { globalScope } from '../util/global-scope'
12
-
13
- const wrapped = {}
14
- const CONSOLE_METHODS = ['debug', 'error', 'info', 'log', 'trace', 'warn']
15
-
16
- /**
17
- * Wraps the `debug`, `error`, `info`, `log`, `trace, and `warn` methods of global `console` object and returns a
18
- * corresponding event emitter scoped to the console object.
19
- * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
20
- * @returns {Object} Scoped event emitter with a debug ID of `console`.
21
- */
22
- export function wrapConsole (sharedEE) {
23
- const ee = scopedEE(sharedEE)
24
-
25
- // We want to wrap console once and only once for each agent instance (`ee.debugId`).
26
- if (wrapped[ee.debugId]) { return ee }
27
- wrapped[ee.debugId] = true
28
-
29
- var functionWrapper = createWrapperWithEmitter(ee)
30
- // Because the console object exists once on the global scope, we don't need to wrap the prototype's methods.
31
- // We use the global scope instead of window to accomodate service workers.
32
- // The leading hyphen on '-console-' tells `inPlace` to prefix emitted event names with the method name too.
33
- functionWrapper.inPlace(globalScope.console, CONSOLE_METHODS, '-console-')
34
-
35
- return ee
36
- }
37
-
38
- /**
39
- * Returns an event emitter scoped specifically for the `console` context. This scoping is a remnant from when all the
40
- * features shared the same group in the event, to isolate events between features. It will likely be revisited.
41
- * @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter.
42
- * Uses `ee` on the global scope if undefined).
43
- * @returns {Object} Scoped event emitter with a debug ID of 'console'.
44
- */
45
- export function scopedEE (sharedEE) {
46
- return (sharedEE || globalEE).get('console')
47
- }