@newrelic/browser-agent 1.320.1 → 1.321.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 (169) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/common/config/runtime.js +3 -0
  3. package/dist/cjs/common/constants/env.cdn.js +1 -1
  4. package/dist/cjs/common/constants/env.npm.js +1 -1
  5. package/dist/cjs/common/dom/selector-path.js +1 -1
  6. package/dist/cjs/common/event-listener/event-listener-opts.js +1 -1
  7. package/dist/cjs/common/harvest/connector.js +202 -0
  8. package/dist/cjs/common/harvest/harvester.js +5 -8
  9. package/dist/cjs/common/harvest/send.js +8 -7
  10. package/dist/cjs/common/session/session-entity.js +1 -1
  11. package/dist/cjs/common/timer/interaction-timer.js +2 -2
  12. package/dist/cjs/common/unload/eol.js +3 -3
  13. package/dist/cjs/common/util/console.js +2 -1
  14. package/dist/cjs/common/util/feature-flags.js +2 -1
  15. package/dist/cjs/common/v2/constants.js +21 -0
  16. package/dist/cjs/common/v2/utils.js +25 -23
  17. package/dist/cjs/common/window/page-visibility.js +1 -1
  18. package/dist/cjs/common/wrap/wrap-events.js +4 -3
  19. package/dist/cjs/common/wrap/wrap-fetch.js +2 -2
  20. package/dist/cjs/common/wrap/wrap-function.js +1 -1
  21. package/dist/cjs/common/wrap/wrap-history.js +3 -2
  22. package/dist/cjs/common/wrap/wrap-xhr.js +2 -2
  23. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  24. package/dist/cjs/features/generic_events/aggregate/index.js +1 -1
  25. package/dist/cjs/features/generic_events/instrument/index.js +1 -1
  26. package/dist/cjs/features/jserrors/aggregate/index.js +5 -5
  27. package/dist/cjs/features/logging/instrument/index.js +1 -1
  28. package/dist/cjs/features/page_view_event/aggregate/index.js +2 -6
  29. package/dist/cjs/features/page_view_event/aggregate_v2/index.js +109 -0
  30. package/dist/cjs/features/page_view_event/instrument/index.js +6 -1
  31. package/dist/cjs/features/page_view_timing/aggregate/index.js +5 -1
  32. package/dist/cjs/features/session_replay/instrument/index.js +9 -0
  33. package/dist/cjs/features/session_replay/shared/recorder.js +2 -1
  34. package/dist/cjs/features/session_replay/shared/utils.js +3 -5
  35. package/dist/cjs/features/session_trace/instrument/index.js +3 -3
  36. package/dist/cjs/features/soft_navigations/instrument/index.js +2 -2
  37. package/dist/cjs/features/utils/aggregate-base.js +0 -12
  38. package/dist/cjs/features/utils/instrument-base.js +72 -29
  39. package/dist/cjs/loaders/agent.js +2 -1
  40. package/dist/cjs/loaders/api/consent.js +2 -2
  41. package/dist/cjs/loaders/api/register.js +26 -13
  42. package/dist/cjs/loaders/configure/configure.js +14 -0
  43. package/dist/cjs/loaders/features/features.js +2 -1
  44. package/dist/esm/common/config/runtime.js +3 -0
  45. package/dist/esm/common/constants/env.cdn.js +1 -1
  46. package/dist/esm/common/constants/env.npm.js +1 -1
  47. package/dist/esm/common/dom/selector-path.js +1 -1
  48. package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
  49. package/dist/esm/common/harvest/connector.js +195 -0
  50. package/dist/esm/common/harvest/harvester.js +5 -8
  51. package/dist/esm/common/harvest/send.js +10 -9
  52. package/dist/esm/common/session/session-entity.js +1 -1
  53. package/dist/esm/common/timer/interaction-timer.js +2 -2
  54. package/dist/esm/common/unload/eol.js +3 -3
  55. package/dist/esm/common/util/console.js +2 -1
  56. package/dist/esm/common/util/feature-flags.js +2 -1
  57. package/dist/esm/common/v2/constants.js +15 -0
  58. package/dist/esm/common/v2/utils.js +24 -22
  59. package/dist/esm/common/window/page-visibility.js +1 -1
  60. package/dist/esm/common/wrap/wrap-events.js +4 -3
  61. package/dist/esm/common/wrap/wrap-fetch.js +2 -2
  62. package/dist/esm/common/wrap/wrap-function.js +1 -1
  63. package/dist/esm/common/wrap/wrap-history.js +3 -2
  64. package/dist/esm/common/wrap/wrap-xhr.js +2 -2
  65. package/dist/esm/features/ajax/aggregate/index.js +2 -2
  66. package/dist/esm/features/generic_events/aggregate/index.js +1 -1
  67. package/dist/esm/features/generic_events/instrument/index.js +1 -1
  68. package/dist/esm/features/jserrors/aggregate/index.js +6 -6
  69. package/dist/esm/features/logging/instrument/index.js +1 -1
  70. package/dist/esm/features/page_view_event/aggregate/index.js +2 -6
  71. package/dist/esm/features/page_view_event/aggregate_v2/index.js +100 -0
  72. package/dist/esm/features/page_view_event/instrument/index.js +6 -1
  73. package/dist/esm/features/page_view_timing/aggregate/index.js +5 -1
  74. package/dist/esm/features/session_replay/instrument/index.js +9 -0
  75. package/dist/esm/features/session_replay/shared/recorder.js +2 -1
  76. package/dist/esm/features/session_replay/shared/utils.js +3 -5
  77. package/dist/esm/features/session_trace/instrument/index.js +3 -3
  78. package/dist/esm/features/soft_navigations/instrument/index.js +2 -2
  79. package/dist/esm/features/utils/aggregate-base.js +0 -12
  80. package/dist/esm/features/utils/instrument-base.js +71 -28
  81. package/dist/esm/loaders/agent.js +2 -1
  82. package/dist/esm/loaders/api/consent.js +2 -2
  83. package/dist/esm/loaders/api/register.js +19 -6
  84. package/dist/esm/loaders/configure/configure.js +14 -0
  85. package/dist/esm/loaders/features/features.js +1 -0
  86. package/dist/tsconfig.tsbuildinfo +1 -1
  87. package/dist/types/common/config/runtime.d.ts.map +1 -1
  88. package/dist/types/common/event-listener/event-listener-opts.d.ts +1 -1
  89. package/dist/types/common/harvest/connector.d.ts +6 -0
  90. package/dist/types/common/harvest/connector.d.ts.map +1 -0
  91. package/dist/types/common/harvest/harvester.d.ts.map +1 -1
  92. package/dist/types/common/harvest/send.d.ts.map +1 -1
  93. package/dist/types/common/unload/eol.d.ts +1 -1
  94. package/dist/types/common/unload/eol.d.ts.map +1 -1
  95. package/dist/types/common/util/console.d.ts +2 -1
  96. package/dist/types/common/util/console.d.ts.map +1 -1
  97. package/dist/types/common/v2/constants.d.ts +9 -0
  98. package/dist/types/common/v2/constants.d.ts.map +1 -0
  99. package/dist/types/common/v2/utils.d.ts +36 -11
  100. package/dist/types/common/v2/utils.d.ts.map +1 -1
  101. package/dist/types/common/wrap/wrap-events.d.ts +2 -1
  102. package/dist/types/common/wrap/wrap-events.d.ts.map +1 -1
  103. package/dist/types/common/wrap/wrap-history.d.ts +2 -1
  104. package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
  105. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  106. package/dist/types/features/page_view_event/aggregate_v2/index.d.ts +20 -0
  107. package/dist/types/features/page_view_event/aggregate_v2/index.d.ts.map +1 -0
  108. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  109. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  110. package/dist/types/features/session_replay/instrument/index.d.ts +1 -0
  111. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  112. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  113. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -1
  114. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  115. package/dist/types/features/utils/aggregate-base.d.ts +0 -5
  116. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  117. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  118. package/dist/types/loaders/agent.d.ts.map +1 -1
  119. package/dist/types/loaders/api/register.d.ts.map +1 -1
  120. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  121. package/dist/types/loaders/features/features.d.ts +1 -0
  122. package/dist/types/loaders/features/features.d.ts.map +1 -1
  123. package/package.json +1 -1
  124. package/src/common/config/runtime.js +3 -0
  125. package/src/common/dom/selector-path.js +1 -1
  126. package/src/common/event-listener/event-listener-opts.js +1 -1
  127. package/src/common/harvest/connector.js +170 -0
  128. package/src/common/harvest/harvester.js +7 -9
  129. package/src/common/harvest/send.js +9 -7
  130. package/src/common/session/session-entity.js +1 -1
  131. package/src/common/timer/interaction-timer.js +2 -2
  132. package/src/common/unload/eol.js +3 -3
  133. package/src/common/util/console.js +2 -1
  134. package/src/common/util/feature-flags.js +1 -1
  135. package/src/common/v2/constants.js +15 -0
  136. package/src/common/v2/utils.js +23 -21
  137. package/src/common/window/page-visibility.js +1 -1
  138. package/src/common/wrap/wrap-events.js +4 -3
  139. package/src/common/wrap/wrap-fetch.js +2 -2
  140. package/src/common/wrap/wrap-function.js +1 -1
  141. package/src/common/wrap/wrap-history.js +3 -2
  142. package/src/common/wrap/wrap-xhr.js +2 -2
  143. package/src/features/ajax/aggregate/index.js +2 -2
  144. package/src/features/generic_events/aggregate/index.js +1 -1
  145. package/src/features/generic_events/instrument/index.js +1 -1
  146. package/src/features/jserrors/aggregate/index.js +6 -6
  147. package/src/features/logging/instrument/index.js +1 -1
  148. package/src/features/page_view_event/aggregate/index.js +2 -6
  149. package/src/features/page_view_event/aggregate_v2/index.js +97 -0
  150. package/src/features/page_view_event/instrument/index.js +6 -1
  151. package/src/features/page_view_timing/aggregate/index.js +5 -1
  152. package/src/features/session_replay/instrument/index.js +9 -0
  153. package/src/features/session_replay/shared/recorder.js +2 -1
  154. package/src/features/session_replay/shared/utils.js +3 -5
  155. package/src/features/session_trace/instrument/index.js +3 -3
  156. package/src/features/soft_navigations/instrument/index.js +2 -2
  157. package/src/features/utils/aggregate-base.js +0 -12
  158. package/src/features/utils/instrument-base.js +71 -25
  159. package/src/loaders/agent.js +2 -1
  160. package/src/loaders/api/consent.js +2 -2
  161. package/src/loaders/api/register.js +16 -6
  162. package/src/loaders/configure/configure.js +12 -0
  163. package/src/loaders/features/features.js +1 -0
  164. package/dist/cjs/common/url/location.js +0 -18
  165. package/dist/esm/common/url/location.js +0 -12
  166. package/dist/types/common/url/location.d.ts +0 -10
  167. package/dist/types/common/url/location.d.ts.map +0 -1
  168. package/src/common/url/__mocks__/location.js +0 -5
  169. package/src/common/url/location.js +0 -12
