@newrelic/browser-agent 1.312.1-rc.11 → 1.312.1-rc.13

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.
@@ -17,8 +17,9 @@ import { AggregateBase } from '../../utils/aggregate-base';
17
17
  import { now } from '../../../common/timing/now';
18
18
  import { applyFnToProps } from '../../../common/util/traverse';
19
19
  import { evaluateInternalError } from './internal-errors';
20
- import { getVersion2Attributes } from '../../../common/v2/utils';
20
+ import { getRegisteredTargetsFromFilename, getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate } from '../../../common/v2/utils';
21
21
  import { buildCauseString } from './cause-string';
22
+ import { ShortCircuit } from '../../../common/util/short-circuit';
22
23
 
23
24
  /**
24
25
  * @typedef {import('./compute-stack-trace.js').StackInfo} StackInfo
@@ -35,8 +36,8 @@ export class Aggregate extends AggregateBase {
35
36
  this.observedAt = {};
36
37
  this.pageviewReported = {};
37
38
  this.errorOnPage = false;
38
- register('err', (...args) => this.storeError(...args), this.featureName, this.ee);
39
- register('ierr', (...args) => this.storeError(...args), this.featureName, this.ee);
39
+ register('err', this.processError.bind(this), this.featureName, this.ee);
40
+ register('ierr', this.processError.bind(this), this.featureName, this.ee);
40
41
  register('returnJserror', (jsErrorEvent, softNavAttrs) => this.#storeJserrorForHarvest(jsErrorEvent, softNavAttrs), this.featureName, this.ee);
41
42
 
42
43
  // 0 == off, 1 == on
@@ -68,60 +69,162 @@ export class Aggregate extends AggregateBase {
68
69
  }
69
70
 
70
71
  /**
71
- * Builds a standardized stack trace string from the frames in the given `stackInfo` object, with each frame separated
72
- * by a newline character. Lines take the form `<functionName>@<url>:<lineNumber>`.
72
+ * Main entry point for processing JavaScript errors. This method orchestrates the complete error processing pipeline.
73
73
  *
74
- * @param {StackInfo} stackInfo - An object specifying a stack string and individual frames.
75
- * @returns {string} A canonical stack string built from the URLs and function names in the given `stackInfo` object.
74
+ * Processing Flow:
75
+ * 1. Filter the error through the customer's onerror handler (if configured and not internal)
76
+ * 2. Compute the stack trace from the error object
77
+ * 3. Evaluate if the error should be swallowed (internal errors, known issues, etc.)
78
+ * 4. Derive target(s) for the error (MFE detection for v2 endpoints, or default target) - Note: "undefined" indicates the default target will be used
79
+ * 5. Store the error for each derived target. During storage (#storeJserrorForHarvest), duplication for MFE <-> container will be handled
80
+ *
81
+ * Important: "ShortCircuit" Pattern:
82
+ * Several steps in the pipeline can throw a ShortCircuit error to halt processing without
83
+ * treating it as a reportable error. This pattern is used when:
84
+ * - The customer's onerror handler returns a truthy value (excluding fingerprinting objects)
85
+ * - The error is identified as an internal error that shouldn't be reported
86
+ *
87
+ * When a ShortCircuit is thrown, processing stops immediately and the error is not stored.
88
+ * Any other thrown error is re-thrown as it represents an actual problem in the agent code.
89
+ *
90
+ * @param {Error|UncaughtError} err - The error instance to be processed
91
+ * @param {number} [time] - The relative ms (to origin) timestamp of occurrence. Defaults to now()
92
+ * @param {boolean} [internal=false] - If the error was "caught" and deemed "internal" before reporting to the jserrors feature
93
+ * @param {object} [customAttributes] - Any custom attributes to be included in the error payload
94
+ * @param {boolean} [hasReplay=false] - A flag indicating if the error occurred during a replay session
95
+ * @param {string} [swallowReason] - A string indicating pre-defined reason if swallowing the error. Mainly used by internal error supportability metrics
96
+ * @param {object} [target] - The target to buffer and harvest to. If undefined, the default configuration target is used
97
+ * @returns {void}
76
98
  */
77
- buildCanonicalStackString(stackInfo) {
78
- var canonicalStackString = '';
79
- for (var i = 0; i < stackInfo.frames.length; i++) {
80
- var frame = stackInfo.frames[i];
81
- var func = canonicalFunctionName(frame.func);
82
- if (canonicalStackString) canonicalStackString += '\n';
83
- if (func) canonicalStackString += func + '@';
84
- if (typeof frame.url === 'string') canonicalStackString += frame.url;
85
- if (frame.line) canonicalStackString += ':' + frame.line;
99
+ processError(err, time, internal, customAttributes, hasReplay, swallowReason, target) {
100
+ if (!err) return;
101
+ time = time || now();
102
+ try {
103
+ const filterOutput = this.#filterError(err, internal);
104
+ const stackInfo = computeStackTrace(err);
105
+ this.#swallowError(stackInfo, internal, swallowReason);
106
+ this.#deriveTargets(stackInfo, target).forEach(target => {
107
+ this.#storeError(err, time, stackInfo, filterOutput, customAttributes, hasReplay, target);
108
+ });
109
+ } catch (e) {
110
+ if (!(e instanceof ShortCircuit)) {
111
+ throw e;
112
+ }
86
113
  }
87
- return canonicalStackString;
88
114
  }
89
115
 
