@newrelic/browser-agent 1.254.1 → 1.256.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 (176) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cjs/common/config/state/runtime.js +2 -1
  3. package/dist/cjs/common/constants/env.cdn.js +2 -2
  4. package/dist/cjs/common/constants/env.npm.js +2 -2
  5. package/dist/cjs/common/constants/runtime.js +1 -1
  6. package/dist/cjs/common/context/shared-context.js +1 -1
  7. package/dist/cjs/common/harvest/harvest.js +2 -1
  8. package/dist/cjs/common/session/session-entity.js +2 -1
  9. package/dist/cjs/common/timer/interaction-timer.js +16 -2
  10. package/dist/cjs/common/timing/time-keeper.js +23 -19
  11. package/dist/cjs/common/vitals/cumulative-layout-shift.js +12 -5
  12. package/dist/cjs/common/vitals/first-contentful-paint.js +10 -6
  13. package/dist/cjs/common/vitals/first-input-delay.js +12 -10
  14. package/dist/cjs/common/vitals/first-paint.js +1 -2
  15. package/dist/cjs/common/vitals/interaction-to-next-paint.js +11 -7
  16. package/dist/cjs/common/vitals/largest-contentful-paint.js +19 -17
  17. package/dist/cjs/common/vitals/long-task.js +0 -1
  18. package/dist/cjs/common/vitals/time-to-first-byte.js +11 -6
  19. package/dist/cjs/common/vitals/vital-metric.js +1 -4
  20. package/dist/cjs/common/window/nreum.js +1 -1
  21. package/dist/cjs/features/ajax/aggregate/index.js +3 -2
  22. package/dist/cjs/features/ajax/instrument/index.js +1 -1
  23. package/dist/cjs/features/jserrors/aggregate/index.js +19 -8
  24. package/dist/cjs/features/jserrors/instrument/index.js +9 -4
  25. package/dist/cjs/features/page_action/aggregate/index.js +3 -2
  26. package/dist/cjs/features/page_view_event/aggregate/index.js +10 -5
  27. package/dist/cjs/features/page_view_timing/aggregate/index.js +21 -7
  28. package/dist/cjs/features/page_view_timing/instrument/index.js +1 -1
  29. package/dist/cjs/features/session_replay/aggregate/index.js +59 -35
  30. package/dist/cjs/features/session_replay/constants.js +2 -1
  31. package/dist/cjs/features/session_replay/instrument/index.js +9 -2
  32. package/dist/cjs/features/session_replay/shared/recorder.js +20 -4
  33. package/dist/cjs/features/session_replay/shared/utils.js +12 -0
  34. package/dist/cjs/features/session_trace/aggregate/index.js +20 -23
  35. package/dist/cjs/features/session_trace/instrument/index.js +1 -1
  36. package/dist/cjs/features/soft_navigations/aggregate/index.js +2 -2
  37. package/dist/cjs/features/soft_navigations/instrument/index.js +1 -1
  38. package/dist/cjs/features/spa/aggregate/index.js +19 -10
  39. package/dist/cjs/features/spa/instrument/index.js +1 -1
  40. package/dist/cjs/features/utils/feature-base.js +0 -2
  41. package/dist/cjs/loaders/agent-base.js +0 -2
  42. package/dist/cjs/loaders/agent.js +1 -1
  43. package/dist/cjs/loaders/api/api.js +8 -2
  44. package/dist/cjs/loaders/configure/configure.js +1 -0
  45. package/dist/cjs/loaders/micro-agent.js +4 -7
  46. package/dist/esm/common/config/state/runtime.js +2 -1
  47. package/dist/esm/common/constants/env.cdn.js +2 -2
  48. package/dist/esm/common/constants/env.npm.js +2 -2
  49. package/dist/esm/common/constants/runtime.js +1 -1
  50. package/dist/esm/common/context/shared-context.js +1 -1
  51. package/dist/esm/common/harvest/harvest.js +2 -1
  52. package/dist/esm/common/session/session-entity.js +2 -1
  53. package/dist/esm/common/timer/interaction-timer.js +16 -2
  54. package/dist/esm/common/timing/time-keeper.js +23 -20
  55. package/dist/esm/common/vitals/cumulative-layout-shift.js +11 -4
  56. package/dist/esm/common/vitals/first-contentful-paint.js +9 -5
  57. package/dist/esm/common/vitals/first-input-delay.js +11 -9
  58. package/dist/esm/common/vitals/first-paint.js +1 -2
  59. package/dist/esm/common/vitals/interaction-to-next-paint.js +10 -6
  60. package/dist/esm/common/vitals/largest-contentful-paint.js +18 -16
  61. package/dist/esm/common/vitals/long-task.js +0 -1
  62. package/dist/esm/common/vitals/time-to-first-byte.js +10 -5
  63. package/dist/esm/common/vitals/vital-metric.js +1 -4
  64. package/dist/esm/common/window/nreum.js +1 -1
  65. package/dist/esm/features/ajax/aggregate/index.js +3 -2
  66. package/dist/esm/features/ajax/instrument/index.js +1 -1
  67. package/dist/esm/features/jserrors/aggregate/index.js +19 -8
  68. package/dist/esm/features/jserrors/instrument/index.js +9 -4
  69. package/dist/esm/features/page_action/aggregate/index.js +3 -2
  70. package/dist/esm/features/page_view_event/aggregate/index.js +10 -5
  71. package/dist/esm/features/page_view_timing/aggregate/index.js +21 -7
  72. package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
  73. package/dist/esm/features/session_replay/aggregate/index.js +59 -35
  74. package/dist/esm/features/session_replay/constants.js +2 -1
  75. package/dist/esm/features/session_replay/instrument/index.js +9 -2
  76. package/dist/esm/features/session_replay/shared/recorder.js +21 -5
  77. package/dist/esm/features/session_replay/shared/utils.js +11 -0
  78. package/dist/esm/features/session_trace/aggregate/index.js +20 -23
  79. package/dist/esm/features/session_trace/instrument/index.js +1 -1
  80. package/dist/esm/features/soft_navigations/aggregate/index.js +2 -2
  81. package/dist/esm/features/soft_navigations/instrument/index.js +1 -1
  82. package/dist/esm/features/spa/aggregate/index.js +19 -10
  83. package/dist/esm/features/spa/instrument/index.js +1 -1
  84. package/dist/esm/features/utils/feature-base.js +0 -2
  85. package/dist/esm/loaders/agent-base.js +0 -2
  86. package/dist/esm/loaders/agent.js +1 -1
  87. package/dist/esm/loaders/api/api.js +8 -2
  88. package/dist/esm/loaders/configure/configure.js +1 -0
  89. package/dist/esm/loaders/micro-agent.js +4 -7
  90. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  91. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  92. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  93. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  94. package/dist/types/common/timer/interaction-timer.d.ts +2 -0
  95. package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
  96. package/dist/types/common/timing/time-keeper.d.ts +4 -9
  97. package/dist/types/common/timing/time-keeper.d.ts.map +1 -1
  98. package/dist/types/common/vitals/vital-metric.d.ts +1 -2
  99. package/dist/types/common/vitals/vital-metric.d.ts.map +1 -1
  100. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  101. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  102. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -1
  103. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  104. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  105. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  106. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  107. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  108. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  109. package/dist/types/features/session_replay/aggregate/index.d.ts +9 -2
  110. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  111. package/dist/types/features/session_replay/constants.d.ts +1 -0
  112. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  113. package/dist/types/features/session_replay/instrument/index.d.ts +1 -0
  114. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  115. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  116. package/dist/types/features/session_replay/shared/utils.d.ts +8 -0
  117. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -1
  118. package/dist/types/features/session_trace/aggregate/index.d.ts +2 -1
  119. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  120. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  121. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  122. package/dist/types/features/spa/aggregate/index.d.ts +0 -2
  123. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  124. package/dist/types/features/utils/feature-base.d.ts +0 -1
  125. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  126. package/dist/types/loaders/agent-base.d.ts +0 -2
  127. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  128. package/dist/types/loaders/api/api.d.ts.map +1 -1
  129. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  130. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  131. package/package.json +2 -2
  132. package/src/common/config/state/runtime.js +2 -1
  133. package/src/common/constants/runtime.js +1 -1
  134. package/src/common/context/__mocks__/shared-context.js +3 -0
  135. package/src/common/context/shared-context.js +1 -1
  136. package/src/common/harvest/harvest.js +2 -2
  137. package/src/common/session/session-entity.js +2 -1
  138. package/src/common/timer/interaction-timer.js +17 -2
  139. package/src/common/timing/__mocks__/time-keeper.js +2 -0
  140. package/src/common/timing/time-keeper.js +25 -22
  141. package/src/common/vitals/cumulative-layout-shift.js +10 -4
  142. package/src/common/vitals/first-contentful-paint.js +9 -4
  143. package/src/common/vitals/first-input-delay.js +11 -6
  144. package/src/common/vitals/first-paint.js +1 -1
  145. package/src/common/vitals/interaction-to-next-paint.js +10 -3
  146. package/src/common/vitals/largest-contentful-paint.js +19 -15
  147. package/src/common/vitals/long-task.js +0 -1
  148. package/src/common/vitals/time-to-first-byte.js +5 -4
  149. package/src/common/vitals/vital-metric.js +2 -4
  150. package/src/common/window/nreum.js +1 -1
  151. package/src/features/ajax/aggregate/index.js +3 -2
  152. package/src/features/ajax/instrument/index.js +1 -1
  153. package/src/features/jserrors/aggregate/index.js +18 -8
  154. package/src/features/jserrors/instrument/index.js +10 -5
  155. package/src/features/page_action/aggregate/index.js +3 -2
  156. package/src/features/page_view_event/aggregate/index.js +11 -5
  157. package/src/features/page_view_timing/aggregate/index.js +16 -6
  158. package/src/features/page_view_timing/instrument/index.js +1 -1
  159. package/src/features/session_replay/aggregate/index.js +53 -31
  160. package/src/features/session_replay/constants.js +2 -1
  161. package/src/features/session_replay/instrument/index.js +7 -2
  162. package/src/features/session_replay/shared/recorder.js +23 -5
  163. package/src/features/session_replay/shared/utils.js +12 -0
  164. package/src/features/session_trace/aggregate/index.js +19 -17
  165. package/src/features/session_trace/instrument/index.js +1 -1
  166. package/src/features/soft_navigations/aggregate/index.js +2 -2
  167. package/src/features/soft_navigations/instrument/index.js +1 -1
  168. package/src/features/spa/aggregate/index.js +19 -8
  169. package/src/features/spa/instrument/index.js +1 -1
  170. package/src/features/utils/feature-base.js +0 -3
  171. package/src/loaders/agent-base.js +0 -2
  172. package/src/loaders/agent.js +1 -1
  173. package/src/loaders/api/api.js +11 -2
  174. package/src/loaders/configure/configure.js +1 -0
  175. package/src/loaders/micro-agent.js +4 -6
  176. package/src/common/vitals/__mocks__/web-vitals.js +0 -19
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.256.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.255.0...v1.256.0) (2024-04-11)
7
+
8
+
9
+ ### Features
10
+
11
+ * Adjust Session Replay Error Tracking ([#951](https://github.com/newrelic/newrelic-browser-agent/issues/951)) ([91d65b5](https://github.com/newrelic/newrelic-browser-agent/commit/91d65b5b7b5b7e753a6603150fd4bb7d2543babd))
12
+ * Allow unmasking elements with nr-unmask selectors ([#949](https://github.com/newrelic/newrelic-browser-agent/issues/949)) ([e17aa25](https://github.com/newrelic/newrelic-browser-agent/commit/e17aa25ee098115ad23a5fb9ae268a4b5769fac1))
13
+ * Generate PTID in Agent ([#964](https://github.com/newrelic/newrelic-browser-agent/issues/964)) ([af7b676](https://github.com/newrelic/newrelic-browser-agent/commit/af7b6764f40cb1ddfb3ab2ca16d05d8e4f459f4e))
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * Resume Page Focus Now Checks Session State ([#961](https://github.com/newrelic/newrelic-browser-agent/issues/961)) ([e48af6b](https://github.com/newrelic/newrelic-browser-agent/commit/e48af6beb369daf6ddc8231daa040f0d9d204d5f))
19
+ * stabilize timestamp corrections ([#966](https://github.com/newrelic/newrelic-browser-agent/issues/966)) ([4fbe962](https://github.com/newrelic/newrelic-browser-agent/commit/4fbe962d7b268968df96da59058e2e53c527c5eb))
20
+
21
+ ## [1.255.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.254.1...v1.255.0) (2024-04-04)
22
+
23
+
24
+ ### Features
25
+
26
+ * Adjust SR Timestamps to NR Server Time ([#939](https://github.com/newrelic/newrelic-browser-agent/issues/939)) ([94f0dee](https://github.com/newrelic/newrelic-browser-agent/commit/94f0deed02a8f5e9d668f3fe5a68ada86cecc439))
27
+ * Send CLS as timing node additionally ([#935](https://github.com/newrelic/newrelic-browser-agent/issues/935)) ([88e71da](https://github.com/newrelic/newrelic-browser-agent/commit/88e71da521f1a58af28ae17fee13f648affd262a))
28
+ * Switch web vitals library to attribution build ([#919](https://github.com/newrelic/newrelic-browser-agent/issues/919)) ([f36acbc](https://github.com/newrelic/newrelic-browser-agent/commit/f36acbc03c4f4d51e65431a270a008e65bb2cfff))
29
+ * Update agent to use new relic server time ([#918](https://github.com/newrelic/newrelic-browser-agent/issues/918)) ([8a4831c](https://github.com/newrelic/newrelic-browser-agent/commit/8a4831cd1f2d32d97daa8788967b15d7f2f723d3))
30
+
6
31
  ## [1.254.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.254.0...v1.254.1) (2024-03-26)
7
32
 
8
33
 
@@ -30,7 +30,8 @@ const model = {
30
30
  xhrWrappable: typeof _runtime.globalScope.XMLHttpRequest?.prototype?.addEventListener === 'function',
31
31
  version: _env.VERSION,
32
32
  denyList: undefined,
33
- harvestCount: 0
33
+ harvestCount: 0,
34
+ timeKeeper: undefined
34
35
  };
35
36
  const _cache = {};
36
37
  function getRuntime(id) {
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = exports.VERSION = "1.254.1";
15
+ const VERSION = exports.VERSION = "1.256.0";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -28,4 +28,4 @@ const DIST_METHOD = exports.DIST_METHOD = 'CDN';
28
28
  /**
29
29
  * Exposes the lib version of rrweb
30
30
  */
31
- const RRWEB_VERSION = exports.RRWEB_VERSION = "2.0.0-alpha.11";
31
+ const RRWEB_VERSION = exports.RRWEB_VERSION = "2.0.0-alpha.12";
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = exports.VERSION = "1.254.1";
15
+ const VERSION = exports.VERSION = "1.256.0";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -29,4 +29,4 @@ const DIST_METHOD = exports.DIST_METHOD = 'NPM';
29
29
  /**
30
30
  * Exposes the lib version of rrweb
31
31
  */
32
- const RRWEB_VERSION = exports.RRWEB_VERSION = "2.0.0-alpha.11";
32
+ const RRWEB_VERSION = exports.RRWEB_VERSION = "2.0.0-alpha.12";
@@ -44,4 +44,4 @@ const ffVersion = exports.ffVersion = (() => {
44
44
  const isIE = exports.isIE = Boolean(isBrowserScope && window.document.documentMode); // deprecated property that only works in IE
45
45
 
46
46
  const supportsSendBeacon = exports.supportsSendBeacon = !!globalScope.navigator?.sendBeacon;
47
- const offset = exports.offset = Math.floor(globalScope?.performance?.timeOrigin || globalScope?.performance?.timing?.navigationStart || Date.now());
47
+ const offset = exports.offset = Math.floor(Date.now() - performance.now());
@@ -20,7 +20,7 @@ class SharedContext {
20
20
  if (Object.keys(model).includes(key)) this.sharedContext[key] = value;
21
21
  });
22
22
  } catch (err) {
23
- (0, _console.warn)('An error occured while setting SharedContext', err);
23
+ (0, _console.warn)('An error occurred while setting SharedContext', err);
24
24
  }
25
25
  }
26
26
  }
@@ -10,7 +10,6 @@ var submitData = _interopRequireWildcard(require("../util/submit-data"));
10
10
  var _location = require("../url/location");
11
11
  var _config = require("../config/config");
12
12
  var _cleanUrl = require("../url/clean-url");
13
- var _now = require("../timing/now");
14
13
  var _eventListenerOpts = require("../event-listener/event-listener-opts");
15
14
  var _obfuscate = require("../util/obfuscate");
16
15
  var _traverse = require("../util/traverse");
@@ -18,6 +17,7 @@ var _sharedContext = require("../context/shared-context");
18
17
  var _env = require("../constants/env.npm");
19
18
  var _runtime = require("../constants/runtime");
20
19
  var _console = require("../util/console");
20
+ var _now = require("../timing/now");
21
21
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
22
22
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
23
  /*
@@ -186,6 +186,7 @@ class Harvest extends _sharedContext.SharedContext {
186
186
  const cbResult = {
187
187
  sent: this.status !== 0,
188
188
  status: this.status,
189
+ failed: this.status === 0 || this.status >= 400,
189
190
  xhr: this,
190
191
  fullUrl
191
192
  };
@@ -127,7 +127,8 @@ class SessionEntity {
127
127
  this.write((0, _configurable.getModeledObject)(this.state, model));
128
128
  },
129
129
  ee: this.ee,
130
- refreshEvents: ['click', 'keydown', 'scroll']
130
+ refreshEvents: ['click', 'keydown', 'scroll'],
131
+ readStorage: () => this.storage.get(this.lookupKey)
131
132
  }, this.state.inactiveAt - Date.now());
132
133
  } else {
133
134
  this.state.inactiveAt = Infinity;
@@ -15,6 +15,9 @@ class InteractionTimer extends _timer.Timer {
15
15
  this.onRefresh = typeof opts.onRefresh === 'function' ? opts.onRefresh : () => {/* noop */};
16
16
  this.onResume = typeof opts.onResume === 'function' ? opts.onResume : () => {/* noop */};
17
17
 
18
+ /** used to double-check LS state at resume time */
19
+ this.readStorage = opts.readStorage;
20
+
18
21
  // used by pause/resume
19
22
  this.remainingMs = undefined;
20
23
  if (!opts.refreshEvents) opts.refreshEvents = ['click', 'keydown', 'scroll'];
@@ -68,8 +71,19 @@ class InteractionTimer extends _timer.Timer {
68
71
  this.remainingMs = this.initialMs - (Date.now() - this.startTimestamp);
69
72
  }
70
73
  resume() {
71
- this.refresh();
72
- this.onResume(); // emit resume event after state updated
74
+ try {
75
+ const lsData = this.readStorage();
76
+ const obj = typeof lsData === 'string' ? JSON.parse(lsData) : lsData;
77
+ if (isExpired(obj.expiresAt) || isExpired(obj.inactiveAt)) this.end();else {
78
+ this.refresh();
79
+ this.onResume(); // emit resume event after state updated
80
+ }
81
+ } catch (err) {
82
+ this.end();
83
+ }
84
+ function isExpired(timestamp) {
85
+ return Date.now() > timestamp;
86
+ }
73
87
  }
74
88
  refresh(cb, ms) {
75
89
  this.clear();
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.TimeKeeper = void 0;
7
- var _nreum = require("../window/nreum");
8
- var _config = require("../config/config");
9
7
  /**
10
8
  * Class used to adjust the timestamp of harvested data to New Relic server time. This
11
9
  * is done by tracking the performance timings of the RUM call and applying a calculation
12
10
  * to the harvested data event offset time.
13
11
  */
14
12
  class TimeKeeper {
15
- #agent;
13
+ /**
14
+ * Represents the browser origin time.
15
+ * @type {number}
16
+ */
17
+ #originTime;
16
18
 
17
19
  /**
18
20
  * Represents the browser origin time corrected to NR server time.
@@ -26,14 +28,23 @@ class TimeKeeper {
26
28
  * @type {number}
27
29
  */
28
30
  #localTimeDiff;
29
- constructor(agent) {
30
- this.#agent = agent;
31
+
32
+ /**
33
+ * Represents whether the timekeeper is in a state that it can accurately convert
34
+ * timestamps.
35
+ * @type {number}
36
+ */
37
+ #ready = false;
38
+ constructor() {
39
+ this.#originTime = Date.now() - performance.now();
40
+ }
41
+ get ready() {
42
+ return this.#ready;
31
43
  }
32
- static getTimeKeeperByAgentIdentifier(agentIdentifier) {
33
- const nr = (0, _nreum.gosNREUM)();
34
- return Object.keys(nr?.initializedAgents || {}).indexOf(agentIdentifier) > -1 ? nr.initializedAgents[agentIdentifier].timeKeeper : undefined;
44
+ get originTime() {
45
+ return this.#originTime;
35
46
  }
36
- get correctedPageOriginTime() {
47
+ get correctedOriginTime() {
37
48
  return this.#correctedOriginTime;
38
49
  }
39
50
 
@@ -53,17 +64,18 @@ class TimeKeeper {
53
64
 
54
65
  // Corrected page origin time
55
66
  this.#correctedOriginTime = Math.floor(Date.parse(responseDateHeader) - serverOffset);
56
- this.#localTimeDiff = (0, _config.getRuntime)(this.#agent.agentIdentifier).offset - this.#correctedOriginTime;
67
+ this.#localTimeDiff = this.#originTime - this.#correctedOriginTime;
57
68
  if (Number.isNaN(this.#correctedOriginTime)) {
58
69
  throw new Error('Date header invalid format.');
59
70
  }
71
+ this.#ready = true;
60
72
  }
61
73
 
62
74
  /**
63
75
  * Converts a page origin relative time to an absolute timestamp
64
76
  * corrected to NR server time.
65
77
  * @param relativeTime {number} The relative time of the event in milliseconds
66
- * @returns {number} The correct timestamp as a unix/epoch timestamp value
78
+ * @returns {number} Corrected unix/epoch timestamp
67
79
  */
68
80
  convertRelativeTimestamp(relativeTime) {
69
81
  return this.#correctedOriginTime + relativeTime;
@@ -77,13 +89,5 @@ class TimeKeeper {
77
89
  correctAbsoluteTimestamp(timestamp) {
78
90
  return Math.floor(timestamp - this.#localTimeDiff);
79
91
  }
80
-
81
- /**
82
- * Returns the current time offset from page origin.
83
- * @return {number}
84
- */
85
- now() {
86
- return Math.floor(performance.now());
87
- }
88
92
  }
89
93
  exports.TimeKeeper = TimeKeeper;
@@ -4,21 +4,28 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.cumulativeLayoutShift = void 0;
7
- var _webVitals = require("web-vitals");
7
+ var _attribution = require("web-vitals/attribution");
8
8
  var _constants = require("./constants");
9
9
  var _vitalMetric = require("./vital-metric");
10
10
  var _runtime = require("../constants/runtime");
11
11
  const cumulativeLayoutShift = exports.cumulativeLayoutShift = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.CUMULATIVE_LAYOUT_SHIFT, x => x);
12
12
  if (_runtime.isBrowserScope) {
13
- (0, _webVitals.onCLS)(_ref => {
13
+ (0, _attribution.onCLS)(_ref => {
14
14
  let {
15
15
  value,
16
- entries
16
+ attribution,
17
+ id
17
18
  } = _ref;
18
- if (cumulativeLayoutShift.roundingMethod(value) === cumulativeLayoutShift.current.value) return;
19
+ const attrs = {
20
+ metricId: id,
21
+ largestShiftTarget: attribution.largestShiftTarget,
22
+ largestShiftTime: attribution.largestShiftTime,
23
+ largestShiftValue: attribution.largestShiftValue,
24
+ loadState: attribution.loadState
25
+ };
19
26
  cumulativeLayoutShift.update({
20
27
  value,
21
- entries
28
+ attrs
22
29
  });
23
30
  }, {
24
31
  reportAllChanges: true
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.firstContentfulPaint = void 0;
7
- var _webVitals = require("web-vitals");
7
+ var _attribution = require("web-vitals/attribution");
8
8
  var _runtime = require("../constants/runtime");
9
9
  var _constants = require("./constants");
10
10
  var _vitalMetric = require("./vital-metric");
@@ -23,8 +23,7 @@ if (_runtime.isBrowserScope) {
23
23
  paintEntries.forEach(entry => {
24
24
  if (entry.name === 'first-contentful-paint') {
25
25
  firstContentfulPaint.update({
26
- value: Math.floor(entry.startTime),
27
- entries: paintEntries
26
+ value: Math.floor(entry.startTime)
28
27
  });
29
28
  }
30
29
  });
@@ -33,15 +32,20 @@ if (_runtime.isBrowserScope) {
33
32
  // ignore
34
33
  }
35
34
  } else {
36
- (0, _webVitals.onFCP)(_ref => {
35
+ (0, _attribution.onFCP)(_ref => {
37
36
  let {
38
37
  value,
39
- entries
38
+ attribution
40
39
  } = _ref;
41
40
  if (_runtime.initiallyHidden || firstContentfulPaint.isValid) return;
41
+ const attrs = {
42
+ timeToFirstByte: attribution.timeToFirstByte,
43
+ firstByteToFCP: attribution.firstByteToFCP,
44
+ loadState: attribution.loadState
45
+ };
42
46
  firstContentfulPaint.update({
43
47
  value,
44
- entries
48
+ attrs
45
49
  });
46
50
  });
47
51
  }
@@ -4,27 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.firstInputDelay = void 0;
7
- var _webVitals = require("web-vitals");
7
+ var _attribution = require("web-vitals/attribution");
8
8
  var _vitalMetric = require("./vital-metric");
9
9
  var _constants = require("./constants");
10
10
  var _runtime = require("../constants/runtime");
11
11
  const firstInputDelay = exports.firstInputDelay = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.FIRST_INPUT_DELAY);
12
12
  if (_runtime.isBrowserScope) {
13
- (0, _webVitals.onFID)(_ref => {
13
+ (0, _attribution.onFID)(_ref => {
14
14
  let {
15
15
  value,
16
- entries
16
+ attribution
17
17
  } = _ref;
18
- if (_runtime.initiallyHidden || firstInputDelay.isValid || entries.length === 0) return;
18
+ if (_runtime.initiallyHidden || firstInputDelay.isValid) return;
19
+ const attrs = {
20
+ type: attribution.eventType,
21
+ fid: Math.round(value),
22
+ eventTarget: attribution.eventTarget,
23
+ loadState: attribution.loadState
24
+ };
19
25
 
20
26
  // 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.
21
27
  firstInputDelay.update({
22
- value: entries[0].startTime,
23
- entries,
24
- attrs: {
25
- type: entries[0].name,
26
- fid: Math.round(value)
27
- }
28
+ value: attribution.eventTime,
29
+ attrs
28
30
  });
29
31
  });
30
32
  }
@@ -16,8 +16,7 @@ if (_runtime.isBrowserScope) {
16
16
 
17
17
  /* Initial hidden state and pre-rendering not yet considered for first paint. See web-vitals onFCP for example. */
18
18
  firstPaint.update({
19
- value: entry.startTime,
20
- entries
19
+ value: entry.startTime
21
20
  });
22
21
  }
23
22
  });
@@ -4,25 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.interactionToNextPaint = void 0;
7
- var _webVitals = require("web-vitals");
7
+ var _attribution = require("web-vitals/attribution");
8
8
  var _vitalMetric = require("./vital-metric");
9
9
  var _constants = require("./constants");
10
10
  var _runtime = require("../constants/runtime");
11
11
  const interactionToNextPaint = exports.interactionToNextPaint = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.INTERACTION_TO_NEXT_PAINT);
12
12
  if (_runtime.isBrowserScope) {
13
13
  /* Interaction-to-Next-Paint */
14
- (0, _webVitals.onINP)(_ref => {
14
+ (0, _attribution.onINP)(_ref => {
15
15
  let {
16
16
  value,
17
- entries,
17
+ attribution,
18
18
  id
19
19
  } = _ref;
20
+ const attrs = {
21
+ metricId: id,
22
+ eventTarget: attribution.eventTarget,
23
+ eventType: attribution.eventType,
24
+ eventTime: attribution.eventTime,
25
+ loadState: attribution.loadState
26
+ };
20
27
  interactionToNextPaint.update({
21
28
  value,
22
- entries,
23
- attrs: {
24
- metricId: id
25
- }
29
+ attrs
26
30
  });
27
31
  });
28
32
  }
@@ -4,36 +4,38 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.largestContentfulPaint = void 0;
7
- var _webVitals = require("web-vitals");
7
+ var _attribution = require("web-vitals/attribution");
8
8
  var _vitalMetric = require("./vital-metric");
9
9
  var _constants = require("./constants");
10
10
  var _runtime = require("../constants/runtime");
11
11
  var _cleanUrl = require("../url/clean-url");
12
12
  const largestContentfulPaint = exports.largestContentfulPaint = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.LARGEST_CONTENTFUL_PAINT);
13
13
  if (_runtime.isBrowserScope) {
14
- (0, _webVitals.onLCP)(_ref => {
14
+ (0, _attribution.onLCP)(_ref => {
15
15
  let {
16
16
  value,
17
- entries
17
+ attribution
18
18
  } = _ref;
19
19
  /* 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. */
20
20
  if (_runtime.initiallyHidden || largestContentfulPaint.isValid) return;
21
- 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...
21
+ let attrs;
22
+ const lcpEntry = attribution.lcpEntry;
23
+ if (lcpEntry) {
24
+ attrs = {
25
+ size: lcpEntry.size,
26
+ eid: lcpEntry.id,
27
+ element: attribution.element,
28
+ timeToFirstByte: attribution.timeToFirstByte,
29
+ resourceLoadDelay: attribution.resourceLoadDelay,
30
+ resourceLoadTime: attribution.resourceLoadTime,
31
+ elementRenderDelay: attribution.elementRenderDelay
32
+ };
33
+ if (attribution.url) attrs.elUrl = (0, _cleanUrl.cleanURL)(attribution.url);
34
+ if (lcpEntry.element?.tagName) attrs.elTag = lcpEntry.element.tagName;
35
+ }
22
36
  largestContentfulPaint.update({
23
37
  value,
24
- entries,
25
- ...(entries.length > 0 && {
26
- attrs: {
27
- size: lcpEntry.size,
28
- eid: lcpEntry.id,
29
- ...(!!lcpEntry.url && {
30
- elUrl: (0, _cleanUrl.cleanURL)(lcpEntry.url)
31
- }),
32
- ...(!!lcpEntry.element?.tagName && {
33
- elTag: lcpEntry.element.tagName
34
- })
35
- }
36
- })
38
+ attrs
37
39
  });
38
40
  });
39
41
  }
@@ -14,7 +14,6 @@ if (_runtime.isBrowserScope) {
14
14
  entries.forEach(entry => {
15
15
  longTask.update({
16
16
  value: entry.duration,
17
- entries: [entry],
18
17
  attrs: {
19
18
  ltFrame: entry.name,
20
19
  // MDN: the browsing context or frame that can be attributed to the long task
@@ -7,17 +7,20 @@ exports.timeToFirstByte = void 0;
7
7
  var _runtime = require("../constants/runtime");
8
8
  var _constants = require("./constants");
9
9
  var _vitalMetric = require("./vital-metric");
10
- var _webVitals = require("web-vitals");
10
+ var _attribution = require("web-vitals/attribution");
11
11
  const timeToFirstByte = exports.timeToFirstByte = new _vitalMetric.VitalMetric(_constants.VITAL_NAMES.TIME_TO_FIRST_BYTE);
12
12
  if (_runtime.isBrowserScope && typeof PerformanceNavigationTiming !== 'undefined' && !_runtime.isiOS) {
13
- (0, _webVitals.onTTFB)(_ref => {
13
+ (0, _attribution.onTTFB)(_ref => {
14
14
  let {
15
15
  value,
16
- entries
16
+ attribution
17
17
  } = _ref;
18
- if (!timeToFirstByte.isValid) timeToFirstByte.update({
18
+ if (timeToFirstByte.isValid) return;
19
+ timeToFirstByte.update({
19
20
  value,
20
- entries
21
+ attrs: {
22
+ navigationEntry: attribution.navigationEntry
23
+ }
21
24
  });
22
25
  });
23
26
  } else {
@@ -29,7 +32,9 @@ if (_runtime.isBrowserScope && typeof PerformanceNavigationTiming !== 'undefined
29
32
  // ttfb is equiv to document's responseStart property in timing API --> https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming/responseStart
30
33
  timeToFirstByte.update({
31
34
  value: entry.responseStart,
32
- entries: [entry]
35
+ attrs: {
36
+ navigationEntry: entry
37
+ }
33
38
  });
34
39
  }
35
40
  }
@@ -15,20 +15,18 @@ class VitalMetric {
15
15
  update(_ref) {
16
16
  let {
17
17
  value,
18
- entries = [],
19
18
  attrs = {}
20
19
  } = _ref;
21
20
  if (value < 0) return;
22
21
  const state = {
23
22
  value: this.roundingMethod(value),
24
23
  name: this.name,
25
- entries,
26
24
  attrs
27
25
  };
28
26
  this.history.push(state);
29
27
  this.#subscribers.forEach(cb => {
30
28
  try {
31
- cb(this.current);
29
+ cb(state);
32
30
  } catch (e) {
33
31
  // ignore errors
34
32
  }
@@ -38,7 +36,6 @@ class VitalMetric {
38
36
  return this.history[this.history.length - 1] || {
39
37
  value: undefined,
40
38
  name: this.name,
41
- entries: [],
42
39
  attrs: {}
43
40
  };
44
41
  }
@@ -14,8 +14,8 @@ exports.gosNREUMInit = gosNREUMInit;
14
14
  exports.gosNREUMLoaderConfig = gosNREUMLoaderConfig;
15
15
  exports.gosNREUMOriginals = gosNREUMOriginals;
16
16
  exports.setNREUMInitializedAgent = setNREUMInitializedAgent;
17
- var _now = require("../timing/now");
18
17
  var _runtime = require("../constants/runtime");
18
+ var _now = require("../timing/now");
19
19
  const defaults = exports.defaults = {
20
20
  beacon: 'bam.nr-data.net',
21
21
  errorBeacon: 'bam.nr-data.net'
@@ -36,7 +36,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
36
36
  scheduler.startTimer(harvestTimeSeconds);
37
37
  this.drain();
38
38
  });
39
- const denyList = (0, _config.getRuntime)(agentIdentifier).denyList;
39
+ const agentRuntime = (0, _config.getRuntime)(agentIdentifier);
40
+ const denyList = agentRuntime.denyList;
40
41
  (0, _denyList.setDenyList)(denyList);
41
42
  let ajaxEvents = [];
42
43
  let spaAjaxEvents = {};
@@ -122,7 +123,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
122
123
  if (xhrContext.dt) {
123
124
  event.spanId = xhrContext.dt.spanId;
124
125
  event.traceId = xhrContext.dt.traceId;
125
- event.spanTimestamp = xhrContext.dt.timestamp;
126
+ event.spanTimestamp = agentRuntime.timeKeeper.correctAbsoluteTimestamp(xhrContext.dt.timestamp);
126
127
  }
127
128
 
128
129
  // parsed from the AJAX body, looking for operationName param & parsing query for operationType
@@ -10,7 +10,6 @@ var _id = require("../../../common/ids/id");
10
10
  var _runtime = require("../../../common/constants/runtime");
11
11
  var _dataSize = require("../../../common/util/data-size");
12
12
  var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
13
- var _now = require("../../../common/timing/now");
14
13
  var _wrap = require("../../../common/wrap");
15
14
  var _parseUrl = require("../../../common/url/parse-url");
16
15
  var _distributedTracing = require("./distributed-tracing");
@@ -19,6 +18,7 @@ var _instrumentBase = require("../../utils/instrument-base");
19
18
  var _constants = require("../constants");
20
19
  var _features = require("../../../loaders/features/features");
21
20
  var _constants2 = require("../../metrics/constants");
21
+ var _now = require("../../../common/timing/now");
22
22
  /*
23
23
  * Copyright 2020 New Relic Corporation. All rights reserved.
24
24
  * SPDX-License-Identifier: Apache-2.0