@@ -4,17 +4,24 @@
4
4
  */
5
5
 
6
6
  import { extractUrlsFromStack, getDeepStackTrace } from './script-tracker';
7
+ import { V2_TYPES } from './constants';
7
8
 
8
9
  /**
9
- * @enum {string}
10
- * @readonly
10
+ * @typedef {Object} V2Target
11
+ * @property {'BA'} type always V2_TYPES.BA -- identifies this as the container (main) agent, not a registered MFE
12
+ * @property {string} instance the container agent's agentIdentifier
13
+ * @property {string} [id] the container agent's entity guid, once known (getter, resolved asynchronously)
14
+ * @property {{[key:string]: any}} attributes the V2 payload attributes for the container agent (getter)
11
15
  */
12
- export const V2_TYPES = {
13
- /** Micro Frontend */
14
- MFE: 'MFE',
15
- /** Browser Application */
16
- BA: 'BA'
17
- };
16
+
17
+ /**
18
+ * Determines if a given target represents a registered MFE (as opposed to the container agent).
19
+ * @param {*} target the target to check
20
+ * @returns {boolean} true if the target is a registered MFE target
21
+ */
22
+ export function isMfeTarget(target) {
23
+ return target?.type === V2_TYPES.MFE;
24
+ }
18
25
 