90
116
  /**
117
+ * Filters an error through the customer's configured onerror handler.
91
118
  *
92
- * @param {Error|UncaughtError} err The error instance to be processed
93
- * @param {number} time the relative ms (to origin) timestamp of occurrence
94
- * @param {boolean=} internal if the error was "caught" and deemed "internal" before reporting to the jserrors feature
95
- * @param {object=} customAttributes any custom attributes to be included in the error payload
96
- * @param {boolean=} hasReplay a flag indicating if the error occurred during a replay session
97
- * @param {string=} swallowReason a string indicating pre-defined reason if swallowing the error. Mainly used by the internal error SMs.
98
- * @param {object=} target the target to buffer and harvest to, if undefined the default configuration target is used
99
- * @returns
119
+ * If the customer has configured a custom onerror handler and the error is not internal,
120
+ * this method invokes that handler. The handler's return value determines whether the error
121
+ * should be reported:
122
+ * - Falsey values (false, null, undefined, etc.) Report the error normally
123
+ * - Truthy non-object values Don't report (throws ShortCircuit)
124
+ * - Object with 'group' property (non-empty string) Report with fingerprinting label
125
+ * - Any other truthy value Don't report (throws ShortCircuit)
126
+ *
127
+ * @param {Error|UncaughtError} err - The error to filter
128
+ * @param {boolean} internal - Whether this is an internal error (internal errors skip filtering)
129
+ * @returns {undefined|object} The filter output. If an object with 'group' property, contains fingerprinting data
130
+ * @throws {ShortCircuit} When the error should not be reported based on the filter output
100
131
  */
101
- storeError(err, time, internal, customAttributes, hasReplay, swallowReason, target) {
102
- if (!err) return;
103
- // are we in an interaction
104
- time = time || now();
132
+ #filterError(err, internal) {
105
133
  let filterOutput;
106
134
  if (!internal && this.agentRef.runtime.onerror) {
107
135
  filterOutput = this.agentRef.runtime.onerror(err);
108
136
  if (filterOutput && !(typeof filterOutput.group === 'string' && filterOutput.group.length)) {
109
137
  // All truthy values mean don't report (store) the error, per backwards-compatible usage,
110
138
  // - EXCEPT if a fingerprinting label is returned, via an object with key of 'group' and value of non-empty string
111
- return;
139
+ throw new ShortCircuit();
112
140
  }
113
141
  // Again as with previous usage, all falsey values would include the error.
114
142
  }
115
- var stackInfo = computeStackTrace(err);
143
+ return filterOutput;
144
+ }
145
+
146
+ /**
147
+ * Evaluates whether an error should be swallowed (not reported) based on internal error criteria.
148
+ *
149
+ * This method uses the evaluateInternalError function to determine if the error matches known
150
+ * internal error patterns (e.g., errors from the agent itself, known browser issues, etc.).
151
+ * If the error should be swallowed, a supportability metric is recorded and processing is halted.
152
+ *
153
+ * @param {StackInfo} stackInfo - The computed stack trace information
154
+ * @param {boolean} internal - Whether the error was marked as internal
155
+ * @param {string} [swallowReason] - Optional pre-determined reason for swallowing
156
+ * @returns {void}
157
+ * @throws {ShortCircuit} When the error should be swallowed and not reported
158
+ */
159
+ #swallowError(stackInfo, internal, swallowReason) {
116
160
  const {
117
161
  shouldSwallow,
118
162
  reason
119
163
  } = evaluateInternalError(stackInfo, internal, swallowReason);
120
164
  if (shouldSwallow) {
121
165
  this.reportSupportabilityMetric('Internal/Error/' + reason);
122
- return;
166
+ throw new ShortCircuit();
123
167
  }
124
- var canonicalStackString = this.buildCanonicalStackString(stackInfo);
168
+ }
169
+
170
+ /**
171
+ * Derives the appropriate targets for reporting the given stack information.
172
+ *
173
+ * Targets represent the entities that should receive the error data. This is particularly
174
+ * important for Micro Frontend (MFE) scenarios where errors may need to be reported to
175
+ * different applications.
176
+ *
177
+ * Logic:
178
+ * - If a target is explicitly provided (e.g., from the register API), use it
179
+ * - For v2 endpoints without an explicit target, scan stack frames to detect MFE sources
180
+ * - If no MFE is detected or v2 is not enabled, use undefined (default target)
181
+ *
182
+ * @param {StackInfo} stackInfo - The computed stack trace information containing frames
183
+ * @param {object} [target] - Explicitly provided target, typically from the register API
184
+ * @returns {Array<object|undefined>} Array of targets to report the error to. Always contains at least one element.
185
+ */
186
+ #deriveTargets(stackInfo, target) {
187
+ const targets = [];
188
+ if (target) {
189
+ // reported by the register API directly
190
+ targets.push(target);
191
+ } else {
192
+ // we dont know if this is MFE yet, we need to figure it out.
193
+ if (this.harvestEndpointVersion === 2) {
194
+ for (const frame of stackInfo.frames) {
195
+ targets.push(...getRegisteredTargetsFromFilename(frame.url, this.agentRef));
196
+ if (targets.length) break;
197
+ }
198
+ }
199
+ if (!targets.length) targets.push(undefined);
200
+ }
201
+ return targets;
202
+ }
203
+
204
+ /**
205
+ * Stores error data for eventual harvesting and transmission to the backend.
206
+ *
207
+ * This method processes the error through several stages:
208
+ * 1. Build canonical stack string for cross-browser error grouping
209
+ * 2. Build cause chain string if the error has a cause property
210
+ * 3. Create params object with error metadata (stack hash, class, message, etc.)
211
+ * 4. Create bucket hash for internal deduplication
212
+ * 5. Store stack trace on first occurrence of this error
213
+ * 6. Add custom attributes and send to other features (trace, replay)
214
+ * 7. Route through soft nav if enabled, or directly to harvest storage
215
+ * 8. Handle MFE duplication for v2 endpoints if needed
216
+ *
217
+ * @param {Error|UncaughtError} err - The error instance to be processed
218
+ * @param {number} time - The relative ms (to origin) timestamp of occurrence
219
+ * @param {StackInfo} stackInfo - The computed stack trace information
220
+ * @param {object} [filterOutput] - Output from the customer's onerror handler, may contain fingerprinting group
221
+ * @param {object} [customAttributes] - Any custom attributes to be included in the error payload
222
+ * @param {boolean} [hasReplay=false] - A flag indicating if the error occurred during a replay session
223
+ * @param {object} [target] - The target to buffer and harvest to. If undefined, the default configuration target is used
224
+ * @returns {void}
225
+ */
226
+ #storeError(err, time, stackInfo, filterOutput, customAttributes, hasReplay, target) {
227
+ var canonicalStackString = this.#buildCanonicalStackString(stackInfo);
125
228
  const causeStackString = buildCauseString(err);
