@newrelic/browser-agent 1.309.0 → 1.310.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.
- package/CHANGELOG.md +14 -0
- package/README.md +0 -2
- package/dist/cjs/common/config/init-types.js +1 -4
- package/dist/cjs/common/config/init.js +1 -5
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/util/browser-stack-matchers.js +15 -0
- package/dist/cjs/common/util/script-tracker.js +184 -0
- package/dist/cjs/common/wrap/wrap-fetch.js +2 -2
- package/dist/cjs/common/wrap/wrap-history.js +2 -2
- package/dist/cjs/common/wrap/wrap-logger.js +2 -2
- package/dist/cjs/common/wrap/wrap-xhr.js +2 -2
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +6 -10
- package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +1 -2
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/interfaces/registered-entity.js +2 -1
- package/dist/cjs/loaders/agent.js +1 -4
- package/dist/cjs/loaders/api/register-api-types.js +20 -8
- package/dist/cjs/loaders/api/register.js +36 -2
- package/dist/cjs/loaders/api-base.js +1 -1
- package/dist/cjs/loaders/features/features.js +6 -9
- package/dist/esm/common/config/init-types.js +1 -4
- package/dist/esm/common/config/init.js +1 -5
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/util/browser-stack-matchers.js +9 -0
- package/dist/esm/common/util/script-tracker.js +179 -0
- package/dist/esm/common/wrap/wrap-fetch.js +2 -2
- package/dist/esm/common/wrap/wrap-history.js +2 -2
- package/dist/esm/common/wrap/wrap-logger.js +2 -2
- package/dist/esm/common/wrap/wrap-xhr.js +2 -2
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +2 -6
- package/dist/esm/features/page_view_event/aggregate/initialized-features.js +1 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/interfaces/registered-entity.js +2 -1
- package/dist/esm/loaders/agent.js +1 -4
- package/dist/esm/loaders/api/register-api-types.js +22 -8
- package/dist/esm/loaders/api/register.js +36 -2
- package/dist/esm/loaders/api-base.js +1 -1
- package/dist/esm/loaders/features/features.js +6 -9
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/common/config/init-types.d.ts +0 -10
- package/dist/types/common/config/init.d.ts.map +1 -1
- package/dist/types/common/util/browser-stack-matchers.d.ts +10 -0
- package/dist/types/common/util/browser-stack-matchers.d.ts.map +1 -0
- package/dist/types/common/util/script-tracker.d.ts +7 -0
- package/dist/types/common/util/script-tracker.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interfaces/registered-entity.d.ts +4 -5
- package/dist/types/interfaces/registered-entity.d.ts.map +1 -1
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/api/register-api-types.d.ts +58 -14
- package/dist/types/loaders/api/register-api-types.d.ts.map +1 -1
- package/dist/types/loaders/api/register.d.ts.map +1 -1
- package/dist/types/loaders/api-base.d.ts +4 -5
- package/dist/types/loaders/api-base.d.ts.map +1 -1
- package/dist/types/loaders/features/features.d.ts +2 -5
- package/dist/types/loaders/features/features.d.ts.map +1 -1
- package/package.json +1 -9
- package/src/common/config/init-types.js +1 -4
- package/src/common/config/init.js +1 -2
- package/src/common/util/browser-stack-matchers.js +9 -0
- package/src/common/util/script-tracker.js +171 -0
- package/src/common/wrap/wrap-fetch.js +2 -2
- package/src/common/wrap/wrap-history.js +2 -2
- package/src/common/wrap/wrap-logger.js +2 -2
- package/src/common/wrap/wrap-xhr.js +2 -2
- package/src/features/jserrors/aggregate/compute-stack-trace.js +2 -7
- package/src/features/page_view_event/aggregate/initialized-features.js +1 -2
- package/src/index.js +2 -2
- package/src/interfaces/registered-entity.js +2 -1
- package/src/loaders/agent.js +0 -4
- package/src/loaders/api/register-api-types.js +22 -8
- package/src/loaders/api/register.js +31 -2
- package/src/loaders/api-base.js +1 -1
- package/src/loaders/features/features.js +6 -9
- package/dist/cjs/common/wrap/wrap-jsonp.js +0 -137
- package/dist/cjs/common/wrap/wrap-mutation.js +0 -62
- package/dist/cjs/common/wrap/wrap-promise.js +0 -166
- package/dist/cjs/common/wrap/wrap-timer.js +0 -71
- package/dist/cjs/features/spa/aggregate/index.js +0 -672
- package/dist/cjs/features/spa/aggregate/interaction-node.js +0 -83
- package/dist/cjs/features/spa/aggregate/interaction.js +0 -95
- package/dist/cjs/features/spa/aggregate/serializer.js +0 -150
- package/dist/cjs/features/spa/constants.js +0 -35
- package/dist/cjs/features/spa/index.js +0 -12
- package/dist/cjs/features/spa/instrument/index.js +0 -136
- package/dist/esm/common/wrap/wrap-jsonp.js +0 -130
- package/dist/esm/common/wrap/wrap-mutation.js +0 -55
- package/dist/esm/common/wrap/wrap-promise.js +0 -159
- package/dist/esm/common/wrap/wrap-timer.js +0 -64
- package/dist/esm/features/spa/aggregate/index.js +0 -663
- package/dist/esm/features/spa/aggregate/interaction-node.js +0 -77
- package/dist/esm/features/spa/aggregate/interaction.js +0 -88
- package/dist/esm/features/spa/aggregate/serializer.js +0 -142
- package/dist/esm/features/spa/constants.js +0 -28
- package/dist/esm/features/spa/index.js +0 -5
- package/dist/esm/features/spa/instrument/index.js +0 -129
- package/dist/types/common/wrap/wrap-jsonp.d.ts +0 -16
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +0 -1
- package/dist/types/common/wrap/wrap-mutation.d.ts +0 -16
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +0 -1
- package/dist/types/common/wrap/wrap-promise.d.ts +0 -17
- package/dist/types/common/wrap/wrap-promise.d.ts.map +0 -1
- package/dist/types/common/wrap/wrap-timer.d.ts +0 -17
- package/dist/types/common/wrap/wrap-timer.d.ts.map +0 -1
- package/dist/types/features/spa/aggregate/index.d.ts +0 -24
- package/dist/types/features/spa/aggregate/index.d.ts.map +0 -1
- package/dist/types/features/spa/aggregate/interaction-node.d.ts +0 -15
- package/dist/types/features/spa/aggregate/interaction-node.d.ts.map +0 -1
- package/dist/types/features/spa/aggregate/interaction.d.ts +0 -19
- package/dist/types/features/spa/aggregate/interaction.d.ts.map +0 -1
- package/dist/types/features/spa/aggregate/serializer.d.ts +0 -17
- package/dist/types/features/spa/aggregate/serializer.d.ts.map +0 -1
- package/dist/types/features/spa/constants.d.ts +0 -23
- package/dist/types/features/spa/constants.d.ts.map +0 -1
- package/dist/types/features/spa/index.d.ts +0 -2
- package/dist/types/features/spa/index.d.ts.map +0 -1
- package/dist/types/features/spa/instrument/index.d.ts +0 -12
- package/dist/types/features/spa/instrument/index.d.ts.map +0 -1
- package/src/common/wrap/wrap-jsonp.js +0 -142
- package/src/common/wrap/wrap-mutation.js +0 -58
- package/src/common/wrap/wrap-promise.js +0 -176
- package/src/common/wrap/wrap-timer.js +0 -70
- package/src/features/spa/aggregate/index.js +0 -734
- package/src/features/spa/aggregate/interaction-node.js +0 -85
- package/src/features/spa/aggregate/interaction.js +0 -108
- package/src/features/spa/aggregate/serializer.js +0 -200
- package/src/features/spa/constants.js +0 -39
- package/src/features/spa/index.js +0 -5
- package/src/features/spa/instrument/index.js +0 -134
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.featurePriority = exports.RUM = exports.LOGS = exports.JSERRORS = exports.FEATURE_TO_ENDPOINT = exports.FEATURE_NAMES = exports.EVENTS = exports.BLOBS = void 0;
|
|
7
7
|
/**
|
|
8
|
-
* Copyright 2020-
|
|
8
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
9
9
|
* SPDX-License-Identifier: Apache-2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -29,8 +29,7 @@ const FEATURE_NAMES = exports.FEATURE_NAMES = {
|
|
|
29
29
|
pageViewTiming: 'page_view_timing',
|
|
30
30
|
sessionReplay: 'session_replay',
|
|
31
31
|
sessionTrace: 'session_trace',
|
|
32
|
-
softNav: 'soft_navigations'
|
|
33
|
-
spa: 'spa'
|
|
32
|
+
softNav: 'soft_navigations'
|
|
34
33
|
};
|
|
35
34
|
|
|
36
35
|
/**
|
|
@@ -42,19 +41,17 @@ const featurePriority = exports.featurePriority = {
|
|
|
42
41
|
[FEATURE_NAMES.pageViewTiming]: 2,
|
|
43
42
|
[FEATURE_NAMES.metrics]: 3,
|
|
44
43
|
[FEATURE_NAMES.jserrors]: 4,
|
|
45
|
-
[FEATURE_NAMES.
|
|
44
|
+
[FEATURE_NAMES.softNav]: 5,
|
|
46
45
|
[FEATURE_NAMES.ajax]: 6,
|
|
47
46
|
[FEATURE_NAMES.sessionTrace]: 7,
|
|
48
|
-
[FEATURE_NAMES.
|
|
49
|
-
[FEATURE_NAMES.
|
|
50
|
-
[FEATURE_NAMES.
|
|
51
|
-
[FEATURE_NAMES.genericEvents]: 11
|
|
47
|
+
[FEATURE_NAMES.sessionReplay]: 8,
|
|
48
|
+
[FEATURE_NAMES.logging]: 9,
|
|
49
|
+
[FEATURE_NAMES.genericEvents]: 10
|
|
52
50
|
};
|
|
53
51
|
const FEATURE_TO_ENDPOINT = exports.FEATURE_TO_ENDPOINT = {
|
|
54
52
|
[FEATURE_NAMES.pageViewEvent]: RUM,
|
|
55
53
|
[FEATURE_NAMES.pageViewTiming]: EVENTS,
|
|
56
54
|
[FEATURE_NAMES.ajax]: EVENTS,
|
|
57
|
-
[FEATURE_NAMES.spa]: EVENTS,
|
|
58
55
|
[FEATURE_NAMES.softNav]: EVENTS,
|
|
59
56
|
[FEATURE_NAMES.metrics]: JSERRORS,
|
|
60
57
|
[FEATURE_NAMES.jserrors]: JSERRORS,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
@@ -80,9 +80,6 @@
|
|
|
80
80
|
* @property {Object} [soft_navigations]
|
|
81
81
|
* @property {boolean} [soft_navigations.enabled] - Turn on/off the soft navigations feature (on by default).
|
|
82
82
|
* @property {boolean} [soft_navigations.autoStart] - If true, the agent will automatically start the soft navigations feature. Otherwise, it will be in a deferred state until the `start` API method is called.
|
|
83
|
-
* @property {Object} [spa]
|
|
84
|
-
* @property {boolean} [spa.enabled] - Turn on/off the single page application feature (on by default). NOTE: the SPA feature is deprecated and under removal procedure.
|
|
85
|
-
* @property {boolean} [spa.autoStart] - If true, the agent will automatically start the single page application feature. Otherwise, it will be in a deferred state until the `start` API method is called.
|
|
86
83
|
* @property {boolean} [ssl] - If explicitly false, the agent will use HTTP instead of HTTPS. This setting should NOT be used.
|
|
87
84
|
* @property {Object} [browser_consent_mode]
|
|
88
85
|
* @property {boolean} [browser_consent_mode.enabled] - If true, the agent will use consent mode for whether to allow or disallow data harvest.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { FEATURE_FLAGS } from '../../features/generic_events/constants';
|
|
@@ -190,10 +190,6 @@ const InitModelFn = () => {
|
|
|
190
190
|
enabled: true,
|
|
191
191
|
autoStart: true
|
|
192
192
|
},
|
|
193
|
-
spa: {
|
|
194
|
-
enabled: true,
|
|
195
|
-
autoStart: true
|
|
196
|
-
},
|
|
197
193
|
ssl: undefined,
|
|
198
194
|
user_actions: {
|
|
199
195
|
enabled: true,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
export const classNameRegex = /function (.+?)\s*\(/;
|
|
6
|
+
export const chromeEval = /^\s*at .+ \(eval at \S+ \((?:(?:file|http|https):[^)]+)?\)(?:, [^:]*:\d+:\d+)?\)$/i;
|
|
7
|
+
export const ieEval = /^\s*at Function code \(Function code:\d+:\d+\)\s*/i;
|
|
8
|
+
export const chrome = /^\s*at (?:((?:\[object object\])?(?:[^(]*\([^)]*\))*[^()]*(?: \[as \S+\])?) )?\(?((?:file|http|https|chrome-extension):.*?)?:(\d+)(?::(\d+))?\)?\s*$/i;
|
|
9
|
+
export const gecko = /^\s*(?:([^@]*)(?:\(.*?\))?@)?((?:file|http|https|chrome|safari-extension).*?):(\d+)(?::(\d+))?\s*$/i;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { globalScope } from '../constants/runtime';
|
|
7
|
+
import { now } from '../timing/now';
|
|
8
|
+
import { cleanURL } from '../url/clean-url';
|
|
9
|
+
import { chrome, gecko } from './browser-stack-matchers';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {import('./register-api-types').RegisterAPITimings} RegisterAPITimings
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** @type {(entry: PerformanceEntry) => boolean} - A shared function to determine if a performance entry is a valid script or link resource for evaluation */
|
|
16
|
+
const validEntryCriteria = entry => entry.initiatorType === 'script' || entry.initiatorType === 'link' && entry.name.endsWith('.js');
|
|
17
|
+
|
|
18
|
+
/** @type {Set<PerformanceResourceTiming>} - A set of resource timing objects that are "valid" -- see "validEntryCriteria" */
|
|
19
|
+
const scripts = new Set();
|
|
20
|
+
/** @type {Array<{ test: (entry: PerformanceEntry) => boolean, addedAt: number }>} an array of PerformanceObserver subscribers to check for late emissions */
|
|
21
|
+
let poSubscribers = [];
|
|
22
|
+
if (globalScope.PerformanceObserver?.supportedEntryTypes.includes('resource')) {
|
|
23
|
+
/** We must track the script assets this way, because the performance buffer can fill up and when it does that
|
|
24
|
+
* it stops accepting new entries (instead of dropping old entries), which means if the register API is called
|
|
25
|
+
* after the buffer fills up we won't be able to get the script timing information from the resource timing API
|
|
26
|
+
*/
|
|
27
|
+
const scriptObserver = new PerformanceObserver(list => {
|
|
28
|
+
list.getEntries().forEach(entry => {
|
|
29
|
+
if (validEntryCriteria(entry)) {
|
|
30
|
+
if (scripts.size > 250) scripts.delete(scripts.values().next().value); // keep the set from growing indefinitely, we only need to check recent entries against the stack of the register API caller, so we can drop old entries as new ones come in
|
|
31
|
+
scripts.add(entry);
|
|
32
|
+
const canClear = [];
|
|
33
|
+
poSubscribers.forEach(({
|
|
34
|
+
test,
|
|
35
|
+
addedAt
|
|
36
|
+
}, idx) => {
|
|
37
|
+
if (test(entry) || now() - addedAt > 10000) canClear.push(idx); // Clear subscribers that have resolved or have been pending for more than 10 seconds
|
|
38
|
+
});
|
|
39
|
+
poSubscribers = poSubscribers.filter((_, idx) => !canClear.includes(idx));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
scriptObserver.observe({
|
|
44
|
+
type: 'resource',
|
|
45
|
+
buffered: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Extracts URLs from stack traces using the same logic as compute-stack-trace.js
|
|
51
|
+
* @param {string} stack The error stack trace
|
|
52
|
+
* @returns {string[]} Array of cleaned URLs found in the stack trace
|
|
53
|
+
*/
|
|
54
|
+
function extractUrlsFromStack(stack) {
|
|
55
|
+
if (!stack || typeof stack !== 'string') return [];
|
|
56
|
+
const urls = new Set();
|
|
57
|
+
const lines = stack.split('\n');
|
|
58
|
+
for (const line of lines) {
|
|
59
|
+
// Try gecko format first, then chrome
|
|
60
|
+
const parts = line.match(gecko) || line.match(chrome);
|
|
61
|
+
if (parts && parts[2]) {
|
|
62
|
+
urls.add(cleanURL(parts[2]));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return [...urls];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns a deep stack trace by temporarily increasing the stack trace limit.
|
|
70
|
+
* @returns {Error.stack | undefined}
|
|
71
|
+
*/
|
|
72
|
+
function getDeepStackTrace() {
|
|
73
|
+
let stack;
|
|
74
|
+
try {
|
|
75
|
+
const originalStackLimit = Error.stackTraceLimit;
|
|
76
|
+
Error.stackTraceLimit = 50;
|
|
77
|
+
stack = new Error().stack;
|
|
78
|
+
Error.stackTraceLimit = originalStackLimit;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
stack = new Error().stack;
|
|
81
|
+
}
|
|
82
|
+
return stack;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Indicates whether the provided URL matches any script preload link tags in the document.
|
|
87
|
+
* @param {string} targetUrl The URL to match against preload tags
|
|
88
|
+
* @returns {boolean} True if a matching preload link is found, false otherwise
|
|
89
|
+
*/
|
|
90
|
+
function wasPreloaded(targetUrl) {
|
|
91
|
+
if (!targetUrl || !globalScope.document) return false;
|
|
92
|
+
try {
|
|
93
|
+
const linkTags = globalScope.document.querySelectorAll('link[rel="preload"][as="script"]');
|
|
94
|
+
for (const link of linkTags) {
|
|
95
|
+
// link.href is resolved to an absolute URL by the browser (even if supplied as relative), so we can match exactly against the cleaned target URL
|
|
96
|
+
if (cleanURL(link.href) === targetUrl) return true;
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
// Don't let DOM parsing errors break anything
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Uses the stack of the initiator function, returns script timing information if a script can be found with the resource timing API matching the URL found in the stack.
|
|
106
|
+
* @returns {RegisterAPITimings} Object containing script fetch start and end times, and the asset URL if found
|
|
107
|
+
*/
|
|
108
|
+
export function findScriptTimings() {
|
|
109
|
+
const timings = {
|
|
110
|
+
registeredAt: now(),
|
|
111
|
+
reportedAt: undefined,
|
|
112
|
+
fetchStart: 0,
|
|
113
|
+
fetchEnd: 0,
|
|
114
|
+
asset: undefined,
|
|
115
|
+
type: 'unknown'
|
|
116
|
+
};
|
|
117
|
+
const stack = getDeepStackTrace();
|
|
118
|
+
if (!stack) return timings;
|
|
119
|
+
const navUrl = globalScope.performance?.getEntriesByType('navigation')?.find(entry => entry.initiatorType === 'navigation')?.name || '';
|
|
120
|
+
try {
|
|
121
|
+
const mfeScriptUrl = extractUrlsFromStack(stack).at(-1); // array of URLs from the stack of the register API caller, the MFE script should be at the bottom
|
|
122
|
+
if (!mfeScriptUrl) return timings;
|
|
123
|
+
if (navUrl.includes(mfeScriptUrl)) {
|
|
124
|
+
// this means the stack is indicating that the registration came from an inline script or eval, so we won't find a matching script resource - return early with just the URL
|
|
125
|
+
timings.asset = cleanURL(navUrl);
|
|
126
|
+
timings.type = 'inline';
|
|
127
|
+
return timings;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// try to find it in the static list, which updates faster than the PO. This cant be solely trusted, since the buffer can fill up and stop accepting entries,
|
|
131
|
+
// but it can still help in cases where the check is made before the asset is emitted by the performance observer and the buffer is not full. Fallback to checking the PO
|
|
132
|
+
// entries that have been buffered as seen in the PO callback if its not found in the static list.
|
|
133
|
+
const match = performance.getEntriesByType('resource').find(entryMatchesMfe) || [...scripts].find(entryMatchesMfe);
|
|
134
|
+
if (match) {
|
|
135
|
+
setMatchedAttributes(match);
|
|
136
|
+
} else {
|
|
137
|
+
// We didnt find a match with the PO, nor a static lookup... check if its preloaded and if so, set basic fallbacks and try to associate with a later script entry if possible, this can happen if the preload is reported late in the PO observer callback
|
|
138
|
+
if (wasPreloaded(mfeScriptUrl)) {
|
|
139
|
+
timings.asset = mfeScriptUrl;
|
|
140
|
+
timings.type = 'preload';
|
|
141
|
+
// wait for a late PO callback... The timings object can be mutated after the fact since we return a pointer and not a cloned object
|
|
142
|
+
poSubscribers.push({
|
|
143
|
+
addedAt: now(),
|
|
144
|
+
test: entry => {
|
|
145
|
+
if (entryMatchesMfe(entry)) {
|
|
146
|
+
setMatchedAttributes(entry);
|
|
147
|
+
return true; // return true so that we know to clear this callback from the pending list since we found our match, otherwise it will stay in the list and be called for future entries which is unnecessary after we found our match and can cause performance issues if there are a lot of future entries and pending callbacks
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A matcher function to determine if a performance entry corresponds to the MFE script based on URL matching. It checks if either the entry URL ends with the MFE script URL or vice versa, to account for potential differences in how URLs are represented in the stack trace versus the resource timing entries.
|
|
157
|
+
* @param {PerformanceResourceTiming} entry - The resource timing entry to compare to the MFE script
|
|
158
|
+
* @returns {boolean} True if we think the entry matches the MFE script, false otherwise
|
|
159
|
+
*/
|
|
160
|
+
function entryMatchesMfe(entry) {
|
|
161
|
+
const entryUrl = cleanURL(entry.name);
|
|
162
|
+
return entryUrl.endsWith(mfeScriptUrl) || mfeScriptUrl.endsWith(entryUrl);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A helper function to set the matched timing attributes on the timings object based on a performance entry. This is called when we have identified a resource timing entry that we believe corresponds to the MFE script, and we want to extract the fetch start and end times, as well as the asset URL and type.
|
|
167
|
+
* @param {PerformanceResourceTiming} entry - The resource timing entry to base values off of
|
|
168
|
+
*/
|
|
169
|
+
function setMatchedAttributes(entry) {
|
|
170
|
+
timings.fetchStart = Math.floor(entry.startTime);
|
|
171
|
+
timings.fetchEnd = Math.floor(entry.responseEnd);
|
|
172
|
+
timings.asset = entry.name;
|
|
173
|
+
timings.type = entry.initiatorType;
|
|
174
|
+
}
|
|
175
|
+
} catch (error) {
|
|
176
|
+
// Don't let stack parsing errors break anything
|
|
177
|
+
}
|
|
178
|
+
return timings;
|
|
179
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @file Wraps `fetch` and related methods for instrumentation.
|
|
8
|
-
* This module is used by: ajax
|
|
8
|
+
* This module is used by: ajax.
|
|
9
9
|
*/
|
|
10
10
|
import { ee as baseEE, contextId } from '../event-emitter/contextual-ee';
|
|
11
11
|
import { globalScope } from '../constants/runtime';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @file Wraps `pushState` and `replaceState` methods of `window.history` object for instrumentation.
|
|
8
|
-
* This module is used by: session_trace,
|
|
8
|
+
* This module is used by: session_trace, soft_navigations.
|
|
9
9
|
*/
|
|
10
10
|
import { ee as globalEE } from '../event-emitter/contextual-ee';
|
|
11
11
|
import { createWrapperWithEmitter as wfn } from './wrap-function';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @file Wraps native timeout and interval methods for instrumentation.
|
|
8
|
-
* This module is used by:
|
|
8
|
+
* This module is used by: logging.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { ee as baseEE, contextId } from '../event-emitter/contextual-ee';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @file Wraps AJAX (XHR) related methods for instrumentation.
|
|
8
|
-
* This module is used by: ajax, jserrors
|
|
8
|
+
* This module is used by: ajax, jserrors.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { wrapEvents } from './wrap-events';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -58,12 +58,8 @@
|
|
|
58
58
|
// ex.name = ReferenceError
|
|
59
59
|
import { formatStackTrace } from './format-stack-trace';
|
|
60
60
|
import { canonicalizeUrl } from '../../../common/url/canonicalize-url';
|
|
61
|
+
import { chrome, chromeEval, classNameRegex, gecko, ieEval } from '../../../common/util/browser-stack-matchers';
|
|
61
62
|
var debug = false;
|
|
62
|
-
var classNameRegex = /function (.+?)\s*\(/;
|
|
63
|
-
var chrome = /^\s*at (?:((?:\[object object\])?(?:[^(]*\([^)]*\))*[^()]*(?: \[as \S+\])?) )?\(?((?:file|http|https|chrome-extension):.*?)?:(\d+)(?::(\d+))?\)?\s*$/i;
|
|
64
|
-
var gecko = /^\s*(?:(\S*|global code)(?:\(.*?\))?@)?((?:file|http|https|chrome|safari-extension).*?):(\d+)(?::(\d+))?\s*$/i;
|
|
65
|
-
var chromeEval = /^\s*at .+ \(eval at \S+ \((?:(?:file|http|https):[^)]+)?\)(?:, [^:]*:\d+:\d+)?\)$/i;
|
|
66
|
-
var ieEval = /^\s*at Function code \(Function code:\d+:\d+\)\s*/i;
|
|
67
63
|
|
|
68
64
|
/**
|
|
69
65
|
* Represents an error with a stack trace.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { FEATURE_NAMES } from '../../../loaders/features/features';
|
|
@@ -30,7 +30,6 @@ export function getActivatedFeaturesFlags(agentId) {
|
|
|
30
30
|
flagArr.push('stn');
|
|
31
31
|
break;
|
|
32
32
|
case FEATURE_NAMES.softNav:
|
|
33
|
-
case FEATURE_NAMES.spa:
|
|
34
33
|
flagArr.push('spa');
|
|
35
34
|
break;
|
|
36
35
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
export { Agent } from './loaders/agent';
|
|
@@ -15,4 +15,4 @@ export { PageViewEvent } from './features/page_view_event';
|
|
|
15
15
|
export { PageViewTiming } from './features/page_view_timing';
|
|
16
16
|
export { SessionTrace } from './features/session_trace';
|
|
17
17
|
export { SessionReplay } from './features/session_replay';
|
|
18
|
-
export {
|
|
18
|
+
export { SoftNav } from './features/soft_navigations';
|
|
@@ -21,6 +21,7 @@ export class RegisteredEntity {
|
|
|
21
21
|
/** @type {RegisterAPIMetadata} */
|
|
22
22
|
metadata = {
|
|
23
23
|
target: {},
|
|
24
|
+
timings: {},
|
|
24
25
|
customAttributes: {}
|
|
25
26
|
};
|
|
26
27
|
|
|
@@ -87,7 +88,7 @@ export class RegisteredEntity {
|
|
|
87
88
|
* Measures a task that is recorded as a BrowserPerformance event.
|
|
88
89
|
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
|
|
89
90
|
* @param {string} name The name of the task
|
|
90
|
-
* @param {{start
|
|
91
|
+
* @param {{start?: number|PerformanceMark, end?: number|PerformanceMark, customAttributes?: object}} [options] An object used to control the way the measure API operates
|
|
91
92
|
* @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
|
|
92
93
|
*/
|
|
93
94
|
measure(name, options) {
|
|
@@ -89,10 +89,7 @@ export class Agent extends AgentBase {
|
|
|
89
89
|
featuresToStart.sort((a, b) => featurePriority[a.featureName] - featurePriority[b.featureName]);
|
|
90
90
|
featuresToStart.forEach(InstrumentCtor => {
|
|
91
91
|
if (!enabledFeatures[InstrumentCtor.featureName] && InstrumentCtor.featureName !== FEATURE_NAMES.pageViewEvent) return; // PVE is required to run even if it's marked disabled
|
|
92
|
-
|
|
93
|
-
warn(67);
|
|
94
|
-
return; // Skip old SPA
|
|
95
|
-
}
|
|
92
|
+
|
|
96
93
|
const dependencies = getFeatureDependencyNames(InstrumentCtor.featureName);
|
|
97
94
|
const missingDependencies = dependencies.filter(featName => !(featName in this.features)); // any other feature(s) this depends on should've been initialized on prior iterations by priority order
|
|
98
95
|
if (missingDependencies.length > 0) {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* @property {(target: RegisterAPIConstructor) => RegisterAPI} register - Record a custom event for the registered entity.
|
|
12
12
|
* @property {() => void} deregister - Deregister the registered entity, which blocks its use and captures end of life timings.
|
|
13
13
|
* @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
|
|
14
|
-
* @property {(eventType: string, options?: {start
|
|
14
|
+
* @property {(eventType: string, options?: {start?: number|PerformanceMark, end?: number|PerformanceMark, customAttributes?: object}) => ({start: number, end: number, duration: number, customAttributes: object})} measure - Measures a task that is recorded as a BrowserPerformance event.
|
|
15
15
|
* @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
|
|
16
16
|
* @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
|
|
17
17
|
* @property {(value: string | null, resetSession?: boolean) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity. Note: a registered entity will not be able to initiate a session reset. It must be done from the main agent.
|
|
@@ -30,13 +30,27 @@
|
|
|
30
30
|
/**
|
|
31
31
|
* @typedef {Object} RegisterAPIMetadata
|
|
32
32
|
* @property {Object} customAttributes - The custom attributes for the registered entity.
|
|
33
|
-
* @property {
|
|
34
|
-
* @property {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* @
|
|
39
|
-
* @property {
|
|
33
|
+
* @property {RegisterAPITimings} timings - The timing metrics for the registered entity.
|
|
34
|
+
* @property {RegisterAPITarget} target - The options for the registered entity.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {Object} RegisterAPITarget
|
|
39
|
+
* @property {string} id - The ID for the registered entity.
|
|
40
|
+
* @property {string} name - The name returned for the registered entity.
|
|
41
|
+
* @property {{[key: string]: any}} [tags] - The tags for the registered entity as key-value pairs.
|
|
42
|
+
* @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
43
|
+
* @property {boolean} [isolated] - When true, each registration creates an isolated instance. When false, multiple registrations with the same id and isolated: false will share a single instance, including all custom attributes, ids, names, and metadata. Calling deregister on a shared instance will deregister it for all entities using the instance. Defaults to true.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {Object} RegisterAPITimings
|
|
48
|
+
* @property {number} registeredAt - The timestamp when the registered entity was created.
|
|
49
|
+
* @property {number} [reportedAt] - The timestamp when the registered entity was deregistered.
|
|
50
|
+
* @property {number} fetchStart - The timestamp when the registered entity began fetching.
|
|
51
|
+
* @property {number} fetchEnd - The timestamp when the registered entity finished fetching.
|
|
52
|
+
* @property {Object} [asset] - The asset path (if found) for the registered entity.
|
|
53
|
+
* @property {string} type - The type of timing associated with the registered entity, 'script' or 'link' if found with the performance resource API, 'inline' if found to be associated with the root document URL, or 'unknown' if no associated resource could be found.
|
|
40
54
|
*/
|
|
41
55
|
|
|
42
56
|
export default {};
|
|
@@ -16,6 +16,8 @@ import { noticeError } from './noticeError';
|
|
|
16
16
|
import { single } from '../../common/util/invoke';
|
|
17
17
|
import { measure } from './measure';
|
|
18
18
|
import { recordCustomEvent } from './recordCustomEvent';
|
|
19
|
+
import { subscribeToPageUnload } from '../../common/window/page-visibility';
|
|
20
|
+
import { findScriptTimings } from '../../common/util/script-tracker';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* @typedef {import('./register-api-types').RegisterAPI} RegisterAPI
|
|
@@ -50,6 +52,7 @@ function register(agentRef, target, parent) {
|
|
|
50
52
|
target.blocked = false;
|
|
51
53
|
target.parent = parent || {};
|
|
52
54
|
if (typeof target.tags !== 'object' || target.tags === null || Array.isArray(target.tags)) target.tags = {};
|
|
55
|
+
const timings = findScriptTimings();
|
|
53
56
|
const attrs = {};
|
|
54
57
|
|
|
55
58
|
// Process tags object and add to attrs, excluding protected keys
|
|
@@ -100,6 +103,7 @@ function register(agentRef, target, parent) {
|
|
|
100
103
|
}, agentRef], target),
|
|
101
104
|
deregister: () => {
|
|
102
105
|
/** note: blocking this instance will disable access for all entities sharing the instance, and will invalidate it from the v2 checks */
|
|
106
|
+
reportTimings();
|
|
103
107
|
block(single(() => warn(68)));
|
|
104
108
|
},
|
|
105
109
|
log: (message, options = {}) => report(log, [message, {
|
|
@@ -131,7 +135,8 @@ function register(agentRef, target, parent) {
|
|
|
131
135
|
/** metadata */
|
|
132
136
|
metadata: {
|
|
133
137
|
customAttributes: attrs,
|
|
134
|
-
target
|
|
138
|
+
target,
|
|
139
|
+
timings
|
|
135
140
|
}
|
|
136
141
|
};
|
|
137
142
|
|
|
@@ -145,7 +150,36 @@ function register(agentRef, target, parent) {
|
|
|
145
150
|
};
|
|
146
151
|
|
|
147
152
|
/** only allow registered APIs to be tracked in the agent runtime */
|
|
148
|
-
if (!isBlocked())
|
|
153
|
+
if (!isBlocked()) {
|
|
154
|
+
registeredEntities.push(api);
|
|
155
|
+
subscribeToPageUnload(reportTimings);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Reports the gathered timings for the registered entity through a custom event to the container agent. Only reports once
|
|
160
|
+
* by checking for the presence of the reportedAt timing.
|
|
161
|
+
* @returns {void}
|
|
162
|
+
*/
|
|
163
|
+
function reportTimings() {
|
|
164
|
+
// only ever report the timings the first time this is called
|
|
165
|
+
if (timings.reportedAt) return;
|
|
166
|
+
timings.reportedAt = now();
|
|
167
|
+
api.recordCustomEvent('MicroFrontEndTiming', {
|
|
168
|
+
assetUrl: timings.asset,
|
|
169
|
+
// the url of the script that was registered, or undefined if it could not be determined (inline or no match)
|
|
170
|
+
assetType: timings.type,
|
|
171
|
+
// the type of asset that was associated with the timings, one of 'script', 'link' (if preloaded and found in the resource timing buffer), 'preload' (if preloaded but not found in the resource timing buffer), or "unknown" if it could not be determined
|
|
172
|
+
timeToLoad: timings.registeredAt - timings.fetchStart,
|
|
173
|
+
// fetchStart to registeredAt
|
|
174
|
+
timeToBeRequested: timings.fetchStart,
|
|
175
|
+
// origin to fetchStart
|
|
176
|
+
timeToFetch: timings.fetchEnd - timings.fetchStart,
|
|
177
|
+
// fetchStart to fetchEnd
|
|
178
|
+
timeToRegister: timings.registeredAt - timings.fetchEnd,
|
|
179
|
+
// fetchEnd to registeredAt
|
|
180
|
+
timeAlive: timings.reportedAt - timings.registeredAt // registeredAt to reportedAt
|
|
181
|
+
});
|
|
182
|
+
}
|
|
149
183
|
|
|
150
184
|
/**
|
|
151
185
|
* Sets a value local to the registered API attrs. Will do nothing if APIs are deregistered.
|
|
@@ -219,7 +219,7 @@ export class ApiBase {
|
|
|
219
219
|
* Measures a task that is recorded as a BrowserPerformance event.
|
|
220
220
|
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
|
|
221
221
|
* @param {string} name The name of the task
|
|
222
|
-
* @param {{start
|
|
222
|
+
* @param {{start?: number|PerformanceMark, end?: number|PerformanceMark, customAttributes?: object}} [options] An object used to control the way the measure API operates
|
|
223
223
|
* @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
|
|
224
224
|
*/
|
|
225
225
|
measure(name, options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -23,8 +23,7 @@ export const FEATURE_NAMES = {
|
|
|
23
23
|
pageViewTiming: 'page_view_timing',
|
|
24
24
|
sessionReplay: 'session_replay',
|
|
25
25
|
sessionTrace: 'session_trace',
|
|
26
|
-
softNav: 'soft_navigations'
|
|
27
|
-
spa: 'spa'
|
|
26
|
+
softNav: 'soft_navigations'
|
|
28
27
|
};
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -36,19 +35,17 @@ export const featurePriority = {
|
|
|
36
35
|
[FEATURE_NAMES.pageViewTiming]: 2,
|
|
37
36
|
[FEATURE_NAMES.metrics]: 3,
|
|
38
37
|
[FEATURE_NAMES.jserrors]: 4,
|
|
39
|
-
[FEATURE_NAMES.
|
|
38
|
+
[FEATURE_NAMES.softNav]: 5,
|
|
40
39
|
[FEATURE_NAMES.ajax]: 6,
|
|
41
40
|
[FEATURE_NAMES.sessionTrace]: 7,
|
|
42
|
-
[FEATURE_NAMES.
|
|
43
|
-
[FEATURE_NAMES.
|
|
44
|
-
[FEATURE_NAMES.
|
|
45
|
-
[FEATURE_NAMES.genericEvents]: 11
|
|
41
|
+
[FEATURE_NAMES.sessionReplay]: 8,
|
|
42
|
+
[FEATURE_NAMES.logging]: 9,
|
|
43
|
+
[FEATURE_NAMES.genericEvents]: 10
|
|
46
44
|
};
|
|
47
45
|
export const FEATURE_TO_ENDPOINT = {
|
|
48
46
|
[FEATURE_NAMES.pageViewEvent]: RUM,
|
|
49
47
|
[FEATURE_NAMES.pageViewTiming]: EVENTS,
|
|
50
48
|
[FEATURE_NAMES.ajax]: EVENTS,
|
|
51
|
-
[FEATURE_NAMES.spa]: EVENTS,
|
|
52
49
|
[FEATURE_NAMES.softNav]: EVENTS,
|
|
53
50
|
[FEATURE_NAMES.metrics]: JSERRORS,
|
|
54
51
|
[FEATURE_NAMES.jserrors]: JSERRORS,
|