19
26
  /**
20
27
  * Returns a single registered entity associated with a given iframe interface ID. Returns undefined if no entity is found.
@@ -110,14 +117,8 @@ export function dedupeRegisteredEntitiesByAsset(entities) {
110
117
  */
111
118
  export function getVersion2Attributes(target, aggregateInstance) {
112
119
  if (!supportsV2(aggregateInstance)) return {};
113
- const containerAgentEntityGuid = aggregateInstance.agentRef.runtime.appMetadata.agents[0].entityGuid;
114
- /** if there's no target, but we are in v2 mode, this means the data belongs to the container agent */
115
- if (!target) {
116
- return {
117
- 'entity.guid': containerAgentEntityGuid,
118
- appId: aggregateInstance.agentRef.info.applicationID
119
- };
120
- }
120
+ /** if the target isn't a registered MFE, but we are in v2 mode, this means the data belongs to the container agent */
121
+ if (!isMfeTarget(target)) return aggregateInstance.agentRef.runtime.v2Target.attributes;
121
122
  /** otherwise, the data belongs to the target (MFE) and should be attributed as such */
122
123
  return target.attributes;
123
124
  }
@@ -147,16 +148,17 @@ export function getVersion2DuplicationAttributes(target, aggregateInstance) {
147
148
  * @returns {boolean} returns true if the event should be duplicated for the target, false otherwise
148
149
  */
149
150
  export function shouldDuplicate(target, aggregateInstance) {
150
- return !!target && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.register.duplicate_data_to_container;
151
+ return isMfeTarget(target) && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.register.duplicate_data_to_container;
151
152
  }
152
153
 
153
154
  /**
154
155
  * Finds the registered targets from the stack trace for a given agent reference.
155
156
  * @param {*} agentRef The agent reference to use for finding targets.
156
- * @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array with undefined.
157
+ * @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array containing the container target.
157
158
  */
158
159
  export function findTargetsFromStackTrace(agentRef) {
159
- if (!isValid(true, agentRef) || !agentRef?.runtime?.registeredEntities?.length) return [undefined];
160
+ if (!agentRef?.runtime) return [];
161
+ if (!isValid(true, agentRef) || !agentRef.runtime.registeredEntities?.length) return [agentRef.runtime.v2Target];
160
162
  const targets = [];
161
163
  try {
162
164
  var urls = extractUrlsFromStack(getDeepStackTrace());
@@ -168,15 +170,15 @@ export function findTargetsFromStackTrace(agentRef) {
168
170
  // Silent catch to prevent errors from propagating
169
171
  }
170
172
  const deduped = dedupeTargetsByInstance(targets);
171
- if (!deduped.length) deduped.push(undefined); // if we can't find any targets from the stack trace, return an array with undefined to signify the container agent is the target
173
+ if (!deduped.length) deduped.push(agentRef.runtime.v2Target); // if we can't find any targets from the stack trace, the container agent is the target
172
174
  return deduped;
173
175
  }
174
176
 
175
177
  /**
176
178
  * Removes duplicate targets from an array, keyed by `target.instance`. This guards against the same canonical
177
179
  * target re-entering the array via multiple matched stack-frame URLs (e.g. a recursive call whose stack contains the
178
- * same file at multiple depths). Entries with no `instance` (i.e. `undefined`, meaning "the container agent")
179
- * naturally collapse to a single entry too, which is the desired behavior.
180
+ * same file at multiple depths). Multiple container-target entries (whose `instance` is the container agent's stable
181
+ * `agentIdentifier`) naturally collapse to a single entry too, which is the desired behavior.
180
182
  * @param {Array} targets
181
183
  * @returns {Array} deduped list of targets, preserving relative order of first occurrence
182
184
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -23,16 +23,17 @@ const flag = "nr@wrapped:".concat(contextId);
23
23
  * `document` (if in a browser scope). Adds custom events in context of a new emitter scoped only to these methods.
24
24
  * @param {Object} sharedEE - The shared event emitter on which a new scoped
25
25
  * event emitter will be based.
26
+ * @param {*} [agentRef] - The agent reference, used to attribute wrapped calls to the correct v2 target.
26
27
  * @returns {Object} Scoped event emitter with a debug ID of `events`.
27
28
  */
28
- export function wrapEvents(sharedEE) {
29
+ export function wrapEvents(sharedEE, agentRef) {
29
30
  var ee = scopedEE(sharedEE);
30
31
 
31
32
  // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
32
33
  // then we increment the count to track # of feats using this at runtime.
33
34
  if (wrapped[ee.debugId]++) return ee;
34
35
  wrapped[ee.debugId] = 1; // otherwise, first feature to wrap events
35
- var wrapFn = wfn(ee, true);
36
+ var wrapFn = wfn(ee, true, agentRef);
36
37
 
37
38
  // Guard against instrumenting environments w/o necessary features
38
39
  if ('getPrototypeOf' in Object) {
@@ -44,8 +44,8 @@ export function wrapFetch(sharedEE, agentRef) {
44
44
  wrapPromiseMethod(globalScope, 'fetch', prefix);
45
45
  ee.on(prefix + 'end', function (err, res, targets) {
46
46
  var ctx = this;
47
- // undefined target reports to container
48
- ctx.targets = targets || [undefined];
47
+ // default target reports to container
48
+ ctx.targets = targets || [agentRef.runtime.v2Target];
49
49
  if (res) {
50
50
  var size = res.headers.get('content-length');
51
51
  if (size !== null) {
@@ -82,7 +82,7 @@ export function createWrapperWithEmitter(emitter, always, agentRef) {
82
82
 
83
83
  // certain wrappers can inform the function wrapper to evaluate the stack of the executed wrapped function to find targets of the execution
84
84
  // (e.g. wrap-logger can inform this method to find try to find the MFE source of a console.log)
85
- targets = evaluateStack ? findTargetsFromStackTrace(agentRef) : [undefined]; // undefined target always maps to the container agent
85
+ targets = evaluateStack ? findTargetsFromStackTrace(agentRef) : [agentRef?.runtime?.v2Target]; // default target always maps to the container agent
86
86
 
87
87
  if (typeof getContext === 'function') {
88
88
  ctx = getContext(args, originalThis);
@@ -17,9 +17,10 @@ const HISTORY_FNS = ['pushState', 'replaceState'];
17
17
  * Wraps the `pushState` and `replaceState` methods of `window.history` and returns a corresponding event emitter
18
18
  * scoped to the history object.
19
19
  * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
20
+ * @param {*} [agentRef] - The agent reference, used to attribute wrapped calls to the correct v2 target.
20
21
  * @returns {Object} Scoped event emitter with a debug ID of `history`.
21
22
  */
22
- export function wrapHistory(sharedEE) {
23
+ export function wrapHistory(sharedEE, agentRef) {
23
24
  const ee = scopedEE(sharedEE);
24
25
 
25
26
  // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
@@ -28,7 +29,7 @@ export function wrapHistory(sharedEE) {
28
29
  if (!isBrowserScope || wrapped[ee.debugId]++) return ee;
29
30
  wrapped[ee.debugId] = 1; // otherwise, first feature to wrap history
30
31
 
31
- var wrapFn = wfn(ee);
32
+ var wrapFn = wfn(ee, undefined, agentRef);
32
33
  /*
33
34
  * For objects that will be instantiated more than once, we wrap the object's prototype methods. The history object
34
35
  * is instantiated only once, so we can wrap its methods directly--and we must wrap the history methods directly as
@@ -35,8 +35,8 @@ export function wrapXhr(sharedEE, agentRef) {
35
35
  if (wrapped[ee.debugId]++) return ee;
36
36
  wrapped[ee.debugId] = 1; // otherwise, first feature to wrap XHR
37
37
 
38
- wrapEvents(baseEE); // wrap-events patches XMLHttpRequest.prototype.addEventListener for us
39
- var wrapFn = wfn(ee);
38
+ wrapEvents(baseEE, agentRef); // wrap-events patches XMLHttpRequest.prototype.addEventListener for us
39
+ var wrapFn = wfn(ee, undefined, agentRef);
40
40
  var OrigXHR = globalScope.XMLHttpRequest;
41
41
  var MutationObserver = globalScope.MutationObserver;
42
42
  var Promise = globalScope.Promise;
@@ -14,7 +14,7 @@ import { gosNREUMOriginals } from '../../../common/window/nreum';
14
14
  import { hasGQLErrors, parseGQL } from './gql';
15
15
  import { canCapturePayload, isLikelyHumanReadable, parseQueryString, createStringAdders } from '../../../common/payloads/payloads';
16
16
  import { Obfuscator } from '../../../common/util/obfuscate';
17
- import { getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate } from '../../../common/v2/utils';
17
+ import { getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate, isMfeTarget } from '../../../common/v2/utils';
18
18
  import { EVENT_TYPES } from '../../../common/constants/events';
19
19
  import { generateUuid } from '../../../common/ids/unique-id';
20
20
  export class Aggregate extends AggregateBase {
@@ -119,7 +119,7 @@ export class Aggregate extends AggregateBase {
119
119
  if (event.gql) this.reportSupportabilityMetric('Ajax/Events/GraphQL/Bytes-Added', stringify(event.gql).length);
120
120
 
121
121
  /** make a copy of the event for the MFE target if it exists */
122
- if (target) {
122
+ if (isMfeTarget(target)) {
123
123
  this.events.add({
124
124
  ...event,
125
125
  targetAttributes: getVersion2Attributes(target, this)
@@ -255,7 +255,7 @@ export class Aggregate extends AggregateBase {
255
255
  this.addEvent(event, target);
256
256
  }, this.featureName, this.ee);
257
257
  if (agentRef.init.feature_flags.includes('websockets') || agentRef.init.web_sockets?.enabled) {
258
- registerHandler('ws-complete', (nrData, targets = [undefined]) => {
258
+ registerHandler('ws-complete', (nrData, targets = [agentRef.runtime.v2Target]) => {
259
259
  targets.forEach(target => {
260
260
  const event = {
261
261
  ...nrData,
@@ -58,7 +58,7 @@ export class Instrument extends InstrumentBase {
58
58
  if (isBrowserScope) {
59
59
  wrapFetch(this.ee, agentRef);
60
60
  wrapXhr(this.ee, agentRef);
61
- historyEE = wrapHistory(this.ee);
61
+ historyEE = wrapHistory(this.ee, agentRef);
62
62
  if (agentRef.init.user_actions.enabled) {
63
63
  OBSERVED_EVENTS.forEach(eventType => windowAddEventListener(eventType, evt => handle('ua', [evt], undefined, this.featureName, this.ee), true));
64
64
  OBSERVED_WINDOW_EVENTS.forEach(eventType => {
@@ -17,7 +17,7 @@ import { AggregateBase } from '../../utils/aggregate-base';
17
17
  import { now } from '../../../common/timing/now';
18
18
  import { Obfuscator } from '../../../common/util/obfuscate';
19
19
  import { evaluateInternalError } from './internal-errors';
20
- import { getRegisteredTargetsFromFilename, getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate } from '../../../common/v2/utils';
20
+ import { getRegisteredTargetsFromFilename, getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate, isMfeTarget } from '../../../common/v2/utils';
21
21
  import { buildCauseString } from './cause-string';
22
22
  import { ShortCircuit } from '../../../common/util/short-circuit';
23
23
  import { EVENT_TYPES } from '../../../common/constants/events';
@@ -205,7 +205,7 @@ export class Aggregate extends AggregateBase {
205
205
  if (targets.length) break;
206
206
  }
207
207
  }
208
- if (!targets.length) targets.push(undefined);
208
+ if (!targets.length) targets.push(this.agentRef.runtime.v2Target);
209
209
  }
210
210
  return targets;
211
211
  }
@@ -249,7 +249,7 @@ export class Aggregate extends AggregateBase {
249
249
  if (filterOutput?.group) params.errorGroup = filterOutput.group;
250
250
 
251
251
  // Should only decorate "hasReplay" for the container agent, so check if the target matches the config
252
- if (hasReplay && !target) params.hasReplay = hasReplay;
252
+ if (hasReplay && !isMfeTarget(target)) params.hasReplay = hasReplay;
253
253
  /**
254
254
  * The bucketHash is different from the params.stackHash because the params.stackHash is based on the canonicalized
255
255
  * stack trace and is used downstream in NR1 to attempt to group the same errors across different browsers. However,
@@ -284,13 +284,13 @@ export class Aggregate extends AggregateBase {
284
284
 
285
285
  // Trace sends the error in its payload, and both trace & replay simply listens for any error to occur.
286
286
  const jsErrorEvent = [type, bucketHash, params, newMetrics, customAttributes];
287
- if (!target) handle('trace-jserror', jsErrorEvent, undefined, FEATURE_NAMES.sessionTrace, this.ee);
287
+ if (!isMfeTarget(target)) handle('trace-jserror', jsErrorEvent, undefined, FEATURE_NAMES.sessionTrace, this.ee);
288
288
  // still send EE events for other features such as above, but stop this one from aggregating internal data
289
289
  if (this.blocked) return;
290
290
  if (err.__newrelic?.socketId) {
291
291
  customAttributes.socketId = err.__newrelic.socketId;
292
292
  }
293
- if (!target) {
293
+ if (!isMfeTarget(target)) {
294
294
  const softNavInUse = Boolean(this.agentRef.features?.[FEATURE_NAMES.softNav]);
295
295
  if (softNavInUse) {
296
296
  // pass the error to soft nav for evaluation - it will return it via 'returnJserror' when interaction is resolved
@@ -301,7 +301,7 @@ export class Aggregate extends AggregateBase {
301
301
  }
302
302
 
303
303
  // always add directly if scoped to a sub-entity, the other pathways above will be deterministic if the main agent should procede
304
- if (target) this.#storeJserrorForHarvest(jsErrorEvent, {}, target);
304
+ if (isMfeTarget(target)) this.#storeJserrorForHarvest(jsErrorEvent, {}, target);
305
305
  }
306
306
 
307
307
  /**
@@ -30,7 +30,7 @@ export class Instrument extends InstrumentBase {
30
30
  });
31
31
 
32
32
  /** emitted by wrap-logger function */
33
- this.ee.on('wrap-logger-end', function handleLog([message], _, __, targets = []) {
33
+ this.ee.on('wrap-logger-end', function handleLog([message], _, __, targets = [agentRef.runtime.v2Target]) {
34
34
  const {
35
35
  level,
36
36
  customAttributes,
@@ -132,9 +132,7 @@ export class Aggregate extends AggregateBase {
132
132
  return queryParameters;
133
133
  };
134
134
  this.events.add(body);
135
- if (this.agentRef.runtime.harvester.triggerHarvestFor(this, {
136
- sendEmptyBody: true
137
- }).ranSend) this.sentRum = true;
135
+ if (this.agentRef.runtime.harvester.triggerHarvestFor(this).ranSend) this.sentRum = true;
138
136
  }
139
137
  serializer(eventBuffer) {
140
138
  // this is necessary because PVE sends a single item rather than an array; in the case of undefined, this prevents sending [null] as body
@@ -175,9 +173,7 @@ export class Aggregate extends AggregateBase {
175
173
 
176
174
  if (this.isRetrying && this.retries++ < 1) {
177
175
  // Only retry once
178
- setTimeout(() => this.agentRef.runtime.harvester.triggerHarvestFor(this, {
179
- sendEmptyBody: true
180
- }), 5000); // Retry sending the RUM event after 5 seconds
176
+ setTimeout(() => this.agentRef.runtime.harvester.triggerHarvestFor(this), 5000); // Retry sending the RUM event after 5 seconds
181
177
  return;
182
178
  }
183
179
  if (status >= 400 || status === 0) {
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { globalScope, isBrowserScope, originTime, getNavigationEntry } from '../../../common/constants/runtime';
6
+ import { addPT, addPN } from '../../../common/timing/nav-timing';
7
+ import { stringify } from '../../../common/util/stringify';
8
+ import * as CONSTANTS from '../constants';
9
+ import { getActivatedFeaturesFlags } from '../aggregate/initialized-features';
10
+ import { AggregateBase } from '../../utils/aggregate-base';
11
+ import { firstContentfulPaint } from '../../../common/vitals/first-contentful-paint';
12
+ import { firstPaint } from '../../../common/vitals/first-paint';
13
+ import { timeToFirstByte } from '../../../common/vitals/time-to-first-byte';
14
+ import { Obfuscator } from '../../../common/util/obfuscate';
15
+ import { webdriverDetected } from '../../../common/util/webdriver-detection';
16
+ import { EVENT_TYPES } from '../../../common/constants/events';
17
+ export class Aggregate extends AggregateBase {
18
+ static featureName = CONSTANTS.FEATURE_NAME;
19
+ #timeToFirstByte = 0;
20
+ #firstByteToWindowLoad = 0; // our "frontend" duration
21
+ #firstByteToDomContent = 0; // our "dom processing" duration
22
+ #obfuscator;
23
+ constructor(agentRef) {
24
+ super(agentRef, CONSTANTS.FEATURE_NAME);
25
+ this.#obfuscator = new Obfuscator(agentRef, EVENT_TYPES.PVE);
26
+ if (isBrowserScope) {
27
+ timeToFirstByte.subscribe(({
28
+ value,
29
+ attrs
30
+ }) => {
31
+ const navEntry = attrs.navigationEntry;
32
+ this.#timeToFirstByte = Math.max(value, this.#timeToFirstByte);
33
+ this.#firstByteToWindowLoad = Math.max(Math.round(navEntry.loadEventEnd - this.#timeToFirstByte), this.#firstByteToWindowLoad); // our "frontend" duration
34
+ this.#firstByteToDomContent = Math.max(Math.round(navEntry.domContentLoadedEventEnd - this.#timeToFirstByte), this.#firstByteToDomContent); // our "dom processing" duration
35
+ });
36
+ }
37
+ this.waitForFlags([]).then(() => {
38
+ const body = this.#obfuscator.traverseAndObfuscateEvents({
39
+ ja: {
40
+ ...agentRef.info.jsAttributes,
41
+ webdriverDetected
42
+ }
43
+ });
44
+ this.events.add(body);
45
+ this.drain();
46
+ });
47
+ }
48
+ queryStringsBuilder() {
49
+ const info = this.agentRef.info;
50
+ const measures = {};
51
+ if (info.queueTime) measures.qt = info.queueTime;
52
+ if (info.applicationTime) measures.ap = info.applicationTime;
53
+
54
+ // 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.
55
+ // Following PR #428, which demands that the BA must drive entity indexing, these need to be sent even outside of the main window context where PerformanceTiming
56
+ // 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.
57
+ measures.be = this.#timeToFirstByte;
58
+ measures.fe = this.#firstByteToWindowLoad;
59
+ measures.dc = this.#firstByteToDomContent;
60
+ const queryParameters = {
61
+ at: info.atts,
62
+ af: getActivatedFeaturesFlags(this.agentRef).join(','),
63
+ igp: this.agentRef.runtime.appMetadata.igp,
64
+ ...measures,
65
+ fp: firstPaint.current.value,
66
+ fcp: firstContentfulPaint.current.value
67
+ };
68
+ if (globalScope.performance) {
69
+ const navTimingEntry = getNavigationEntry();
70
+ if (navTimingEntry) {
71
+ // Navigation Timing level 2 API that replaced PerformanceTiming & PerformanceNavigation
72
+ const perf = {
73
+ timing: addPT(originTime, navTimingEntry, {}),
74
+ navigation: addPN(navTimingEntry, {})
75
+ };
76
+ queryParameters.perf = stringify(perf);
77
+ } else if (typeof PerformanceTiming !== 'undefined') {
78
+ // Modern Safari iFrames and Safari pre-15 do not support level 2 timing.
79
+ const perf = {
80
+ timing: addPT(originTime, globalScope.performance.timing, {}, true),
81
+ navigation: addPN(globalScope.performance.navigation, {})
82
+ };
83
+ queryParameters.perf = stringify(perf);
84
+ }
85
+ }
86
+ const {
87
+ correctedOriginTime
88
+ } = this.agentRef.runtime.timeKeeper;
89
+ if (correctedOriginTime) queryParameters.timestamp = correctedOriginTime; // a "PageView" is set to represent the page's (server adjusted) origin time rather than when event is recorded/harvested
90
+
91
+ return queryParameters;
92
+ }
93
+ get harvestEndpointVersion() {
94
+ return 2;
95
+ }
96
+ serializer(eventBuffer) {
97
+ // this is necessary because PVE sends a single item rather than an array; in the case of undefined, this prevents sending [null] as body
98
+ return eventBuffer[0];
99
+ }
100
+ }
@@ -18,7 +18,12 @@ export class Instrument extends InstrumentBase {
18
18
 
19
19
  /** feature specific APIs */
20
20
  setupSetPageViewNameAPI(agentRef);
21
- this.importAggregator(agentRef, () => import(/* webpackChunkName: "page_view_event-aggregate" */'../aggregate'));
21
+ this.importAggregator(agentRef, () => {
22
+ if (agentRef.init.feature_flags.includes('rum_v2')) {
23
+ return import(/* webpackChunkName: "page_view_event-aggregate" */'../aggregate_v2');
24
+ }
25
+ return import(/* webpackChunkName: "page_view_event-aggregate" */'../aggregate');
26
+ });
22
27
  }
23
28
  setupInspectionEvents() {
24
29
  const dispatch = (evt, name) => {
@@ -66,7 +66,11 @@ export class Aggregate extends AggregateBase {
66
66
  } = cumulativeLayoutShift.current;
67
67
  if (value === undefined) return;
68
68
  this.addTiming(name, value * 1000, attrs);
69
- }, true, true); // CLS node should only reports on vis change rather than on every change
69
+ }, true, true); // CLS node should only report on vis change rather than on every change.
70
+ /* NOTE: the capture=true is required -- empirically verified against a real browser (Chrome) for CLS
71
+ timing node to reliably be in the same final harvest as the rest, alongside Harvester#startTimer's
72
+ queueMicrotask deferral of the EOL harvest itself. Dropping this flag caused CLS to be split into its own,
73
+ separate, later harvest instead of going out together with pageHide/INP. */
70
74
 
71
75
  this.drain();
72
76
  });
@@ -40,6 +40,10 @@ export class Instrument extends InstrumentBase {
40
40
  recorder.startRecording(TRIGGERS.PRELOAD, session?.sessionReplayMode);
41
41
  }); // could handle specific fail-state behaviors with a .catch block here
42
42
  }
43
+
44
+ // If the aggregate never successfully loads (missing session prerequisite, or the aggregate module itself
45
+ // fails to import/construct), any preload recording that already started needs to be stopped.
46
+ this.abortHandler = this.#abort;
43
47
  this.importAggregator(this.agentRef, () => import(/* webpackChunkName: "session_replay-aggregate" */'../aggregate'), this);
44
48
 
45
49
  /** If the recorder is running, we can pass error events on to the agg to help it switch to full mode later */
@@ -104,5 +108,10 @@ export class Instrument extends InstrumentBase {
104
108
  }); // could handle specific fail-state behaviors with a .catch block here
105
109
  }
106
110
  }
111
+
112
+ /** Stops any preload recording that already started if the aggregate never ends up successfully loading. */
113
+ #abort() {
114
+ this.recorder?.stopRecording();
115
+ }
107
116
  }
108
117
  export const SessionReplay = Instrument;
@@ -209,7 +209,8 @@ export class Recorder {
209
209
 
210
210
  // We are making an effort to try to keep payloads manageable for unloading. If they reach the unload limit before their interval,
211
211
  // it will send immediately. This often happens on the first snapshot, which can be significantly larger than the other payloads.
212
- if ((this.events.hasSnapshot && this.events.hasMeta || payloadSize > IDEAL_PAYLOAD_SIZE) && !this.isErrorMode) {
212
+ // (the aggregate may not exist yet/at all if its own bootstrap hasn't finished or failed -- nothing to harvest for in that case.)
213
+ if ((this.events.hasSnapshot && this.events.hasMeta || payloadSize > IDEAL_PAYLOAD_SIZE) && !this.isErrorMode && this.srInstrument.featAggregate) {
213
214
  // if we've made it to the ideal size of ~16kb before the interval timer, we should send early.
214
215
  this.agentRef.runtime.harvester.triggerHarvestFor(this.srInstrument.featAggregate);
215
216
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { gosNREUMOriginals } from '../../../common/window/nreum';
@@ -16,10 +16,8 @@ export function isPreloadAllowed(agentInit) {
16
16
  }
17
17
  export function customMasker(text, element) {
18
18
  try {
19
- if (typeof element?.type === 'string') {
20
- if (element.type.toLowerCase() === 'password') return '*'.repeat(text?.length || 0);
21
- if (element?.dataset?.nrUnmask !== undefined || element?.classList?.contains('nr-unmask')) return text;
22
- }
19
+ if (typeof element?.type === 'string' && element.type.toLowerCase() === 'password') return '*'.repeat(text?.length || 0);
20
+ if (element?.dataset?.nrUnmask !== undefined || element?.classList?.contains('nr-unmask')) return text;
23
21
  } catch (err) {
24
22
  // likely an element was passed to this handler that was invalid and was missing attributes or methods
25
23
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { handle } from '../../../common/event-emitter/handle';
@@ -36,8 +36,8 @@ export class Instrument extends InstrumentBase {
36
36
  return;
37
37
  }
38
38
  const thisInstrumentEE = this.ee;
39
- wrapHistory(thisInstrumentEE);
40
- this.eventsEE = wrapEvents(thisInstrumentEE);
39
+ wrapHistory(thisInstrumentEE, agentRef);
40
+ this.eventsEE = wrapEvents(thisInstrumentEE, agentRef);
41
41
  this.eventsEE.on(FN_START, function (args, target) {
42
42
  this.bstStart = now();
43
43
  });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { gosNREUMOriginals } from '../../../common/window/nreum';
@@ -29,7 +29,7 @@ export class Instrument extends InstrumentBase {
29
29
  setupInteractionAPI(agentRef);
30
30
  if (!isBrowserScope || !gosNREUMOriginals().o.MO) return; // soft navigations is not supported outside web env or browsers without the mutation observer API
31
31
 
32
- const historyEE = wrapHistory(this.ee);
32
+ const historyEE = wrapHistory(this.ee, agentRef);
33
33
  try {
34
34
  this.removeOnAbort = new AbortController();
35
35
  } catch (e) {}
@@ -5,7 +5,6 @@
5
5
  import { FeatureBase } from './feature-base';
6
6
  import { drain } from '../../common/drain/drain';
7
7
  import { FEATURE_NAMES } from '../../loaders/features/features';
8
- import { Harvester } from '../../common/harvest/harvester';
9
8
  import { EventBuffer } from './event-buffer';
10
9
  import { handle } from '../../common/event-emitter/handle';
11
10
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../metrics/constants';
@@ -20,7 +19,6 @@ export class AggregateBase extends FeatureBase {
20
19
  */
21
20
  constructor(agentRef, featureName) {
22
21
  super(agentRef, featureName);
23
- this.doOnceForAllAggregate(agentRef);
24
22
 
25
23
  /** @type {Boolean} indicates if custom attributes are combined in each event payload for size estimation purposes. this is set to true in derived classes that need to evaluate custom attributes separately from the event payload */
26
24
  this.customAttributesAreSeparate = false;
@@ -172,16 +170,6 @@ export class AggregateBase extends FeatureBase {
172
170
  this.events.clearSave(this.harvestOpts);
173
171
  }
174
172
 
175
- /**
176
- * These are actions related to shared resources that should be initialized once by whichever feature Aggregate subclass loads first.
177
- * This method should run after checkConfiguration, which may reset the agent's info/runtime object that is used here.
178
- */
179
- doOnceForAllAggregate(agentRef) {
180
- // Note: obfuscator is now created per-feature for their specific event types
181
-
182
- if (!agentRef.runtime.harvester) agentRef.runtime.harvester = new Harvester(agentRef);
183
- }
184
-
185
173
  /**
186
174
  * Report a supportability metric
187
175
  * @param {*} metricName The tag of the name matching the Angler aggregation tag