126
229
  const params = {
127
230
  stackHash: stringHashCode(canonicalStackString),
@@ -144,7 +247,7 @@ export class Aggregate extends AggregateBase {
144
247
  * the canonical stack trace excludes items like the column number increasing the hit-rate of different errors potentially
145
248
  * bucketing and ultimately resulting in the loss of data in NR1.
146
249
  */
147
- var bucketHash = stringHashCode("".concat(stackInfo.name, "_").concat(stackInfo.message, "_").concat(stackInfo.stackString, "_").concat(params.hasReplay ? 1 : 0, "_").concat(target?.id || 'container'));
250
+ var bucketHash = stringHashCode("".concat(stackInfo.name, "_").concat(stackInfo.message, "_").concat(stackInfo.stackString, "_").concat(params.hasReplay ? 1 : 0, "_").concat(target?.id || 'container', "_").concat(target?.instance || ''));
148
251
  if (!this.stackReported[bucketHash]) {
149
252
  this.stackReported[bucketHash] = true;
150
253
  params.stack_trace = truncateSize(stackInfo.stackString);
@@ -184,27 +287,90 @@ export class Aggregate extends AggregateBase {
184
287
  // pass the error to soft nav for evaluation - it will return it via 'returnJserror' when interaction is resolved
185
288
  handle('jserror', [jsErrorEvent], undefined, FEATURE_NAMES.softNav, this.ee);
186
289
  } else {
187
- this.#storeJserrorForHarvest(jsErrorEvent, false);
290
+ this.#storeJserrorForHarvest(jsErrorEvent);
188
291
  }
189
292
  }
190
293
 
191
294
  // always add directly if scoped to a sub-entity, the other pathways above will be deterministic if the main agent should procede
192
- if (target) this.#storeJserrorForHarvest([...jsErrorEvent, target], false, params._softNavAttributes);
295
+ if (target) this.#storeJserrorForHarvest(jsErrorEvent, {}, target);
296
+ }
297
+
298
+ /**
299
+ * Builds a standardized (canonical) stack trace string from the frames in the given `stackInfo` object.
300
+ *
301
+ * The canonical format is used for cross-browser error grouping in NR1, as different browsers
302
+ * format stack traces differently. Each frame is separated by a newline character and takes
303
+ * the form: `<functionName>@<url>:<lineNumber>`
304
+ *
305
+ * Note: Column numbers are intentionally excluded from the canonical format to improve
306
+ * grouping accuracy, as the same error across different minified builds might have different
307
+ * column numbers but should still be grouped together.
308
+ *
309
+ * Example output:
310
+ * ```
311
+ * handleClick@https://example.com/app.js:42
312
+ * EventEmitter.emit@https://example.com/vendor.js:1337
313
+ * ```
314
+ *
315
+ * @param {StackInfo} stackInfo - An object containing parsed stack frames from computeStackTrace
316
+ * @returns {string} A canonical stack string built from the URLs and function names in the given `stackInfo` object
317
+ */
318
+ #buildCanonicalStackString(stackInfo) {
319
+ var canonicalStackString = '';
320
+ for (var i = 0; i < stackInfo.frames.length; i++) {
321
+ var frame = stackInfo.frames[i];
322
+ var func = canonicalFunctionName(frame.func);
323
+ if (canonicalStackString) canonicalStackString += '\n';
324
+ if (func) canonicalStackString += func + '@';
325
+ if (typeof frame.url === 'string') canonicalStackString += frame.url;
326
+ if (frame.line) canonicalStackString += ':' + frame.line;
327
+ }
328
+ return canonicalStackString;
193
329
  }
194
- #storeJserrorForHarvest(errorInfoArr, softNavCustomAttrs = {}) {
195
- let [type, bucketHash, params, newMetrics, localAttrs, target] = errorInfoArr;
330
+
331
+ /**
332
+ * Adds a processed error to the harvest buffer with all custom attributes merged.
333
+ *
334
+ * This is the final step before an error is stored to be sent to the backend. It handles:
335
+ * - Merging all custom attributes (global, soft nav, MFE, and local)
336
+ * - Creating a unique aggregate hash for deduplication
337
+ * - Adding the error to the events buffer for harvest
338
+ * - Duplicating the error for MFE scenarios when needed (v2 endpoints)
339
+ *
340
+ * Custom Attribute Precedence (lowest to highest):
341
+ * 1. Global jsAttributes from agent config
342
+ * 2. Soft navigation attributes (if from a soft nav interaction)
343
+ * 3. MFE v2 attributes (source/parent metadata)
344
+ * 4. Local custom attributes passed with the specific error
345
+ *
346
+ * @param {Array} errorInfoArr - Array containing [type, bucketHash, params, metrics, customAttributes, target]
347
+ * @param {object} [attrs={}] - Additional attributes to merge (e.g., from soft nav interactions)
348
+ * @returns {void}
349
+ */
350
+ #storeJserrorForHarvest(errorInfoArr, attrs = {}, target) {
351
+ let [type, bucketHash, params, newMetrics, localAttrs] = errorInfoArr;
196
352
  const allCustomAttrs = {
197
353
  /** MFE specific attributes if in "multiple" mode (ie consumer version 2) */
198
354
  ...getVersion2Attributes(target, this)
199
355
  };
