@newrelic/browser-agent 0.1.231 → 1.232.1
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/README.md +2 -2
- package/dist/cjs/common/config/state/configurable.js +27 -21
- package/dist/cjs/common/config/state/init.js +8 -0
- package/dist/cjs/common/config/state/runtime.js +24 -26
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/context/shared-context.js +2 -1
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +2 -2
- package/dist/cjs/common/event-emitter/register-handler.test.js +1 -1
- package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
- package/dist/cjs/common/harvest/harvest-scheduler.js +14 -11
- package/dist/cjs/common/harvest/harvest.js +3 -1
- package/dist/cjs/common/session/constants.js +12 -0
- package/dist/cjs/common/session/session-entity.js +278 -0
- package/dist/cjs/common/session/session-entity.test.js +436 -0
- package/dist/cjs/common/storage/first-party-cookies.js +35 -0
- package/dist/cjs/common/storage/local-memory.js +35 -0
- package/dist/cjs/common/storage/local-memory.test.js +20 -0
- package/dist/cjs/common/storage/local-storage.js +33 -0
- package/dist/cjs/common/storage/local-storage.test.js +14 -0
- package/dist/cjs/common/timer/interaction-timer.js +78 -0
- package/dist/cjs/common/timer/interaction-timer.test.js +216 -0
- package/dist/cjs/common/timer/timer.js +32 -0
- package/dist/cjs/common/timer/timer.test.js +105 -0
- package/dist/cjs/common/unload/eol.js +2 -2
- package/dist/cjs/common/url/canonicalize-url.js +32 -0
- package/dist/cjs/common/url/canonicalize-url.test.js +42 -0
- package/dist/cjs/common/url/clean-url.js +10 -3
- package/dist/cjs/common/util/data-size.js +6 -0
- package/dist/cjs/common/util/data-size.test.js +47 -0
- package/dist/cjs/common/util/global-scope.js +4 -2
- package/dist/cjs/common/util/invoke.js +73 -0
- package/dist/cjs/common/util/invoke.test.js +49 -0
- package/dist/cjs/common/util/obfuscate.js +0 -4
- package/dist/cjs/common/window/page-visibility.js +3 -1
- package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
- package/dist/cjs/common/wrap/wrap-function.js +1 -3
- package/dist/cjs/common/wrap/wrap-timer.js +1 -1
- package/dist/cjs/features/ajax/aggregate/index.js +2 -2
- package/dist/cjs/features/ajax/instrument/index.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +12 -4
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +93 -10
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +164 -38
- package/dist/cjs/features/jserrors/aggregate/index.js +25 -46
- package/dist/cjs/features/jserrors/instrument/index.js +0 -2
- package/dist/cjs/features/metrics/aggregate/index.js +13 -2
- package/dist/cjs/features/page_action/aggregate/index.js +2 -2
- package/dist/cjs/features/page_view_event/aggregate/index.js +6 -3
- package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -6
- package/dist/cjs/features/session_trace/aggregate/index.js +3 -5
- package/dist/cjs/features/spa/aggregate/index.js +6 -5
- package/dist/cjs/features/utils/agent-session.js +73 -0
- package/dist/cjs/features/utils/feature-base.js +1 -1
- package/dist/cjs/features/utils/instrument-base.js +7 -2
- package/dist/cjs/features/utils/lazy-loader.js +1 -1
- package/dist/cjs/loaders/agent.js +1 -1
- package/dist/cjs/loaders/api/api.js +1 -4
- package/dist/cjs/loaders/api/apiAsync.js +3 -2
- package/dist/cjs/loaders/configure/configure.js +0 -6
- package/dist/esm/common/config/state/configurable.js +26 -20
- package/dist/esm/common/config/state/init.js +8 -0
- package/dist/esm/common/config/state/runtime.js +24 -26
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/context/shared-context.js +2 -1
- package/dist/esm/common/event-emitter/contextual-ee.test.js +2 -2
- package/dist/esm/common/event-emitter/register-handler.test.js +1 -1
- package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
- package/dist/esm/common/harvest/harvest-scheduler.js +14 -11
- package/dist/esm/common/harvest/harvest.js +3 -1
- package/dist/esm/common/session/constants.js +3 -0
- package/dist/esm/common/session/session-entity.js +271 -0
- package/dist/esm/common/session/session-entity.test.js +434 -0
- package/dist/esm/common/storage/first-party-cookies.js +28 -0
- package/dist/esm/common/storage/local-memory.js +28 -0
- package/dist/esm/common/storage/local-memory.test.js +18 -0
- package/dist/esm/common/storage/local-storage.js +26 -0
- package/dist/esm/common/storage/local-storage.test.js +12 -0
- package/dist/esm/common/timer/interaction-timer.js +71 -0
- package/dist/esm/common/timer/interaction-timer.test.js +214 -0
- package/dist/esm/common/timer/timer.js +25 -0
- package/dist/esm/common/timer/timer.test.js +103 -0
- package/dist/esm/common/unload/eol.js +1 -1
- package/dist/esm/common/url/canonicalize-url.js +27 -0
- package/dist/esm/common/url/canonicalize-url.test.js +38 -0
- package/dist/esm/common/url/clean-url.js +10 -3
- package/dist/esm/common/util/data-size.js +7 -0
- package/dist/esm/common/util/data-size.test.js +45 -0
- package/dist/esm/common/util/global-scope.js +1 -0
- package/dist/esm/common/util/invoke.js +66 -0
- package/dist/esm/common/util/invoke.test.js +47 -0
- package/dist/esm/common/util/obfuscate.js +0 -4
- package/dist/esm/common/window/page-visibility.js +3 -1
- package/dist/esm/common/wrap/wrap-fetch.js +1 -2
- package/dist/esm/common/wrap/wrap-function.js +1 -2
- package/dist/esm/common/wrap/wrap-timer.js +1 -1
- package/dist/esm/features/ajax/aggregate/index.js +2 -2
- package/dist/esm/features/ajax/instrument/index.js +1 -1
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +12 -4
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +93 -10
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +149 -25
- package/dist/esm/features/jserrors/aggregate/index.js +26 -46
- package/dist/esm/features/jserrors/instrument/index.js +0 -1
- package/dist/esm/features/metrics/aggregate/index.js +14 -3
- package/dist/esm/features/page_action/aggregate/index.js +2 -2
- package/dist/esm/features/page_view_event/aggregate/index.js +6 -3
- package/dist/esm/features/page_view_timing/aggregate/index.js +6 -6
- package/dist/esm/features/session_trace/aggregate/index.js +3 -4
- package/dist/esm/features/spa/aggregate/index.js +6 -5
- package/dist/esm/features/utils/agent-session.js +67 -0
- package/dist/esm/features/utils/feature-base.js +1 -1
- package/dist/esm/features/utils/instrument-base.js +7 -2
- package/dist/esm/features/utils/lazy-loader.js +1 -1
- package/dist/esm/loaders/agent.js +1 -1
- package/dist/esm/loaders/api/api.js +2 -5
- package/dist/esm/loaders/api/apiAsync.js +2 -1
- package/dist/esm/loaders/configure/configure.js +2 -8
- package/dist/types/common/config/state/configurable.d.ts.map +1 -1
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/config/state/runtime.d.ts.map +1 -1
- package/dist/types/common/context/shared-context.d.ts.map +1 -1
- package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
- package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/session/constants.d.ts +4 -0
- package/dist/types/common/session/constants.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +72 -0
- package/dist/types/common/session/session-entity.d.ts.map +1 -0
- package/dist/types/common/storage/first-party-cookies.d.ts +8 -0
- package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -0
- package/dist/types/common/storage/local-memory.d.ts +8 -0
- package/dist/types/common/storage/local-memory.d.ts.map +1 -0
- package/dist/types/common/storage/local-storage.d.ts +6 -0
- package/dist/types/common/storage/local-storage.d.ts.map +1 -0
- package/dist/types/common/timer/interaction-timer.d.ts +11 -0
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -0
- package/dist/types/common/timer/timer.d.ts +12 -0
- package/dist/types/common/timer/timer.d.ts.map +1 -0
- package/dist/types/common/url/canonicalize-url.d.ts +9 -0
- package/dist/types/common/url/canonicalize-url.d.ts.map +1 -0
- package/dist/types/common/url/clean-url.d.ts +7 -1
- package/dist/types/common/url/clean-url.d.ts.map +1 -1
- package/dist/types/common/util/data-size.d.ts +7 -1
- package/dist/types/common/util/data-size.d.ts.map +1 -1
- package/dist/types/common/util/global-scope.d.ts +1 -0
- package/dist/types/common/util/global-scope.d.ts.map +1 -1
- package/dist/types/common/util/invoke.d.ts +35 -0
- package/dist/types/common/util/invoke.d.ts.map +1 -0
- package/dist/types/common/util/obfuscate.d.ts.map +1 -1
- package/dist/types/common/window/page-visibility.d.ts +1 -1
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +8 -1
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +48 -19
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +14 -5
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts +3 -3
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +2 -2
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts +2 -2
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts +2 -0
- package/dist/types/features/utils/agent-session.d.ts.map +1 -0
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/features/utils/lazy-loader.d.ts +2 -2
- package/dist/types/features/utils/lazy-loader.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts.map +1 -1
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/common/config/state/configurable.js +26 -19
- package/src/common/config/state/init.js +7 -0
- package/src/common/config/state/runtime.js +22 -27
- package/src/common/context/shared-context.js +2 -1
- package/src/common/event-emitter/contextual-ee.test.js +2 -2
- package/src/common/event-emitter/register-handler.test.js +1 -1
- package/src/common/event-listener/event-listener-opts.js +4 -4
- package/src/common/harvest/harvest-scheduler.js +12 -8
- package/src/common/harvest/harvest.js +3 -1
- package/src/common/session/constants.js +3 -0
- package/src/common/session/session-entity.js +271 -0
- package/src/common/session/session-entity.test.js +317 -0
- package/src/common/storage/first-party-cookies.js +31 -0
- package/src/common/storage/local-memory.js +30 -0
- package/src/common/storage/local-memory.test.js +19 -0
- package/src/common/storage/local-storage.js +28 -0
- package/src/common/storage/local-storage.test.js +17 -0
- package/src/common/timer/interaction-timer.js +75 -0
- package/src/common/timer/interaction-timer.test.js +167 -0
- package/src/common/timer/timer.js +31 -0
- package/src/common/timer/timer.test.js +100 -0
- package/src/common/unload/eol.js +1 -1
- package/src/common/url/canonicalize-url.js +28 -0
- package/src/common/url/canonicalize-url.test.js +34 -0
- package/src/common/url/clean-url.js +10 -3
- package/src/common/util/data-size.js +6 -0
- package/src/common/util/data-size.test.js +50 -0
- package/src/common/util/global-scope.js +2 -0
- package/src/common/util/invoke.js +55 -0
- package/src/common/util/invoke.test.js +65 -0
- package/src/common/util/obfuscate.js +0 -4
- package/src/common/window/page-visibility.js +2 -2
- package/src/common/wrap/wrap-fetch.js +1 -2
- package/src/common/wrap/wrap-function.js +1 -2
- package/src/common/wrap/wrap-timer.js +1 -1
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/ajax/instrument/index.js +1 -1
- package/src/features/jserrors/aggregate/canonical-function-name.js +12 -4
- package/src/features/jserrors/aggregate/compute-stack-trace.js +85 -11
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +141 -24
- package/src/features/jserrors/aggregate/index.js +24 -50
- package/src/features/jserrors/instrument/index.js +0 -1
- package/src/features/metrics/aggregate/index.js +18 -3
- package/src/features/page_action/aggregate/index.js +2 -2
- package/src/features/page_view_event/aggregate/index.js +6 -3
- package/src/features/page_view_timing/aggregate/index.js +6 -6
- package/src/features/session_trace/aggregate/index.js +3 -4
- package/src/features/spa/aggregate/index.js +5 -5
- package/src/features/utils/agent-session.js +68 -0
- package/src/features/utils/feature-base.js +1 -1
- package/src/features/utils/instrument-base.js +5 -2
- package/src/features/utils/lazy-loader.js +1 -1
- package/src/loaders/agent.js +1 -1
- package/src/loaders/api/api.js +2 -5
- package/src/loaders/api/apiAsync.js +2 -1
- package/src/loaders/configure/configure.js +2 -7
- package/dist/cjs/common/util/single.js +0 -23
- package/dist/cjs/common/window/session-storage.js +0 -87
- package/dist/cjs/features/utils/aggregate-base.js +0 -13
- package/dist/esm/common/util/single.js +0 -16
- package/dist/esm/common/window/session-storage.js +0 -77
- package/dist/esm/features/utils/aggregate-base.js +0 -6
- package/dist/types/common/util/single.d.ts +0 -2
- package/dist/types/common/util/single.d.ts.map +0 -1
- package/dist/types/common/window/session-storage.d.ts +0 -18
- package/dist/types/common/window/session-storage.d.ts.map +0 -1
- package/dist/types/features/utils/aggregate-base.d.ts +0 -4
- package/dist/types/features/utils/aggregate-base.d.ts.map +0 -1
- package/src/common/util/single.js +0 -18
- package/src/common/window/session-storage.js +0 -75
- package/src/features/utils/aggregate-base.js +0 -7
|
@@ -15,10 +15,6 @@ var fileProtocolRule = {
|
|
|
15
15
|
replacement: 'file://OBFUSCATED'
|
|
16
16
|
};
|
|
17
17
|
class Obfuscator extends _sharedContext.SharedContext {
|
|
18
|
-
constructor(parent) {
|
|
19
|
-
super(parent); // gets any allowed properties from the parent and stores them in `sharedContext`
|
|
20
|
-
}
|
|
21
|
-
|
|
22
18
|
shouldObfuscate() {
|
|
23
19
|
return getRules(this.sharedContext.agentIdentifier).length > 0;
|
|
24
20
|
}
|
|
@@ -17,7 +17,9 @@ var _eventListenerOpts = require("../event-listener/event-listener-opts");
|
|
|
17
17
|
*/
|
|
18
18
|
function subscribeToVisibilityChange(cb) {
|
|
19
19
|
let toHiddenOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
20
|
-
|
|
20
|
+
let capture = arguments.length > 2 ? arguments[2] : undefined;
|
|
21
|
+
let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
|
|
22
|
+
(0, _eventListenerOpts.documentAddEventListener)('visibilitychange', handleVisibilityChange, capture, abortSignal);
|
|
21
23
|
return;
|
|
22
24
|
function handleVisibilityChange() {
|
|
23
25
|
if (toHiddenOnly) {
|
|
@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.scopedEE = scopedEE;
|
|
7
7
|
exports.wrapFetch = wrapFetch;
|
|
8
8
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
9
|
-
var _lodash = _interopRequireDefault(require("lodash._slice"));
|
|
10
9
|
var _globalScope = require("../util/global-scope");
|
|
11
10
|
var _wrapFunction = require("./wrap-function");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
11
|
/*
|
|
14
12
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
15
13
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -77,7 +75,7 @@ function wrapFetch(sharedEE) {
|
|
|
77
75
|
var fn = target[name];
|
|
78
76
|
if (typeof fn === 'function') {
|
|
79
77
|
target[name] = function () {
|
|
80
|
-
var args =
|
|
78
|
+
var args = Array.from(arguments);
|
|
81
79
|
var ctx = {};
|
|
82
80
|
// we are wrapping args in an array so we can preserve the reference
|
|
83
81
|
ee.emit(prefix + 'before-start', [args], ctx);
|
|
@@ -8,8 +8,6 @@ exports.flag = exports.default = void 0;
|
|
|
8
8
|
exports.wrapFunction = wrapFunction;
|
|
9
9
|
exports.wrapInPlace = wrapInPlace;
|
|
10
10
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
11
|
-
var _lodash = _interopRequireDefault(require("lodash._slice"));
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
11
|
/*
|
|
14
12
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
15
13
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -83,7 +81,7 @@ function createWrapperWithEmitter(emitter, always) {
|
|
|
83
81
|
var result;
|
|
84
82
|
try {
|
|
85
83
|
originalThis = this;
|
|
86
|
-
args =
|
|
84
|
+
args = Array.from(arguments);
|
|
87
85
|
if (typeof getContext === 'function') {
|
|
88
86
|
ctx = getContext(args, originalThis);
|
|
89
87
|
} else {
|
|
@@ -32,7 +32,7 @@ const TIMER_FNS = [SET_TIMEOUT, 'setImmediate', SET_INTERVAL, CLEAR_TIMEOUT, 'cl
|
|
|
32
32
|
* @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
|
|
33
33
|
* @returns {Object} Scoped event emitter with a debug ID of `timer`.
|
|
34
34
|
*/
|
|
35
|
-
//eslint-disable-next-line
|
|
35
|
+
// eslint-disable-next-line
|
|
36
36
|
function wrapTimer(sharedEE) {
|
|
37
37
|
const ee = scopedEE(sharedEE);
|
|
38
38
|
|
|
@@ -11,17 +11,17 @@ var _handle = require("../../../common/event-emitter/handle");
|
|
|
11
11
|
var _config = require("../../../common/config/config");
|
|
12
12
|
var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
|
|
13
13
|
var _denyList = require("../../../common/deny-list/deny-list");
|
|
14
|
-
var _aggregateBase = require("../../utils/aggregate-base");
|
|
15
14
|
var _constants = require("../constants");
|
|
16
15
|
var _drain = require("../../../common/drain/drain");
|
|
17
16
|
var _features = require("../../../loaders/features/features");
|
|
18
17
|
var _constants2 = require("../../metrics/constants");
|
|
18
|
+
var _featureBase = require("../../utils/feature-base");
|
|
19
19
|
/*
|
|
20
20
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
21
21
|
* SPDX-License-Identifier: Apache-2.0
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
class Aggregate extends
|
|
24
|
+
class Aggregate extends _featureBase.FeatureBase {
|
|
25
25
|
static featureName = _constants.FEATURE_NAME;
|
|
26
26
|
constructor(agentIdentifier, aggregator) {
|
|
27
27
|
super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
|
|
@@ -99,7 +99,7 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
99
99
|
}
|
|
100
100
|
function onOpenXhrEnd(args, xhr) {
|
|
101
101
|
var loader_config = (0, _config.getLoaderConfig)(agentIdentifier);
|
|
102
|
-
if (
|
|
102
|
+
if (loader_config.xpid && this.sameOrigin) {
|
|
103
103
|
xhr.setRequestHeader('X-NewRelic-ID', loader_config.xpid);
|
|
104
104
|
}
|
|
105
105
|
var payload = dt.generateTracePayload(this.parsedOrigin);
|
|
@@ -9,10 +9,18 @@ exports.canonicalFunctionName = canonicalFunctionName;
|
|
|
9
9
|
* SPDX-License-Identifier: Apache-2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const canonicalFunctionNameRe = /([a-z0-9]+)$/i;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Given a function name string, extracts only an alphanumeric segment at the end of the string (if one exists).
|
|
16
|
+
* This is useful for stack traces, where functions might not be named (e.g., anonymous, computed).
|
|
17
|
+
*
|
|
18
|
+
* @param {string} functionNameString - The original function name string.
|
|
19
|
+
* @returns {string|undefined} The canonical function name, or undefined if the input is falsy or no alphanumeric segments are found.
|
|
20
|
+
*/
|
|
21
|
+
function canonicalFunctionName(functionNameString) {
|
|
22
|
+
if (!functionNameString) return;
|
|
23
|
+
const match = functionNameString.match(canonicalFunctionNameRe);
|
|
16
24
|
if (match) return match[1];
|
|
17
25
|
return;
|
|
18
26
|
}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.computeStackTrace = computeStackTrace;
|
|
7
7
|
var _formatStackTrace = require("./format-stack-trace");
|
|
8
|
+
var _canonicalizeUrl = require("../../../common/url/canonicalize-url");
|
|
8
9
|
/*
|
|
9
10
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
10
11
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -70,6 +71,24 @@ var chrome = /^\s*at (?:((?:\[object object\])?(?:[^(]*\([^)]*\))*[^()]*(?: \[as
|
|
|
70
71
|
var gecko = /^\s*(?:(\S*|global code)(?:\(.*?\))?@)?((?:file|http|https|chrome|safari-extension).*?):(\d+)(?::(\d+))?\s*$/i;
|
|
71
72
|
var chrome_eval = /^\s*at .+ \(eval at \S+ \((?:(?:file|http|https):[^)]+)?\)(?:, [^:]*:\d+:\d+)?\)$/i;
|
|
72
73
|
var ie_eval = /^\s*at Function code \(Function code:\d+:\d+\)\s*/i;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Represents an error with a stack trace.
|
|
77
|
+
* @typedef {Object} StackInfo
|
|
78
|
+
* @property {string} name - The name of the error (e.g. 'TypeError').
|
|
79
|
+
* @property {string} message - The error message.
|
|
80
|
+
* @property {string} stackString - The stack trace as a string.
|
|
81
|
+
* @property {Array<Object>} frames - An array of frames in the stack trace.
|
|
82
|
+
* @property {string} frames.url - The URL of the file containing the code for the frame.
|
|
83
|
+
* @property {string} frames.func - The name of the function associated with the frame.
|
|
84
|
+
* @property {number} frames.line - The line number of the code in the frame.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Attempts to compute a stack trace for the given exception.
|
|
89
|
+
* @param {Error} ex - The exception for which to compute the stack trace.
|
|
90
|
+
* @returns {StackInfo} A stack trace object containing information about the frames on the stack.
|
|
91
|
+
*/
|
|
73
92
|
function computeStackTrace(ex) {
|
|
74
93
|
var stack = null;
|
|
75
94
|
try {
|
|
@@ -110,9 +129,9 @@ function computeStackTrace(ex) {
|
|
|
110
129
|
}
|
|
111
130
|
|
|
112
131
|
/**
|
|
113
|
-
* Computes stack trace information from the stack property.
|
|
114
|
-
*
|
|
115
|
-
* @param {Error} ex
|
|
132
|
+
* Computes stack trace information from the stack property. Chrome and Gecko use this property.
|
|
133
|
+
*
|
|
134
|
+
* @param {Error} ex - The error object to compute the stack trace for.
|
|
116
135
|
* @return {?Object.<string, *>} Stack trace information.
|
|
117
136
|
*/
|
|
118
137
|
function computeStackTraceFromStackProp(ex) {
|
|
@@ -133,17 +152,48 @@ function computeStackTraceFromStackProp(ex) {
|
|
|
133
152
|
frames: errorInfo.frames
|
|
134
153
|
};
|
|
135
154
|
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Parses a line from a JavaScript error stack trace and adds it to the given `info` object.
|
|
158
|
+
* Ignores all stack entries thrown from one of our wrapper functions.
|
|
159
|
+
*
|
|
160
|
+
* @param {object} info - The `info` object to add the parsed line to.
|
|
161
|
+
* @param {string} line - The line to parse.
|
|
162
|
+
* @returns {object} The `info` object with the parsed line added.
|
|
163
|
+
*/
|
|
136
164
|
function parseStackProp(info, line) {
|
|
137
|
-
|
|
165
|
+
let element = getStackElement(line);
|
|
166
|
+
|
|
167
|
+
// This catches lines that aren't frames (like the first line stating the error).
|
|
138
168
|
if (!element) {
|
|
139
169
|
info.stackLines.push(line);
|
|
140
170
|
return info;
|
|
141
171
|
}
|
|
142
|
-
|
|
143
|
-
|
|
172
|
+
|
|
173
|
+
// Once we've seen a wrapper, ignore all subsequent stack entries.
|
|
174
|
+
if (isNrWrapper(element.func)) info.wrapperSeen = true;
|
|
175
|
+
if (!info.wrapperSeen) {
|
|
176
|
+
// Query strings and fragments should be removed, and URLs matching the loader's origin should be "<inline>".
|
|
177
|
+
let canonicalUrl = (0, _canonicalizeUrl.canonicalizeUrl)(element.url);
|
|
178
|
+
if (canonicalUrl !== element.url) {
|
|
179
|
+
line = line.replace(element.url, canonicalUrl);
|
|
180
|
+
element.url = canonicalUrl;
|
|
181
|
+
}
|
|
182
|
+
info.stackLines.push(line);
|
|
183
|
+
info.frames.push(element);
|
|
184
|
+
}
|
|
144
185
|
return info;
|
|
145
186
|
}
|
|
146
|
-
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Parses a line from a JavaScript error stack trace to extract information about a stack trace element, such as the
|
|
190
|
+
* URL, function name, line number, and column number.
|
|
191
|
+
*
|
|
192
|
+
* @param {string} line - A single line from a JavaScript error stack trace.
|
|
193
|
+
* @returns {object} An object containing information about the stack trace element, including the URL, function
|
|
194
|
+
* name, line number, and column number (if available).
|
|
195
|
+
*/
|
|
196
|
+
function getStackElement(line) {
|
|
147
197
|
var parts = line.match(gecko);
|
|
148
198
|
if (!parts) parts = line.match(chrome);
|
|
149
199
|
if (parts) {
|
|
@@ -160,6 +210,15 @@ function getElement(line) {
|
|
|
160
210
|
};
|
|
161
211
|
}
|
|
162
212
|
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Computes a stack trace object from an error object, by extracting the source and line number from the error object,
|
|
216
|
+
* and using them to create a single stack frame.
|
|
217
|
+
*
|
|
218
|
+
* @param {Error} ex - The error object to compute the stack trace for.
|
|
219
|
+
* @returns {Object|null} - An object representing the computed stack trace, or null if the
|
|
220
|
+
* input error object does not contain a line number.
|
|
221
|
+
*/
|
|
163
222
|
function computeStackTraceBySourceAndLine(ex) {
|
|
164
223
|
if (!('line' in ex)) return null;
|
|
165
224
|
var className = ex.name || getClassName(ex);
|
|
@@ -176,7 +235,10 @@ function computeStackTraceBySourceAndLine(ex) {
|
|
|
176
235
|
}]
|
|
177
236
|
};
|
|
178
237
|
}
|
|
179
|
-
|
|
238
|
+
|
|
239
|
+
// Remove any query string and fragment
|
|
240
|
+
var canonicalUrl = (0, _canonicalizeUrl.canonicalizeUrl)(ex.sourceURL);
|
|
241
|
+
var stackString = className + ': ' + ex.message + '\n at ' + canonicalUrl;
|
|
180
242
|
if (ex.line) {
|
|
181
243
|
stackString += ':' + ex.line;
|
|
182
244
|
if (ex.column) {
|
|
@@ -189,12 +251,19 @@ function computeStackTraceBySourceAndLine(ex) {
|
|
|
189
251
|
message: ex.message,
|
|
190
252
|
stackString: stackString,
|
|
191
253
|
frames: [{
|
|
192
|
-
url:
|
|
254
|
+
url: canonicalUrl,
|
|
193
255
|
line: ex.line,
|
|
194
256
|
column: ex.column
|
|
195
257
|
}]
|
|
196
258
|
};
|
|
197
259
|
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* For exceptions with no stack and only a message, derives a stack trace by extracting the class name and message.
|
|
263
|
+
*
|
|
264
|
+
* @param {Error} ex - The exception for which to compute the stack trace.
|
|
265
|
+
* @returns {StackTrace} A stack trace object containing the name and message of the exception.
|
|
266
|
+
*/
|
|
198
267
|
function computeStackTraceWithMessageOnly(ex) {
|
|
199
268
|
var className = ex.name || getClassName(ex);
|
|
200
269
|
if (!className) return null;
|
|
@@ -206,10 +275,24 @@ function computeStackTraceWithMessageOnly(ex) {
|
|
|
206
275
|
frames: []
|
|
207
276
|
};
|
|
208
277
|
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Attempts to extract the name of the constructor function (the class) of the given object.
|
|
281
|
+
*
|
|
282
|
+
* @param {Object} obj - The object for which to extract the constructor function name.
|
|
283
|
+
* @returns {string} The name of the constructor function, or 'unknown' if the name cannot be determined.
|
|
284
|
+
*/
|
|
209
285
|
function getClassName(obj) {
|
|
210
286
|
var results = classNameRegex.exec(String(obj.constructor));
|
|
211
287
|
return results && results.length > 1 ? results[1] : 'unknown';
|
|
212
288
|
}
|
|
213
|
-
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Checks whether the given function name is a New Relic wrapper function.
|
|
292
|
+
*
|
|
293
|
+
* @param {string} functionName - The name of the function to check.
|
|
294
|
+
* @returns {boolean} True if the function name includes the string 'nrWrapper', false otherwise.
|
|
295
|
+
*/
|
|
296
|
+
function isNrWrapper(functionName) {
|
|
214
297
|
return functionName && functionName.indexOf('nrWrapper') >= 0;
|
|
215
298
|
}
|
|
@@ -2,16 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
var _faker = require("@faker-js/faker");
|
|
4
4
|
var _testingUtils = require("../../../../tools/testing-utils");
|
|
5
|
-
|
|
5
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
6
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
7
|
+
const globalScopeLocation = 'https://example.com/';
|
|
8
|
+
const mockGlobalScopeLocation = url => {
|
|
9
|
+
jest.doMock('../../../common/util/global-scope', () => ({
|
|
10
|
+
initialLocation: url || globalScopeLocation
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
jest.resetModules();
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
});
|
|
6
17
|
const baseMockError = {
|
|
7
18
|
toString: 'RangeError: Invalid array length',
|
|
8
19
|
name: 'RangeError',
|
|
9
20
|
constructor: 'function RangeError() { [native code] }',
|
|
10
21
|
message: 'Invalid array length',
|
|
11
|
-
stack: 'RangeError: Invalid array length\n at errorTest (
|
|
22
|
+
stack: 'RangeError: Invalid array length\n' + ' at errorTest (' + globalScopeLocation + '?loader=spa#hello:74:16)\n' + ' at captureError (' + globalScopeLocation + 'js/script.js?loader=spa:17:9)\n' + ' at onload (' + globalScopeLocation + 'js/script.js?loader=spa:70:5)'
|
|
12
23
|
};
|
|
13
|
-
test('parsing should return a failure for a null error object', () => {
|
|
14
|
-
|
|
24
|
+
test('parsing should return a failure for a null error object', async () => {
|
|
25
|
+
mockGlobalScopeLocation();
|
|
26
|
+
const {
|
|
27
|
+
computeStackTrace
|
|
28
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
29
|
+
const result = computeStackTrace(null);
|
|
15
30
|
expect(result).toEqual(expect.objectContaining({
|
|
16
31
|
mode: 'failed',
|
|
17
32
|
stackString: '',
|
|
@@ -19,25 +34,46 @@ test('parsing should return a failure for a null error object', () => {
|
|
|
19
34
|
}));
|
|
20
35
|
});
|
|
21
36
|
describe('errors with stack property', () => {
|
|
22
|
-
test('
|
|
37
|
+
test('should show <inline> for same-page stack string URLs but not sub-paths', async () => {
|
|
38
|
+
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
39
|
+
...baseMockError
|
|
40
|
+
});
|
|
41
|
+
mockGlobalScopeLocation();
|
|
42
|
+
const {
|
|
43
|
+
computeStackTrace
|
|
44
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
45
|
+
const result = computeStackTrace(mockError);
|
|
46
|
+
expect(result).toEqual(expect.objectContaining({
|
|
47
|
+
stackString:
|
|
48
|
+
// canonicalized
|
|
49
|
+
'RangeError: Invalid array length\n' + ' at errorTest (<inline>:74:16)\n' + ' at captureError (' + globalScopeLocation + 'js/script.js:17:9)\n' + ' at onload (' + globalScopeLocation + 'js/script.js:70:5)'
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
test('parsed name should be unknown when name and constructor are missing', async () => {
|
|
23
53
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
24
54
|
...baseMockError,
|
|
25
55
|
name: null,
|
|
26
56
|
constructor: null
|
|
27
57
|
});
|
|
28
|
-
|
|
58
|
+
mockGlobalScopeLocation();
|
|
59
|
+
const {
|
|
60
|
+
computeStackTrace
|
|
61
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
62
|
+
const result = computeStackTrace(mockError);
|
|
29
63
|
expect(result).toEqual(expect.objectContaining({
|
|
30
64
|
mode: 'stack',
|
|
31
|
-
name: 'unknown'
|
|
32
|
-
message: mockError.message,
|
|
33
|
-
stackString: mockError.stack
|
|
65
|
+
name: 'unknown'
|
|
34
66
|
}));
|
|
35
67
|
});
|
|
36
|
-
test('parsed stack should not contain nrWrapper', () => {
|
|
68
|
+
test('parsed stack should not contain nrWrapper', async () => {
|
|
37
69
|
const alteredError = baseMockError;
|
|
38
|
-
alteredError.stack += '\n at nrWrapper (
|
|
70
|
+
alteredError.stack += '\n at nrWrapper (' + globalScopeLocation + '?loader=spa:60:17)';
|
|
39
71
|
const mockError = _testingUtils.browserErrorUtils.constructError(alteredError);
|
|
40
|
-
|
|
72
|
+
mockGlobalScopeLocation();
|
|
73
|
+
const {
|
|
74
|
+
computeStackTrace
|
|
75
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
76
|
+
const result = computeStackTrace(mockError);
|
|
41
77
|
expect(result).toEqual(expect.objectContaining({
|
|
42
78
|
mode: 'stack',
|
|
43
79
|
name: mockError.name,
|
|
@@ -48,17 +84,21 @@ describe('errors with stack property', () => {
|
|
|
48
84
|
func: 'nrWrapper'
|
|
49
85
|
}));
|
|
50
86
|
});
|
|
51
|
-
test('stack should still parse when column numbers are missing', () => {
|
|
87
|
+
test('stack should still parse when column numbers are missing', async () => {
|
|
52
88
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
53
89
|
...baseMockError,
|
|
54
|
-
stack: 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n at errorTest (
|
|
90
|
+
stack: 'RangeError: Invalid array length\n' + 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n' + ' at errorTest (' + globalScopeLocation + '?loader=spa:60)\n' + ' at captureError (' + globalScopeLocation + '?loader=spa:17)\n' + ' at onload (' + globalScopeLocation + '?loader=spa:57)'
|
|
55
91
|
});
|
|
56
|
-
|
|
92
|
+
mockGlobalScopeLocation();
|
|
93
|
+
const {
|
|
94
|
+
computeStackTrace
|
|
95
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
96
|
+
const result = computeStackTrace(mockError);
|
|
57
97
|
expect(result).toEqual(expect.objectContaining({
|
|
58
98
|
mode: 'stack',
|
|
59
99
|
name: mockError.name,
|
|
60
100
|
message: mockError.message,
|
|
61
|
-
stackString:
|
|
101
|
+
stackString: 'RangeError: Invalid array length\n' + 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n' + ' at errorTest (<inline>:60)\n' + ' at captureError (<inline>:17)\n' + ' at onload (<inline>:57)'
|
|
62
102
|
}));
|
|
63
103
|
expect(result.frames.length).toEqual(3);
|
|
64
104
|
expect(result.frames).toContainEqual(expect.objectContaining({
|
|
@@ -74,12 +114,16 @@ describe('errors with stack property', () => {
|
|
|
74
114
|
column: null
|
|
75
115
|
}));
|
|
76
116
|
});
|
|
77
|
-
test('parser can handle chrome eval stack', () => {
|
|
117
|
+
test('parser can handle chrome eval stack', async () => {
|
|
78
118
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
79
119
|
...baseMockError,
|
|
80
|
-
stack: ' at foobar (eval at foobar (
|
|
120
|
+
stack: ' at foobar (eval at foobar (' + globalScopeLocation + '))'
|
|
81
121
|
});
|
|
82
|
-
|
|
122
|
+
mockGlobalScopeLocation();
|
|
123
|
+
const {
|
|
124
|
+
computeStackTrace
|
|
125
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
126
|
+
const result = computeStackTrace(mockError);
|
|
83
127
|
expect(result).toEqual(expect.objectContaining({
|
|
84
128
|
mode: 'stack',
|
|
85
129
|
name: mockError.name,
|
|
@@ -91,7 +135,7 @@ describe('errors with stack property', () => {
|
|
|
91
135
|
func: 'evaluated code'
|
|
92
136
|
}));
|
|
93
137
|
});
|
|
94
|
-
test('parser can handle ie eval stack', () => {
|
|
138
|
+
test('parser can handle ie eval stack', async () => {
|
|
95
139
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
96
140
|
toString: 'TypeError: Permission denied',
|
|
97
141
|
name: 'TypeError',
|
|
@@ -99,7 +143,11 @@ describe('errors with stack property', () => {
|
|
|
99
143
|
message: 'Permission denied',
|
|
100
144
|
stack: ' at Function code (Function code:23:23)'
|
|
101
145
|
});
|
|
102
|
-
|
|
146
|
+
mockGlobalScopeLocation();
|
|
147
|
+
const {
|
|
148
|
+
computeStackTrace
|
|
149
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
150
|
+
const result = computeStackTrace(mockError);
|
|
103
151
|
expect(result).toEqual(expect.objectContaining({
|
|
104
152
|
mode: 'stack',
|
|
105
153
|
name: mockError.name,
|
|
@@ -111,12 +159,16 @@ describe('errors with stack property', () => {
|
|
|
111
159
|
func: 'evaluated code'
|
|
112
160
|
}));
|
|
113
161
|
});
|
|
114
|
-
test('parser can handle stack with anonymous function', () => {
|
|
162
|
+
test('parser can handle stack with anonymous function', async () => {
|
|
115
163
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
116
164
|
...baseMockError,
|
|
117
165
|
stack: 'anonymous'
|
|
118
166
|
});
|
|
119
|
-
|
|
167
|
+
mockGlobalScopeLocation();
|
|
168
|
+
const {
|
|
169
|
+
computeStackTrace
|
|
170
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
171
|
+
const result = computeStackTrace(mockError);
|
|
120
172
|
expect(result).toEqual(expect.objectContaining({
|
|
121
173
|
mode: 'stack',
|
|
122
174
|
name: mockError.name,
|
|
@@ -133,7 +185,7 @@ describe('errors without stack property and with line property', () => {
|
|
|
133
185
|
/**
|
|
134
186
|
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
135
187
|
*/
|
|
136
|
-
test('parsed stack should contain sourceURL and line number', () => {
|
|
188
|
+
test('parsed stack should contain sourceURL and line number', async () => {
|
|
137
189
|
const sourceURL = _faker.faker.internet.url();
|
|
138
190
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
139
191
|
...baseMockError,
|
|
@@ -141,7 +193,11 @@ describe('errors without stack property and with line property', () => {
|
|
|
141
193
|
line: 100,
|
|
142
194
|
sourceURL
|
|
143
195
|
});
|
|
144
|
-
|
|
196
|
+
mockGlobalScopeLocation();
|
|
197
|
+
const {
|
|
198
|
+
computeStackTrace
|
|
199
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
200
|
+
const result = computeStackTrace(mockError);
|
|
145
201
|
expect(result).toEqual(expect.objectContaining({
|
|
146
202
|
mode: 'sourceline',
|
|
147
203
|
name: mockError.name,
|
|
@@ -158,7 +214,7 @@ describe('errors without stack property and with line property', () => {
|
|
|
158
214
|
/**
|
|
159
215
|
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
160
216
|
*/
|
|
161
|
-
test('parsed stack should contain sourceURL, line number, and column number', () => {
|
|
217
|
+
test('parsed stack should contain sourceURL, line number, and column number', async () => {
|
|
162
218
|
const sourceURL = _faker.faker.internet.url();
|
|
163
219
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
164
220
|
...baseMockError,
|
|
@@ -167,7 +223,11 @@ describe('errors without stack property and with line property', () => {
|
|
|
167
223
|
stack: undefined,
|
|
168
224
|
sourceURL
|
|
169
225
|
});
|
|
170
|
-
|
|
226
|
+
mockGlobalScopeLocation();
|
|
227
|
+
const {
|
|
228
|
+
computeStackTrace
|
|
229
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
230
|
+
const result = computeStackTrace(mockError);
|
|
171
231
|
expect(result).toEqual(expect.objectContaining({
|
|
172
232
|
mode: 'sourceline',
|
|
173
233
|
name: mockError.name,
|
|
@@ -181,14 +241,18 @@ describe('errors without stack property and with line property', () => {
|
|
|
181
241
|
column: mockError.column
|
|
182
242
|
}));
|
|
183
243
|
});
|
|
184
|
-
test('parsed stack should contain "evaluated code" if sourceURL property is not present', () => {
|
|
244
|
+
test('parsed stack should contain "evaluated code" if sourceURL property is not present', async () => {
|
|
185
245
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
186
246
|
...baseMockError,
|
|
187
247
|
line: 100,
|
|
188
248
|
column: 200,
|
|
189
249
|
stack: undefined
|
|
190
250
|
});
|
|
191
|
-
|
|
251
|
+
mockGlobalScopeLocation();
|
|
252
|
+
const {
|
|
253
|
+
computeStackTrace
|
|
254
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
255
|
+
const result = computeStackTrace(mockError);
|
|
192
256
|
expect(result).toEqual(expect.objectContaining({
|
|
193
257
|
mode: 'sourceline',
|
|
194
258
|
name: mockError.name,
|
|
@@ -201,6 +265,58 @@ describe('errors without stack property and with line property', () => {
|
|
|
201
265
|
}));
|
|
202
266
|
});
|
|
203
267
|
|
|
268
|
+
/**
|
|
269
|
+
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
270
|
+
*/
|
|
271
|
+
test('should show <inline> for same-page URLs', async () => {
|
|
272
|
+
const pageLocation = _faker.faker.internet.url();
|
|
273
|
+
const sourceURL = pageLocation + '?abc=123';
|
|
274
|
+
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
275
|
+
...baseMockError,
|
|
276
|
+
line: 100,
|
|
277
|
+
column: 200,
|
|
278
|
+
stack: undefined,
|
|
279
|
+
sourceURL: sourceURL
|
|
280
|
+
});
|
|
281
|
+
mockGlobalScopeLocation(pageLocation);
|
|
282
|
+
const {
|
|
283
|
+
computeStackTrace
|
|
284
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
285
|
+
const result = computeStackTrace(mockError);
|
|
286
|
+
expect(result).toEqual(expect.objectContaining({
|
|
287
|
+
stackString: "".concat(mockError.name, ": ").concat(mockError.message, "\n at <inline>:").concat(mockError.line, ":").concat(mockError.column)
|
|
288
|
+
}));
|
|
289
|
+
expect(result.frames).toContainEqual(expect.objectContaining({
|
|
290
|
+
url: '<inline>'
|
|
291
|
+
}));
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @deprecated sourceURL is no longer present in errors for any browsers we support
|
|
296
|
+
*/
|
|
297
|
+
test('should NOT show <inline> for same-domain URLs with a sub-path', async () => {
|
|
298
|
+
const pageLocation = _faker.faker.internet.url();
|
|
299
|
+
const sourceURL = pageLocation + '/path/to/script.js';
|
|
300
|
+
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
301
|
+
...baseMockError,
|
|
302
|
+
line: 100,
|
|
303
|
+
column: 200,
|
|
304
|
+
stack: undefined,
|
|
305
|
+
sourceURL
|
|
306
|
+
});
|
|
307
|
+
mockGlobalScopeLocation(pageLocation);
|
|
308
|
+
const {
|
|
309
|
+
computeStackTrace
|
|
310
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
311
|
+
const result = computeStackTrace(mockError);
|
|
312
|
+
expect(result).toEqual(expect.objectContaining({
|
|
313
|
+
stackString: "".concat(mockError.name, ": ").concat(mockError.message, "\n at ").concat(sourceURL, ":").concat(mockError.line, ":").concat(mockError.column)
|
|
314
|
+
}));
|
|
315
|
+
expect(result.frames).toContainEqual(expect.objectContaining({
|
|
316
|
+
url: sourceURL
|
|
317
|
+
}));
|
|
318
|
+
});
|
|
319
|
+
|
|
204
320
|
// TODO: computeStackTraceBySourceAndLine does not respect firefox lineNumber and columnNumber properties when stack is empty
|
|
205
321
|
});
|
|
206
322
|
|
|
@@ -209,12 +325,16 @@ describe('errors without stack property and with line property', () => {
|
|
|
209
325
|
* error, including primitives.
|
|
210
326
|
*/
|
|
211
327
|
describe('errors that are messages only or primitives', () => {
|
|
212
|
-
test('parser should get error name from constructor', () => {
|
|
328
|
+
test('parser should get error name from constructor', async () => {
|
|
213
329
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
214
330
|
toString: '0',
|
|
215
331
|
constructor: 'function Number() { [native code] }'
|
|
216
332
|
});
|
|
217
|
-
|
|
333
|
+
mockGlobalScopeLocation();
|
|
334
|
+
const {
|
|
335
|
+
computeStackTrace
|
|
336
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
337
|
+
const result = computeStackTrace(mockError);
|
|
218
338
|
expect(result).toEqual(expect.objectContaining({
|
|
219
339
|
mode: 'nameonly',
|
|
220
340
|
name: 'Number',
|
|
@@ -222,13 +342,17 @@ describe('errors that are messages only or primitives', () => {
|
|
|
222
342
|
frames: []
|
|
223
343
|
}));
|
|
224
344
|
});
|
|
225
|
-
test('parser should get error name from name property', () => {
|
|
345
|
+
test('parser should get error name from name property', async () => {
|
|
226
346
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
227
347
|
toString: '0',
|
|
228
348
|
name: _faker.faker.datatype.uuid(),
|
|
229
349
|
constructor: 'function Number() { [native code] }'
|
|
230
350
|
});
|
|
231
|
-
|
|
351
|
+
mockGlobalScopeLocation();
|
|
352
|
+
const {
|
|
353
|
+
computeStackTrace
|
|
354
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
355
|
+
const result = computeStackTrace(mockError);
|
|
232
356
|
expect(result).toEqual(expect.objectContaining({
|
|
233
357
|
mode: 'nameonly',
|
|
234
358
|
name: mockError.name,
|
|
@@ -236,14 +360,18 @@ describe('errors that are messages only or primitives', () => {
|
|
|
236
360
|
frames: []
|
|
237
361
|
}));
|
|
238
362
|
});
|
|
239
|
-
test('parser should include the message property', () => {
|
|
363
|
+
test('parser should include the message property', async () => {
|
|
240
364
|
const mockError = _testingUtils.browserErrorUtils.constructError({
|
|
241
365
|
toString: '0',
|
|
242
366
|
name: _faker.faker.datatype.uuid(),
|
|
243
367
|
message: _faker.faker.datatype.uuid(),
|
|
244
368
|
constructor: 'function Number() { [native code] }'
|
|
245
369
|
});
|
|
246
|
-
|
|
370
|
+
mockGlobalScopeLocation();
|
|
371
|
+
const {
|
|
372
|
+
computeStackTrace
|
|
373
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./compute-stack-trace')));
|
|
374
|
+
const result = computeStackTrace(mockError);
|
|
247
375
|
expect(result).toEqual(expect.objectContaining({
|
|
248
376
|
mode: 'nameonly',
|
|
249
377
|
name: mockError.name,
|
|
@@ -252,6 +380,4 @@ describe('errors that are messages only or primitives', () => {
|
|
|
252
380
|
frames: []
|
|
253
381
|
}));
|
|
254
382
|
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
// describe('')
|
|
383
|
+
});
|