200
356
  Object.entries(this.agentRef.info.jsAttributes).forEach(([k, v]) => setCustom(k, v));
201
- Object.entries(softNavCustomAttrs).forEach(([k, v]) => setCustom(k, v)); // when an ixn finishes, it'll pass attrs specific to the ixn; if no associated ixn, this defaults to empty
357
+ Object.entries(attrs).forEach(([k, v]) => setCustom(k, v)); // when an ixn finishes, it'll pass attrs specific to the ixn; if no associated ixn, this defaults to empty
202
358
  if (params.browserInteractionId) bucketHash += params.browserInteractionId;
203
359
  if (localAttrs) Object.entries(localAttrs).forEach(([k, v]) => setCustom(k, v)); // local custom attrs are applied in either case with the highest precedence
204
360
 
205
361
  const jsAttributesHash = stringHashCode(stringify(allCustomAttrs));
206
362
  const aggregateHash = bucketHash + ':' + jsAttributesHash;
207
363
  this.events.add([type, aggregateHash, params, newMetrics, allCustomAttrs]);
364
+ if (shouldDuplicate(target, this)) {
365
+ // Clone the array with new object references to prevent deduplication in the shared aggregator
366
+ this.#storeJserrorForHarvest([type, bucketHash, {
367
+ ...params
368
+ }, {
369
+ ...newMetrics
370
+ }, localAttrs && {
371
+ ...localAttrs
372
+ }], getVersion2DuplicationAttributes(target, this));
373
+ }
208
374
  function setCustom(key, val) {
209
375
  allCustomAttrs[key] = val && typeof val === 'object' ? stringify(val) : val;
210
376
  }
@@ -26,6 +26,17 @@ import { generateRandomHexString } from '../../common/ids/unique-id';
26
26
 
27
27
  const PROTECTED_KEYS = ['name', 'id', 'type'];
28
28
 
29
+ /**
30
+ * Warning functions that only fire once - can be reset in tests
31
+ * @private
32
+ */
33
+ export const warnings = {
34
+ experimental: single(() => warn(54, 'newrelic.register')),
35
+ disabled: single(() => warn(55)),
36
+ invalidTarget: single(target => warn(48, target)),
37
+ deregistered: single(() => warn(68))
38
+ };
39
+
29
40
  /**
30
41
  * @experimental
31
42
  * IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
@@ -45,7 +56,7 @@ export function setupRegisterAPI(agent) {
45
56
  * @returns {RegisterAPI} the api object to be returned from the register api method
46
57
  */
47
58
  function register(agentRef, target) {
48
- warn(54, 'newrelic.register');
59
+ warnings.experimental();
49
60
  target ||= {};
50
61
  target.instance = generateRandomHexString(8);
51
62
  target.type = V2_TYPES.MFE;
@@ -103,8 +114,8 @@ function register(agentRef, target) {
103
114
  }
104
115
 
105
116
  /** primary cases that can block the register API from working at init time */
106
- if (!agentRef.init.api.register.enabled) block(single(() => warn(55)));
107
- if (!hasValidValue(target.id) || !hasValidValue(target.name)) block(single(() => warn(48, target)));
117
+ if (!agentRef.init.api.register.enabled) block(warnings.disabled);
118
+ if (!hasValidValue(target.id) || !hasValidValue(target.name)) block(() => warnings.invalidTarget(target));
108
119
 
109
120
  /** @type {RegisterAPI} */
110
121
  const api = {
@@ -115,7 +126,7 @@ function register(agentRef, target) {
115
126
  deregister: () => {
116
127
  /** note: blocking this instance will disable access for all entities sharing the instance, and will invalidate it from the v2 checks */
117
128
  reportTimings();
118
- block(single(() => warn(68)));
129
+ block(warnings.deregistered);
119
130
  },
120
131
  log: (message, options = {}) => report(log, [message, {
121
132
  ...options,
@@ -1 +1 @@
1
- {"root":["../src/index.js","../src/cdn/experimental.js","../src/cdn/lite.js","../src/cdn/pro.js","../src/cdn/spa.js","../src/common/aggregate/aggregator.js","../src/common/aggregate/event-aggregator.js","../src/common/config/configurable.js","../src/common/config/info.js","../src/common/config/init-types.js","../src/common/config/init.js","../src/common/config/loader-config.js","../src/common/config/runtime.js","../src/common/constants/agent-constants.js","../src/common/constants/env.cdn.js","../src/common/constants/env.js","../src/common/constants/env.npm.js","../src/common/constants/runtime.js","../src/common/constants/shared-channel.js","../src/common/deny-list/deny-list.js","../src/common/dispatch/global-event.js","../src/common/dom/iframe.js","../src/common/dom/query-selector.js","../src/common/dom/selector-path.js","../src/common/drain/drain.js","../src/common/event-emitter/contextual-ee.js","../src/common/event-emitter/event-context.js","../src/common/event-emitter/handle.js","../src/common/event-emitter/register-handler.js","../src/common/event-listener/event-listener-opts.js","../src/common/harvest/harvester.js","../src/common/harvest/types.js","../src/common/ids/bundle-id.js","../src/common/ids/id.js","../src/common/ids/unique-id.js","../src/common/serialize/bel-serializer.js","../src/common/session/constants.js","../src/common/session/session-entity.js","../src/common/storage/local-storage.js","../src/common/timer/interaction-timer.js","../src/common/timer/timer.js","../src/common/timing/nav-timing.js","../src/common/timing/now.js","../src/common/timing/time-keeper.js","../src/common/unload/eol.js","../src/common/url/canonicalize-url.js","../src/common/url/clean-url.js","../src/common/url/encode.js","../src/common/url/extract-url.js","../src/common/url/location.js","../src/common/url/parse-url.js","../src/common/url/protocol.js","../src/common/util/attribute-size.js","../src/common/util/browser-stack-matchers.js","../src/common/util/console.js","../src/common/util/data-size.js","../src/common/util/event-origin.js","../src/common/util/feature-flags.js","../src/common/util/get-or-set.js","../src/common/util/invoke.js","../src/common/util/monkey-patched.js","../src/common/util/obfuscate.js","../src/common/util/stringify.js","../src/common/util/submit-data.js","../src/common/util/text.js","../src/common/util/traverse.js","../src/common/util/type-check.js","../src/common/util/webdriver-detection.js","../src/common/v2/script-correlation.js","../src/common/v2/script-tracker.js","../src/common/v2/utils.js","../src/common/vitals/constants.js","../src/common/vitals/cumulative-layout-shift.js","../src/common/vitals/first-contentful-paint.js","../src/common/vitals/first-paint.js","../src/common/vitals/interaction-to-next-paint.js","../src/common/vitals/largest-contentful-paint.js","../src/common/vitals/load-time.js","../src/common/vitals/time-to-first-byte.js","../src/common/vitals/vital-metric.js","../src/common/window/load.js","../src/common/window/nreum.js","../src/common/window/page-visibility.js","../src/common/wrap/wrap-events.js","../src/common/wrap/wrap-fetch.js","../src/common/wrap/wrap-function.js","../src/common/wrap/wrap-history.js","../src/common/wrap/wrap-logger.js","../src/common/wrap/wrap-websocket.js","../src/common/wrap/wrap-xhr.js","../src/features/ajax/constants.js","../src/features/ajax/index.js","../src/features/ajax/aggregate/gql.js","../src/features/ajax/aggregate/index.js","../src/features/ajax/instrument/distributed-tracing.js","../src/features/ajax/instrument/index.js","../src/features/ajax/instrument/response-size.js","../src/features/generic_events/constants.js","../src/features/generic_events/index.js","../src/features/generic_events/aggregate/index.js","../src/features/generic_events/aggregate/user-actions/aggregated-user-action.js","../src/features/generic_events/aggregate/user-actions/user-actions-aggregator.js","../src/features/generic_events/instrument/index.js","../src/features/jserrors/constants.js","../src/features/jserrors/index.js","../src/features/jserrors/aggregate/canonical-function-name.js","../src/features/jserrors/aggregate/cause-string.js","../src/features/jserrors/aggregate/compute-stack-trace.js","../src/features/jserrors/aggregate/format-stack-trace.js","../src/features/jserrors/aggregate/index.js","../src/features/jserrors/aggregate/internal-errors.js","../src/features/jserrors/aggregate/string-hash-code.js","../src/features/jserrors/instrument/index.js","../src/features/jserrors/shared/cast-error.js","../src/features/jserrors/shared/uncaught-error.js","../src/features/logging/constants.js","../src/features/logging/index.js","../src/features/logging/aggregate/index.js","../src/features/logging/instrument/index.js","../src/features/logging/shared/log.js","../src/features/logging/shared/utils.js","../src/features/metrics/constants.js","../src/features/metrics/index.js","../src/features/metrics/aggregate/framework-detection.js","../src/features/metrics/aggregate/harvest-metadata.js","../src/features/metrics/aggregate/index.js","../src/features/metrics/instrument/index.js","../src/features/page_action/constants.js","../src/features/page_action/index.js","../src/features/page_action/instrument/index.js","../src/features/page_view_event/constants.js","../src/features/page_view_event/index.js","../src/features/page_view_event/aggregate/index.js","../src/features/page_view_event/aggregate/initialized-features.js","../src/features/page_view_event/instrument/index.js","../src/features/page_view_timing/constants.js","../src/features/page_view_timing/index.js","../src/features/page_view_timing/aggregate/index.js","../src/features/page_view_timing/instrument/index.js","../src/features/session_replay/constants.js","../src/features/session_replay/index.js","../src/features/session_replay/aggregate/index.js","../src/features/session_replay/instrument/index.js","../src/features/session_replay/shared/recorder-events.js","../src/features/session_replay/shared/recorder.js","../src/features/session_replay/shared/stylesheet-evaluator.js","../src/features/session_replay/shared/utils.js","../src/features/session_trace/constants.js","../src/features/session_trace/index.js","../src/features/session_trace/aggregate/index.js","../src/features/session_trace/aggregate/trace/node.js","../src/features/session_trace/aggregate/trace/storage.js","../src/features/session_trace/aggregate/trace/utils.js","../src/features/session_trace/instrument/index.js","../src/features/soft_navigations/constants.js","../src/features/soft_navigations/index.js","../src/features/soft_navigations/aggregate/ajax-node.js","../src/features/soft_navigations/aggregate/bel-node.js","../src/features/soft_navigations/aggregate/index.js","../src/features/soft_navigations/aggregate/initial-page-load-interaction.js","../src/features/soft_navigations/aggregate/interaction.js","../src/features/soft_navigations/instrument/index.js","../src/features/utils/agent-session.js","../src/features/utils/aggregate-base.js","../src/features/utils/event-buffer.js","../src/features/utils/feature-base.js","../src/features/utils/feature-gates.js","../src/features/utils/instrument-base.js","../src/interfaces/registered-entity.js","../src/loaders/agent-base.js","../src/loaders/agent.js","../src/loaders/api-base.js","../src/loaders/browser-agent.js","../src/loaders/micro-agent-base.js","../src/loaders/micro-agent.js","../src/loaders/api/addPageAction.js","../src/loaders/api/addRelease.js","../src/loaders/api/addToTrace.js","../src/loaders/api/consent.js","../src/loaders/api/constants.js","../src/loaders/api/finished.js","../src/loaders/api/interaction-types.js","../src/loaders/api/interaction.js","../src/loaders/api/log.js","../src/loaders/api/measure.js","../src/loaders/api/noticeError.js","../src/loaders/api/pauseReplay.js","../src/loaders/api/recordCustomEvent.js","../src/loaders/api/recordReplay.js","../src/loaders/api/register-api-types.js","../src/loaders/api/register.js","../src/loaders/api/setApplicationVersion.js","../src/loaders/api/setCustomAttribute.js","../src/loaders/api/setErrorHandler.js","../src/loaders/api/setPageViewName.js","../src/loaders/api/setUserId.js","../src/loaders/api/sharedHandlers.js","../src/loaders/api/start.js","../src/loaders/api/topLevelCallers.js","../src/loaders/api/wrapLogger.js","../src/loaders/configure/configure.js","../src/loaders/configure/nonce.js","../src/loaders/configure/public-path.js","../src/loaders/features/enabled-features.js","../src/loaders/features/featureDependencies.js","../src/loaders/features/features.js"],"version":"5.9.3"}
1
+ {"root":["../src/index.js","../src/cdn/experimental.js","../src/cdn/lite.js","../src/cdn/pro.js","../src/cdn/spa.js","../src/common/aggregate/aggregator.js","../src/common/aggregate/event-aggregator.js","../src/common/config/configurable.js","../src/common/config/info.js","../src/common/config/init-types.js","../src/common/config/init.js","../src/common/config/loader-config.js","../src/common/config/runtime.js","../src/common/constants/agent-constants.js","../src/common/constants/env.cdn.js","../src/common/constants/env.js","../src/common/constants/env.npm.js","../src/common/constants/runtime.js","../src/common/constants/shared-channel.js","../src/common/deny-list/deny-list.js","../src/common/dispatch/global-event.js","../src/common/dom/iframe.js","../src/common/dom/query-selector.js","../src/common/dom/selector-path.js","../src/common/drain/drain.js","../src/common/event-emitter/contextual-ee.js","../src/common/event-emitter/event-context.js","../src/common/event-emitter/handle.js","../src/common/event-emitter/register-handler.js","../src/common/event-listener/event-listener-opts.js","../src/common/harvest/harvester.js","../src/common/harvest/types.js","../src/common/ids/bundle-id.js","../src/common/ids/id.js","../src/common/ids/unique-id.js","../src/common/serialize/bel-serializer.js","../src/common/session/constants.js","../src/common/session/session-entity.js","../src/common/storage/local-storage.js","../src/common/timer/interaction-timer.js","../src/common/timer/timer.js","../src/common/timing/nav-timing.js","../src/common/timing/now.js","../src/common/timing/time-keeper.js","../src/common/unload/eol.js","../src/common/url/canonicalize-url.js","../src/common/url/clean-url.js","../src/common/url/encode.js","../src/common/url/extract-url.js","../src/common/url/location.js","../src/common/url/parse-url.js","../src/common/url/protocol.js","../src/common/util/attribute-size.js","../src/common/util/browser-stack-matchers.js","../src/common/util/console.js","../src/common/util/data-size.js","../src/common/util/event-origin.js","../src/common/util/feature-flags.js","../src/common/util/get-or-set.js","../src/common/util/invoke.js","../src/common/util/monkey-patched.js","../src/common/util/obfuscate.js","../src/common/util/short-circuit.js","../src/common/util/stringify.js","../src/common/util/submit-data.js","../src/common/util/text.js","../src/common/util/traverse.js","../src/common/util/type-check.js","../src/common/util/webdriver-detection.js","../src/common/v2/script-correlation.js","../src/common/v2/script-tracker.js","../src/common/v2/utils.js","../src/common/vitals/constants.js","../src/common/vitals/cumulative-layout-shift.js","../src/common/vitals/first-contentful-paint.js","../src/common/vitals/first-paint.js","../src/common/vitals/interaction-to-next-paint.js","../src/common/vitals/largest-contentful-paint.js","../src/common/vitals/load-time.js","../src/common/vitals/time-to-first-byte.js","../src/common/vitals/vital-metric.js","../src/common/window/load.js","../src/common/window/nreum.js","../src/common/window/page-visibility.js","../src/common/wrap/wrap-events.js","../src/common/wrap/wrap-fetch.js","../src/common/wrap/wrap-function.js","../src/common/wrap/wrap-history.js","../src/common/wrap/wrap-logger.js","../src/common/wrap/wrap-websocket.js","../src/common/wrap/wrap-xhr.js","../src/features/ajax/constants.js","../src/features/ajax/index.js","../src/features/ajax/aggregate/gql.js","../src/features/ajax/aggregate/index.js","../src/features/ajax/instrument/distributed-tracing.js","../src/features/ajax/instrument/index.js","../src/features/ajax/instrument/response-size.js","../src/features/generic_events/constants.js","../src/features/generic_events/index.js","../src/features/generic_events/aggregate/index.js","../src/features/generic_events/aggregate/user-actions/aggregated-user-action.js","../src/features/generic_events/aggregate/user-actions/user-actions-aggregator.js","../src/features/generic_events/instrument/index.js","../src/features/jserrors/constants.js","../src/features/jserrors/index.js","../src/features/jserrors/aggregate/canonical-function-name.js","../src/features/jserrors/aggregate/cause-string.js","../src/features/jserrors/aggregate/compute-stack-trace.js","../src/features/jserrors/aggregate/format-stack-trace.js","../src/features/jserrors/aggregate/index.js","../src/features/jserrors/aggregate/internal-errors.js","../src/features/jserrors/aggregate/string-hash-code.js","../src/features/jserrors/instrument/index.js","../src/features/jserrors/shared/cast-error.js","../src/features/jserrors/shared/uncaught-error.js","../src/features/logging/constants.js","../src/features/logging/index.js","../src/features/logging/aggregate/index.js","../src/features/logging/instrument/index.js","../src/features/logging/shared/log.js","../src/features/logging/shared/utils.js","../src/features/metrics/constants.js","../src/features/metrics/index.js","../src/features/metrics/aggregate/framework-detection.js","../src/features/metrics/aggregate/harvest-metadata.js","../src/features/metrics/aggregate/index.js","../src/features/metrics/instrument/index.js","../src/features/page_action/constants.js","../src/features/page_action/index.js","../src/features/page_action/instrument/index.js","../src/features/page_view_event/constants.js","../src/features/page_view_event/index.js","../src/features/page_view_event/aggregate/index.js","../src/features/page_view_event/aggregate/initialized-features.js","../src/features/page_view_event/instrument/index.js","../src/features/page_view_timing/constants.js","../src/features/page_view_timing/index.js","../src/features/page_view_timing/aggregate/index.js","../src/features/page_view_timing/instrument/index.js","../src/features/session_replay/constants.js","../src/features/session_replay/index.js","../src/features/session_replay/aggregate/index.js","../src/features/session_replay/instrument/index.js","../src/features/session_replay/shared/recorder-events.js","../src/features/session_replay/shared/recorder.js","../src/features/session_replay/shared/stylesheet-evaluator.js","../src/features/session_replay/shared/utils.js","../src/features/session_trace/constants.js","../src/features/session_trace/index.js","../src/features/session_trace/aggregate/index.js","../src/features/session_trace/aggregate/trace/node.js","../src/features/session_trace/aggregate/trace/storage.js","../src/features/session_trace/aggregate/trace/utils.js","../src/features/session_trace/instrument/index.js","../src/features/soft_navigations/constants.js","../src/features/soft_navigations/index.js","../src/features/soft_navigations/aggregate/ajax-node.js","../src/features/soft_navigations/aggregate/bel-node.js","../src/features/soft_navigations/aggregate/index.js","../src/features/soft_navigations/aggregate/initial-page-load-interaction.js","../src/features/soft_navigations/aggregate/interaction.js","../src/features/soft_navigations/instrument/index.js","../src/features/utils/agent-session.js","../src/features/utils/aggregate-base.js","../src/features/utils/event-buffer.js","../src/features/utils/feature-base.js","../src/features/utils/feature-gates.js","../src/features/utils/instrument-base.js","../src/interfaces/registered-entity.js","../src/loaders/agent-base.js","../src/loaders/agent.js","../src/loaders/api-base.js","../src/loaders/browser-agent.js","../src/loaders/micro-agent-base.js","../src/loaders/micro-agent.js","../src/loaders/api/addPageAction.js","../src/loaders/api/addRelease.js","../src/loaders/api/addToTrace.js","../src/loaders/api/consent.js","../src/loaders/api/constants.js","../src/loaders/api/finished.js","../src/loaders/api/interaction-types.js","../src/loaders/api/interaction.js","../src/loaders/api/log.js","../src/loaders/api/measure.js","../src/loaders/api/noticeError.js","../src/loaders/api/pauseReplay.js","../src/loaders/api/recordCustomEvent.js","../src/loaders/api/recordReplay.js","../src/loaders/api/register-api-types.js","../src/loaders/api/register.js","../src/loaders/api/setApplicationVersion.js","../src/loaders/api/setCustomAttribute.js","../src/loaders/api/setErrorHandler.js","../src/loaders/api/setPageViewName.js","../src/loaders/api/setUserId.js","../src/loaders/api/sharedHandlers.js","../src/loaders/api/start.js","../src/loaders/api/topLevelCallers.js","../src/loaders/api/wrapLogger.js","../src/loaders/configure/configure.js","../src/loaders/configure/nonce.js","../src/loaders/configure/public-path.js","../src/loaders/features/enabled-features.js","../src/loaders/features/featureDependencies.js","../src/loaders/features/features.js"],"version":"5.9.3"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /** A special error used to short-circuit the error processing pipeline */
6
+ export class ShortCircuit extends Error {
7
+ }
8
+ //# sourceMappingURL=short-circuit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"short-circuit.d.ts","sourceRoot":"","sources":["../../../../src/common/util/short-circuit.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH,0EAA0E;AAC1E;CAA0C"}
@@ -14,25 +14,34 @@ export class Aggregate extends AggregateBase {
14
14
  pve: string;
15
15
  };
16
16
  /**
17
- * Builds a standardized stack trace string from the frames in the given `stackInfo` object, with each frame separated
18
- * by a newline character. Lines take the form `<functionName>@<url>:<lineNumber>`.
17
+ * Main entry point for processing JavaScript errors. This method orchestrates the complete error processing pipeline.
19
18
  *
20
- * @param {StackInfo} stackInfo - An object specifying a stack string and individual frames.
21
- * @returns {string} A canonical stack string built from the URLs and function names in the given `stackInfo` object.
22
- */
23
- buildCanonicalStackString(stackInfo: StackInfo): string;
24
- /**
19
+ * Processing Flow:
20
+ * 1. Filter the error through the customer's onerror handler (if configured and not internal)
21
+ * 2. Compute the stack trace from the error object
22
+ * 3. Evaluate if the error should be swallowed (internal errors, known issues, etc.)
23
+ * 4. Derive target(s) for the error (MFE detection for v2 endpoints, or default target) - Note: "undefined" indicates the default target will be used
24
+ * 5. Store the error for each derived target. During storage (#storeJserrorForHarvest), duplication for MFE <-> container will be handled
25
+ *
26
+ * Important: "ShortCircuit" Pattern:
27
+ * Several steps in the pipeline can throw a ShortCircuit error to halt processing without
28
+ * treating it as a reportable error. This pattern is used when:
29
+ * - The customer's onerror handler returns a truthy value (excluding fingerprinting objects)
30
+ * - The error is identified as an internal error that shouldn't be reported
31
+ *
32
+ * When a ShortCircuit is thrown, processing stops immediately and the error is not stored.
33
+ * Any other thrown error is re-thrown as it represents an actual problem in the agent code.
25
34
  *
26
- * @param {Error|UncaughtError} err The error instance to be processed
27
- * @param {number} time the relative ms (to origin) timestamp of occurrence
28
- * @param {boolean=} internal if the error was "caught" and deemed "internal" before reporting to the jserrors feature
29
- * @param {object=} customAttributes any custom attributes to be included in the error payload
30
- * @param {boolean=} hasReplay a flag indicating if the error occurred during a replay session
31
- * @param {string=} swallowReason a string indicating pre-defined reason if swallowing the error. Mainly used by the internal error SMs.
32
- * @param {object=} target the target to buffer and harvest to, if undefined the default configuration target is used
33
- * @returns
35
+ * @param {Error|UncaughtError} err - The error instance to be processed
36
+ * @param {number} [time] - The relative ms (to origin) timestamp of occurrence. Defaults to now()
37
+ * @param {boolean} [internal=false] - If the error was "caught" and deemed "internal" before reporting to the jserrors feature
38
+ * @param {object} [customAttributes] - Any custom attributes to be included in the error payload
39
+ * @param {boolean} [hasReplay=false] - A flag indicating if the error occurred during a replay session
40
+ * @param {string} [swallowReason] - A string indicating pre-defined reason if swallowing the error. Mainly used by internal error supportability metrics
41
+ * @param {object} [target] - The target to buffer and harvest to. If undefined, the default configuration target is used
42
+ * @returns {void}
34
43
  */
35
- storeError(err: Error | UncaughtError, time: number, internal?: boolean | undefined, customAttributes?: object | undefined, hasReplay?: boolean | undefined, swallowReason?: string | undefined, target?: object | undefined): void;
44
+ processError(err: Error | UncaughtError, time?: number, internal?: boolean, customAttributes?: object, hasReplay?: boolean, swallowReason?: string, target?: object): void;
36
45
  #private;
37
46
  }
38
47
  export type StackInfo = import("./compute-stack-trace.js").StackInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/jserrors/aggregate/index.js"],"names":[],"mappings":"AAwBA;;GAEG;AAEH;IACE,2BAAiC;IACjC,2BAuBC;IAlBC,kBAAuB;IACvB,eAAoB;IACpB,qBAA0B;IAC1B,qBAAwB;IAiB1B,oDAEC;IAED;;;MAcC;IAED;;;;;;OAMG;IACH,qCAHW,SAAS,GACP,MAAM,CAgBlB;IAED;;;;;;;;;;OAUG;IACH,gBATW,KAAK,GAAC,aAAa,QACnB,MAAM,aACN,OAAO,YAAC,qBACR,MAAM,YAAC,cACP,OAAO,YAAC,kBACR,MAAM,YAAC,WACP,MAAM,YAAC,QAkGjB;;CAuBF;wBA1MY,OAAO,0BAA0B,EAAE,SAAS;8BAR3B,4BAA4B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/jserrors/aggregate/index.js"],"names":[],"mappings":"AAyBA;;GAEG;AAEH;IACE,2BAAiC;IACjC,2BAuBC;IAlBC,kBAAuB;IACvB,eAAoB;IACpB,qBAA0B;IAC1B,qBAAwB;IAiB1B,oDAEC;IAED;;;MAcC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,kBATW,KAAK,GAAC,aAAa,SACnB,MAAM,aACN,OAAO,qBACP,MAAM,cACN,OAAO,kBACP,MAAM,WACN,MAAM,GACJ,IAAI,CAiBhB;;CAyQF;wBAtWY,OAAO,0BAA0B,EAAE,SAAS;8BAT3B,4BAA4B"}
@@ -4,5 +4,11 @@
4
4
  * It is not recommended for use in production environments and will not receive support for issues.
5
5
  */
6
6
  export function setupRegisterAPI(agent: any): void;
7
+ export namespace warnings {
8
+ let experimental: Function;
9
+ let disabled: Function;
10
+ let invalidTarget: Function;
11
+ let deregistered: Function;
12
+ }
7
13
  export type RegisterAPI = import("./register-api-types").RegisterAPI;
8
14
  //# sourceMappingURL=register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"AA4BA;;;;GAIG;AACH,mDAIC;0BAdY,OAAO,sBAAsB,EAAE,WAAW"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"AAuCA;;;;GAIG;AACH,mDAIC;;;;;;;0BAzBY,OAAO,sBAAsB,EAAE,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.312.1-rc.11",
3
+ "version": "1.312.1-rc.13",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /** A special error used to short-circuit the error processing pipeline */
6
+ export class ShortCircuit extends Error {}