@newrelic/browser-agent 1.233.1 → 1.235.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/README.md +1 -1
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/constants/shared-channel.js +19 -0
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +10 -10
- package/dist/cjs/common/harvest/{harvest-scheduler.test.js → harvest-scheduler.component-test.js} +2 -2
- package/dist/cjs/common/harvest/harvest-scheduler.js +21 -5
- package/dist/cjs/common/harvest/harvest.component-test.js +224 -0
- package/dist/cjs/common/harvest/harvest.js +4 -11
- package/dist/cjs/common/session/{session-entity.test.js → session-entity.component-test.js} +79 -42
- package/dist/cjs/common/session/session-entity.js +19 -11
- package/dist/cjs/common/timer/interaction-timer.js +1 -1
- package/dist/cjs/common/url/canonicalize-url.test.js +26 -30
- package/dist/cjs/common/url/encode.js +2 -2
- package/dist/cjs/common/util/console.test.js +30 -0
- package/dist/cjs/common/util/data-size.test.js +37 -20
- package/dist/cjs/common/util/feature-flags.js +23 -12
- package/dist/cjs/common/util/feature-flags.test.js +84 -0
- package/dist/cjs/common/util/get-or-set.js +8 -1
- package/dist/cjs/common/util/get-or-set.test.js +47 -0
- package/dist/cjs/common/util/global-scope.js +1 -32
- package/dist/cjs/common/util/global-scope.test.js +72 -0
- package/dist/cjs/common/util/obfuscate.component-test.js +129 -0
- package/dist/cjs/common/util/obfuscate.js +2 -2
- package/dist/cjs/common/util/stringify.test.js +48 -0
- package/dist/cjs/common/util/submit-data.js +18 -18
- package/dist/cjs/common/util/submit-data.test.js +245 -0
- package/dist/cjs/common/util/traverse.js +19 -27
- package/dist/cjs/common/util/traverse.test.js +44 -0
- package/dist/cjs/common/wrap/wrap-raf.js +1 -1
- package/dist/cjs/common/wrap/wrap-timer.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/index.js +4 -0
- package/dist/cjs/features/jserrors/instrument/index.js +2 -15
- package/dist/cjs/features/metrics/aggregate/endpoint-map.js +14 -0
- package/dist/cjs/features/metrics/aggregate/index.js +3 -2
- package/dist/cjs/features/metrics/instrument/index.js +0 -2
- package/dist/cjs/features/page_view_event/aggregate/index.js +58 -44
- package/dist/cjs/features/session_replay/aggregate/index.component-test.js +457 -0
- package/dist/cjs/features/session_replay/aggregate/index.js +99 -82
- package/dist/cjs/features/session_replay/replay-mode.js +28 -0
- package/dist/cjs/features/session_trace/aggregate/index.js +222 -99
- package/dist/cjs/features/session_trace/constants.js +1 -3
- package/dist/cjs/features/session_trace/instrument/index.js +0 -16
- package/dist/cjs/features/spa/constants.js +0 -1
- package/dist/cjs/features/utils/agent-session.js +20 -36
- package/dist/cjs/features/utils/agent-session.test.js +211 -0
- package/dist/cjs/features/utils/aggregate-base.js +7 -12
- package/dist/cjs/features/utils/aggregate-base.test.js +110 -0
- package/dist/cjs/features/utils/feature-base.test.js +42 -0
- package/dist/cjs/features/utils/handler-cache.js +28 -23
- package/dist/cjs/features/utils/handler-cache.test.js +53 -0
- package/dist/cjs/features/utils/instrument-base.js +58 -39
- package/dist/cjs/features/utils/instrument-base.test.js +179 -0
- package/dist/cjs/features/utils/lazy-feature-loader.test.js +30 -0
- package/dist/cjs/loaders/agent.js +0 -1
- package/dist/cjs/loaders/api/api.js +1 -1
- package/dist/cjs/loaders/configure/configure.js +0 -1
- package/dist/cjs/loaders/features/featureDependencies.js +2 -0
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/constants/shared-channel.js +12 -0
- package/dist/esm/common/event-emitter/contextual-ee.test.js +10 -10
- package/dist/esm/common/harvest/{harvest-scheduler.test.js → harvest-scheduler.component-test.js} +2 -2
- package/dist/esm/common/harvest/harvest-scheduler.js +21 -5
- package/dist/esm/common/harvest/harvest.component-test.js +222 -0
- package/dist/esm/common/harvest/harvest.js +4 -11
- package/dist/esm/common/session/{session-entity.test.js → session-entity.component-test.js} +77 -40
- package/dist/esm/common/session/session-entity.js +17 -11
- package/dist/esm/common/timer/interaction-timer.js +1 -1
- package/dist/esm/common/url/canonicalize-url.test.js +25 -29
- package/dist/esm/common/url/encode.js +2 -2
- package/dist/esm/common/util/console.test.js +28 -0
- package/dist/esm/common/util/data-size.test.js +35 -20
- package/dist/esm/common/util/feature-flags.js +23 -12
- package/dist/esm/common/util/feature-flags.test.js +80 -0
- package/dist/esm/common/util/get-or-set.js +8 -1
- package/dist/esm/common/util/get-or-set.test.js +45 -0
- package/dist/esm/common/util/global-scope.js +1 -29
- package/dist/esm/common/util/global-scope.test.js +70 -0
- package/dist/esm/common/util/obfuscate.component-test.js +125 -0
- package/dist/esm/common/util/obfuscate.js +2 -2
- package/dist/esm/common/util/stringify.test.js +46 -0
- package/dist/esm/common/util/submit-data.js +18 -18
- package/dist/esm/common/util/submit-data.test.js +241 -0
- package/dist/esm/common/util/traverse.js +19 -27
- package/dist/esm/common/util/traverse.test.js +42 -0
- package/dist/esm/common/wrap/wrap-raf.js +1 -1
- package/dist/esm/common/wrap/wrap-timer.js +1 -1
- package/dist/esm/features/jserrors/aggregate/index.js +4 -0
- package/dist/esm/features/jserrors/instrument/index.js +2 -15
- package/dist/esm/features/metrics/aggregate/endpoint-map.js +7 -0
- package/dist/esm/features/metrics/aggregate/index.js +3 -2
- package/dist/esm/features/metrics/instrument/index.js +0 -2
- package/dist/esm/features/page_view_event/aggregate/index.js +58 -44
- package/dist/esm/features/session_replay/aggregate/index.component-test.js +453 -0
- package/dist/esm/features/session_replay/aggregate/index.js +92 -78
- package/dist/esm/features/session_replay/replay-mode.js +23 -0
- package/dist/esm/features/session_trace/aggregate/index.js +223 -100
- package/dist/esm/features/session_trace/constants.js +0 -1
- package/dist/esm/features/session_trace/instrument/index.js +1 -17
- package/dist/esm/features/spa/constants.js +0 -1
- package/dist/esm/features/utils/agent-session.js +21 -37
- package/dist/esm/features/utils/agent-session.test.js +207 -0
- package/dist/esm/features/utils/aggregate-base.js +7 -12
- package/dist/esm/features/utils/aggregate-base.test.js +108 -0
- package/dist/esm/features/utils/feature-base.test.js +40 -0
- package/dist/esm/features/utils/handler-cache.js +28 -23
- package/dist/esm/features/utils/handler-cache.test.js +51 -0
- package/dist/esm/features/utils/instrument-base.js +58 -39
- package/dist/esm/features/utils/instrument-base.test.js +175 -0
- package/dist/esm/features/utils/lazy-feature-loader.test.js +29 -0
- package/dist/esm/loaders/agent.js +0 -1
- package/dist/esm/loaders/api/api.js +2 -2
- package/dist/esm/loaders/configure/configure.js +0 -1
- package/dist/esm/loaders/features/featureDependencies.js +2 -0
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/constants/shared-channel.d.ts +5 -0
- package/dist/types/common/constants/shared-channel.d.ts.map +1 -0
- package/dist/types/common/context/shared-context.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest-scheduler.component-test.d.ts +2 -0
- package/dist/types/common/harvest/harvest-scheduler.component-test.d.ts.map +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts +4 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.component-test.d.ts +2 -0
- package/dist/types/common/harvest/harvest.component-test.d.ts.map +1 -0
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/session/session-entity.component-test.d.ts +2 -0
- package/dist/types/common/session/session-entity.component-test.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +9 -5
- package/dist/types/common/session/session-entity.d.ts.map +1 -1
- package/dist/types/common/timer/interaction-timer.component-test.d.ts +2 -0
- package/dist/types/common/timer/interaction-timer.component-test.d.ts.map +1 -0
- package/dist/types/common/timer/timer.d.ts.map +1 -1
- package/dist/types/common/url/encode.component-test.d.ts +2 -0
- package/dist/types/common/url/encode.component-test.d.ts.map +1 -0
- package/dist/types/common/url/protocol.component-test.d.ts +2 -0
- package/dist/types/common/url/protocol.component-test.d.ts.map +1 -0
- package/dist/types/common/util/feature-flags.d.ts +1 -0
- package/dist/types/common/util/feature-flags.d.ts.map +1 -1
- package/dist/types/common/util/get-or-set.d.ts +9 -1
- package/dist/types/common/util/get-or-set.d.ts.map +1 -1
- package/dist/types/common/util/global-scope.d.ts +0 -9
- package/dist/types/common/util/global-scope.d.ts.map +1 -1
- package/dist/types/common/util/obfuscate.component-test.d.ts +2 -0
- package/dist/types/common/util/obfuscate.component-test.d.ts.map +1 -0
- package/dist/types/common/util/submit-data.d.ts +14 -10
- package/dist/types/common/util/submit-data.d.ts.map +1 -1
- package/dist/types/common/util/traverse.d.ts +10 -1
- package/dist/types/common/util/traverse.d.ts.map +1 -1
- package/dist/types/common/window/nreum.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +1 -0
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +8 -0
- package/dist/types/features/metrics/aggregate/endpoint-map.d.ts.map +1 -0
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/aggregate/index.component-test.d.ts +2 -0
- package/dist/types/features/session_replay/aggregate/index.component-test.d.ts.map +1 -0
- package/dist/types/features/session_replay/aggregate/index.d.ts +14 -5
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/replay-mode.d.ts +9 -0
- package/dist/types/features/session_replay/replay-mode.d.ts.map +1 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts +21 -3
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/constants.d.ts +0 -1
- package/dist/types/features/session_trace/constants.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts +0 -2
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/constants.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts.map +1 -1
- package/dist/types/features/utils/aggregate-base.d.ts +6 -1
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
- package/dist/types/features/utils/handler-cache.d.ts +12 -11
- package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
- package/dist/types/features/utils/instrument-base.d.ts +17 -1
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
- package/package.json +14 -8
- package/src/common/config/state/init.js +0 -1
- package/src/common/constants/shared-channel.js +13 -0
- package/src/common/context/shared-context.js +0 -1
- package/src/common/event-emitter/contextual-ee.test.js +10 -10
- package/src/common/harvest/{harvest-scheduler.test.js → harvest-scheduler.component-test.js} +2 -2
- package/src/common/harvest/harvest-scheduler.js +17 -6
- package/src/common/harvest/harvest.component-test.js +169 -0
- package/src/common/harvest/harvest.js +5 -9
- package/src/common/session/{session-entity.test.js → session-entity.component-test.js} +70 -48
- package/src/common/session/session-entity.js +15 -12
- package/src/common/timer/interaction-timer.js +1 -1
- package/src/common/timer/timer.js +0 -1
- package/src/common/url/canonicalize-url.test.js +32 -21
- package/src/common/url/encode.js +2 -2
- package/src/common/util/console.test.js +34 -0
- package/src/common/util/data-size.test.js +27 -20
- package/src/common/util/feature-flags.js +24 -12
- package/src/common/util/feature-flags.test.js +98 -0
- package/src/common/util/get-or-set.js +8 -1
- package/src/common/util/get-or-set.test.js +58 -0
- package/src/common/util/global-scope.js +0 -26
- package/src/common/util/global-scope.test.js +87 -0
- package/src/common/util/obfuscate.component-test.js +173 -0
- package/src/common/util/obfuscate.js +2 -2
- package/src/common/util/stringify.test.js +49 -0
- package/src/common/util/submit-data.js +18 -19
- package/src/common/util/submit-data.test.js +226 -0
- package/src/common/util/traverse.js +18 -27
- package/src/common/util/traverse.test.js +50 -0
- package/src/common/window/nreum.js +0 -1
- package/src/common/wrap/wrap-raf.js +1 -1
- package/src/common/wrap/wrap-timer.js +1 -1
- package/src/features/jserrors/aggregate/index.js +5 -0
- package/src/features/jserrors/instrument/index.js +2 -15
- package/src/features/metrics/aggregate/endpoint-map.js +7 -0
- package/src/features/metrics/aggregate/index.js +3 -2
- package/src/features/metrics/aggregate/polyfill-detection.es5.js +0 -1
- package/src/features/metrics/instrument/index.js +0 -2
- package/src/features/page_view_event/aggregate/index.js +48 -51
- package/src/features/page_view_event/instrument/index.js +0 -1
- package/src/features/session_replay/aggregate/index.component-test.js +368 -0
- package/src/features/session_replay/aggregate/index.js +96 -71
- package/src/features/session_replay/instrument/index.js +0 -1
- package/src/features/session_replay/replay-mode.js +23 -0
- package/src/features/session_trace/aggregate/index.js +198 -79
- package/src/features/session_trace/constants.js +0 -1
- package/src/features/session_trace/instrument/index.js +2 -19
- package/src/features/spa/constants.js +0 -1
- package/src/features/utils/agent-session.js +22 -34
- package/src/features/utils/agent-session.test.js +194 -0
- package/src/features/utils/aggregate-base.js +12 -9
- package/src/features/utils/aggregate-base.test.js +122 -0
- package/src/features/utils/feature-base.test.js +45 -0
- package/src/features/utils/handler-cache.js +29 -24
- package/src/features/utils/handler-cache.test.js +72 -0
- package/src/features/utils/instrument-base.js +45 -29
- package/src/features/utils/instrument-base.test.js +190 -0
- package/src/features/utils/lazy-feature-loader.test.js +37 -0
- package/src/loaders/agent.js +0 -1
- package/src/loaders/api/api.js +2 -2
- package/src/loaders/configure/configure.js +0 -1
- package/src/loaders/features/featureDependencies.js +2 -0
- package/dist/cjs/common/storage/local-memory.js +0 -35
- package/dist/cjs/common/storage/local-memory.test.js +0 -20
- package/dist/cjs/common/util/s-hash.js +0 -19
- package/dist/cjs/features/metrics/instrument/workers-helper.js +0 -124
- package/dist/esm/common/storage/local-memory.js +0 -28
- package/dist/esm/common/storage/local-memory.test.js +0 -18
- package/dist/esm/common/util/s-hash.js +0 -13
- package/dist/esm/features/metrics/instrument/workers-helper.js +0 -119
- package/dist/types/common/storage/local-memory.d.ts +0 -8
- package/dist/types/common/storage/local-memory.d.ts.map +0 -1
- package/dist/types/common/util/s-hash.d.ts +0 -2
- package/dist/types/common/util/s-hash.d.ts.map +0 -1
- package/dist/types/features/metrics/instrument/workers-helper.d.ts +0 -7
- package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +0 -1
- package/src/common/storage/local-memory.js +0 -30
- package/src/common/storage/local-memory.test.js +0 -19
- package/src/common/util/s-hash.js +0 -14
- package/src/features/metrics/instrument/workers-helper.js +0 -113
- /package/dist/cjs/common/timer/{interaction-timer.test.js → interaction-timer.component-test.js} +0 -0
- /package/dist/cjs/common/url/{encode.test.js → encode.component-test.js} +0 -0
- /package/dist/cjs/common/url/{protocol.test.js → protocol.component-test.js} +0 -0
- /package/dist/esm/common/timer/{interaction-timer.test.js → interaction-timer.component-test.js} +0 -0
- /package/dist/esm/common/url/{encode.test.js → encode.component-test.js} +0 -0
- /package/dist/esm/common/url/{protocol.test.js → protocol.component-test.js} +0 -0
- /package/src/common/timer/{interaction-timer.test.js → interaction-timer.component-test.js} +0 -0
- /package/src/common/url/{encode.test.js → encode.component-test.js} +0 -0
- /package/src/common/url/{protocol.test.js → protocol.component-test.js} +0 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The New Relic browser agent instruments your web application or site and provide
|
|
|
6
6
|
|
|
7
7
|
- The instructions on this page pertain to installing the browser agent as an NPM package.
|
|
8
8
|
|
|
9
|
-
- The browser agent is also generally available as a copy-paste JavaScript snippet and via auto-injection by backend apps. See *[Install the browser agent](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/)* for info on these alternatives.
|
|
9
|
+
- The browser agent is also generally available as a copy-paste JavaScript snippet and via auto-injection by backend apps. See *[Install the browser agent](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/)* for info on these alternatives. Releases are deployed to customers gradually, so the version available via these other methods often lags the current release of this package.
|
|
10
10
|
|
|
11
11
|
- For questions and feedback on this package, please visit the [Explorer's Hub](https://forum.newrelic.com/s/), New Relic's community support forum.
|
|
12
12
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sharedChannel = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @file Keeps an object alive that is passed to all feature aggregate modules.
|
|
9
|
+
* The purpose is to have a way for communication and signals to relay across features at runtime.
|
|
10
|
+
* This object can hold any arbitrary values and should be treated as on-the-fly dynamic.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
let onReplayReady;
|
|
14
|
+
const sessionReplayInitialized = new Promise(resolve => onReplayReady = resolve);
|
|
15
|
+
const sharedChannel = Object.freeze({
|
|
16
|
+
onReplayReady,
|
|
17
|
+
sessionReplayInitialized
|
|
18
|
+
});
|
|
19
|
+
exports.sharedChannel = sharedChannel;
|
|
@@ -93,7 +93,7 @@ describe('event-emitter context', () => {
|
|
|
93
93
|
});
|
|
94
94
|
});
|
|
95
95
|
describe('event-emitter buffer', () => {
|
|
96
|
-
|
|
96
|
+
test('it should create a new buffer for the given group', async () => {
|
|
97
97
|
const {
|
|
98
98
|
ee
|
|
99
99
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -105,7 +105,7 @@ describe('event-emitter buffer', () => {
|
|
|
105
105
|
}));
|
|
106
106
|
expect(ee.isBuffering(eventType)).toEqual(true);
|
|
107
107
|
});
|
|
108
|
-
|
|
108
|
+
test('it should default group to "feature"', async () => {
|
|
109
109
|
const {
|
|
110
110
|
ee
|
|
111
111
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -116,7 +116,7 @@ describe('event-emitter buffer', () => {
|
|
|
116
116
|
}));
|
|
117
117
|
expect(ee.isBuffering(eventType)).toEqual(true);
|
|
118
118
|
});
|
|
119
|
-
|
|
119
|
+
test('it should not create buffer if event-emitter is aborted', async () => {
|
|
120
120
|
const {
|
|
121
121
|
ee
|
|
122
122
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -156,7 +156,7 @@ describe('event-emitter abort', () => {
|
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
158
|
describe('event-emitter emit', () => {
|
|
159
|
-
|
|
159
|
+
test('should execute the listener', async () => {
|
|
160
160
|
const {
|
|
161
161
|
ee
|
|
162
162
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -167,7 +167,7 @@ describe('event-emitter emit', () => {
|
|
|
167
167
|
ee.emit(eventType, eventArgs);
|
|
168
168
|
expect(mockListener).toHaveBeenCalledWith(eventArgs[0], eventArgs[1], eventArgs[2]);
|
|
169
169
|
});
|
|
170
|
-
|
|
170
|
+
test('should not execute the listener after removal', async () => {
|
|
171
171
|
const {
|
|
172
172
|
ee
|
|
173
173
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -180,7 +180,7 @@ describe('event-emitter emit', () => {
|
|
|
180
180
|
ee.emit(eventType, eventArgs);
|
|
181
181
|
expect(mockListener).toHaveBeenCalledTimes(1);
|
|
182
182
|
});
|
|
183
|
-
|
|
183
|
+
test('should return early if global event-emitter is aborted', async () => {
|
|
184
184
|
const {
|
|
185
185
|
ee
|
|
186
186
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -195,7 +195,7 @@ describe('event-emitter emit', () => {
|
|
|
195
195
|
ee.emit(eventType, eventArgs);
|
|
196
196
|
expect(mockListener).toHaveBeenCalledTimes(0);
|
|
197
197
|
});
|
|
198
|
-
|
|
198
|
+
test('should still emit if global event-emitter is aborted but force flag is true', async () => {
|
|
199
199
|
const {
|
|
200
200
|
ee
|
|
201
201
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -211,7 +211,7 @@ describe('event-emitter emit', () => {
|
|
|
211
211
|
scopeEE.emit(eventType, eventArgs, {}, true);
|
|
212
212
|
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
213
213
|
});
|
|
214
|
-
|
|
214
|
+
test('should bubble the event if bubble flag is true', async () => {
|
|
215
215
|
const {
|
|
216
216
|
ee
|
|
217
217
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -226,7 +226,7 @@ describe('event-emitter emit', () => {
|
|
|
226
226
|
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
227
227
|
expect(mockListener).toHaveBeenCalledTimes(1);
|
|
228
228
|
});
|
|
229
|
-
|
|
229
|
+
test('should not bubble the event if bubble flag is false', async () => {
|
|
230
230
|
const {
|
|
231
231
|
ee
|
|
232
232
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
|
@@ -241,7 +241,7 @@ describe('event-emitter emit', () => {
|
|
|
241
241
|
expect(mockScopeListener).toHaveBeenCalledTimes(1);
|
|
242
242
|
expect(mockListener).not.toHaveBeenCalled();
|
|
243
243
|
});
|
|
244
|
-
|
|
244
|
+
test('should buffer the event on the scoped event-emitter', async () => {
|
|
245
245
|
const {
|
|
246
246
|
ee
|
|
247
247
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./contextual-ee')));
|
package/dist/cjs/common/harvest/{harvest-scheduler.test.js → harvest-scheduler.component-test.js}
RENAMED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _init = require("../config/state/init");
|
|
4
4
|
var _harvestScheduler = require("./harvest-scheduler");
|
|
5
5
|
describe('runHarvest', () => {
|
|
6
|
-
|
|
6
|
+
test('should re-schedule harvest even if there is no accumulated data', () => {
|
|
7
7
|
(0, _init.setConfiguration)('asdf', {});
|
|
8
8
|
const scheduler = new _harvestScheduler.HarvestScheduler('events', {
|
|
9
9
|
getPayload: jest.fn()
|
|
@@ -19,7 +19,7 @@ describe('runHarvest', () => {
|
|
|
19
19
|
expect(scheduler.opts.getPayload()).toBeFalsy();
|
|
20
20
|
expect(scheduler.scheduleHarvest).toHaveBeenCalledTimes(1);
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
test('should also re-schedule harvest if there is accumulated data', () => {
|
|
23
23
|
(0, _init.setConfiguration)('asdf', {});
|
|
24
24
|
const scheduler = new _harvestScheduler.HarvestScheduler('events', {
|
|
25
25
|
getPayload: jest.fn().mockImplementation(() => 'payload')
|
|
@@ -9,6 +9,7 @@ var _sharedContext = require("../context/shared-context");
|
|
|
9
9
|
var _harvest = require("./harvest");
|
|
10
10
|
var _eol = require("../unload/eol");
|
|
11
11
|
var _config = require("../config/config");
|
|
12
|
+
var _sessionEntity = require("../session/session-entity");
|
|
12
13
|
/*
|
|
13
14
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
14
15
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -42,9 +43,18 @@ class HarvestScheduler extends _sharedContext.SharedContext {
|
|
|
42
43
|
// unload if EOL mechanism fires
|
|
43
44
|
(0, _eol.subscribeToEOL)(this.unload.bind(this), (0, _config.getConfigurationValue)(this.sharedContext.agentIdentifier, 'allow_bfcache')); // TO DO: remove feature flag after rls stable
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
/* Flush all buffered data if session resets and give up retries. This should be synchronous to ensure that the correct `session` value is sent.
|
|
47
|
+
Since session-reset generates a new session ID and the ID is grabbed at send-time, any delays or retries would cause the payload to be sent under
|
|
48
|
+
the wrong session ID. */
|
|
49
|
+
this.sharedContext?.ee.on(_sessionEntity.SESSION_EVENTS.RESET, () => this.runHarvest({
|
|
50
|
+
forceNoRetry: true
|
|
51
|
+
}));
|
|
47
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* This function is only meant for the last outgoing harvest cycle of a page. It trickles down to using sendBeacon, which should not be used
|
|
56
|
+
* to send payloads while the page is still active, due to limitations on how much data can be buffered in the API at any one time.
|
|
57
|
+
*/
|
|
48
58
|
unload() {
|
|
49
59
|
if (this.aborted) return;
|
|
50
60
|
// If opts.onUnload is defined, these are special actions to execute before attempting to send the final payload.
|
|
@@ -116,7 +126,7 @@ class HarvestScheduler extends _sharedContext.SharedContext {
|
|
|
116
126
|
payload,
|
|
117
127
|
opts,
|
|
118
128
|
submitMethod,
|
|
119
|
-
cbFinished:
|
|
129
|
+
cbFinished: cbRanAfterSend,
|
|
120
130
|
customUrl: this.opts.customUrl,
|
|
121
131
|
raw: this.opts.raw
|
|
122
132
|
});
|
|
@@ -125,8 +135,14 @@ class HarvestScheduler extends _sharedContext.SharedContext {
|
|
|
125
135
|
this.scheduleHarvest();
|
|
126
136
|
}
|
|
127
137
|
return;
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* This is executed immediately after harvest sends the data via XHR, or if there's nothing to send. Note that this excludes on unloading / sendBeacon.
|
|
141
|
+
* @param {Object} result
|
|
142
|
+
*/
|
|
143
|
+
function cbRanAfterSend(result) {
|
|
144
|
+
if (opts?.forceNoRetry) result.retry = false; // discard unsent data rather than re-queuing for next harvest attempt
|
|
145
|
+
scheduler.onHarvestFinished(opts, result);
|
|
130
146
|
}
|
|
131
147
|
}
|
|
132
148
|
onHarvestFinished(opts, result) {
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _submitData = require("../util/submit-data");
|
|
4
|
+
var _harvest = require("./harvest");
|
|
5
|
+
jest.mock('../context/shared-context', () => ({
|
|
6
|
+
__esModule: true,
|
|
7
|
+
SharedContext: function () {
|
|
8
|
+
this.sharedContext = {
|
|
9
|
+
agentIdentifier: 'abcd'
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}));
|
|
13
|
+
jest.mock('../config/config', () => ({
|
|
14
|
+
__esModule: true,
|
|
15
|
+
getConfigurationValue: jest.fn(),
|
|
16
|
+
getInfo: jest.fn().mockReturnValue({
|
|
17
|
+
errorBeacon: 'example.com',
|
|
18
|
+
licenseKey: 'abcd'
|
|
19
|
+
}),
|
|
20
|
+
getRuntime: jest.fn().mockReturnValue({
|
|
21
|
+
bytesSent: {},
|
|
22
|
+
queryBytesSent: {}
|
|
23
|
+
})
|
|
24
|
+
}));
|
|
25
|
+
jest.mock('../util/submit-data', () => ({
|
|
26
|
+
__esModule: true,
|
|
27
|
+
submitData: {
|
|
28
|
+
xhr: jest.fn(() => ({
|
|
29
|
+
addEventListener: jest.fn()
|
|
30
|
+
})),
|
|
31
|
+
beacon: jest.fn(),
|
|
32
|
+
img: jest.fn()
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
describe('sendX', () => {
|
|
36
|
+
test.each([null, undefined, false])('should not send request when body is empty and sendEmptyBody is %s', sendEmptyBody => {
|
|
37
|
+
const sendCallback = jest.fn();
|
|
38
|
+
const harvester = new _harvest.Harvest();
|
|
39
|
+
harvester.on('jserrors', () => ({
|
|
40
|
+
body: {},
|
|
41
|
+
qs: {}
|
|
42
|
+
}));
|
|
43
|
+
harvester.sendX({
|
|
44
|
+
endpoint: 'jserrors',
|
|
45
|
+
cbFinished: sendCallback
|
|
46
|
+
});
|
|
47
|
+
expect(sendCallback).toHaveBeenCalledWith({
|
|
48
|
+
sent: false
|
|
49
|
+
});
|
|
50
|
+
expect(_submitData.submitData.xhr).not.toHaveBeenCalled();
|
|
51
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
52
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
test('should send request when body is empty and sendEmptyBody is true', () => {
|
|
55
|
+
const harvester = new _harvest.Harvest();
|
|
56
|
+
harvester.on('jserrors', () => ({
|
|
57
|
+
body: {},
|
|
58
|
+
qs: {}
|
|
59
|
+
}));
|
|
60
|
+
harvester.sendX({
|
|
61
|
+
endpoint: 'jserrors',
|
|
62
|
+
opts: {
|
|
63
|
+
sendEmptyBody: true
|
|
64
|
+
},
|
|
65
|
+
cbFinished: jest.fn()
|
|
66
|
+
});
|
|
67
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
68
|
+
url: expect.stringContaining('https://example.com/jserrors/1/abcd?'),
|
|
69
|
+
body: undefined
|
|
70
|
+
}));
|
|
71
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
72
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
test.each([null, undefined, []])('should remove %s values from the body and query string when sending', emptyValue => {
|
|
75
|
+
const harvester = new _harvest.Harvest();
|
|
76
|
+
harvester.on('jserrors', () => ({
|
|
77
|
+
body: {
|
|
78
|
+
bar: 'foo',
|
|
79
|
+
empty: emptyValue
|
|
80
|
+
},
|
|
81
|
+
qs: {
|
|
82
|
+
foo: 'bar',
|
|
83
|
+
empty: emptyValue
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
harvester.sendX({
|
|
87
|
+
endpoint: 'jserrors',
|
|
88
|
+
cbFinished: jest.fn()
|
|
89
|
+
});
|
|
90
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
91
|
+
url: expect.stringContaining('&foo=bar'),
|
|
92
|
+
body: JSON.stringify({
|
|
93
|
+
bar: 'foo'
|
|
94
|
+
})
|
|
95
|
+
}));
|
|
96
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
97
|
+
url: expect.not.stringContaining('&empty'),
|
|
98
|
+
body: expect.not.stringContaining('empty')
|
|
99
|
+
}));
|
|
100
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
101
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
102
|
+
});
|
|
103
|
+
test.each([1, false, true])('should not remove value %s (when it doesn\'t have a length) from the body and query string when sending', nonStringValue => {
|
|
104
|
+
const harvester = new _harvest.Harvest();
|
|
105
|
+
harvester.on('jserrors', () => ({
|
|
106
|
+
body: {
|
|
107
|
+
bar: 'foo',
|
|
108
|
+
nonString: nonStringValue
|
|
109
|
+
},
|
|
110
|
+
qs: {
|
|
111
|
+
foo: 'bar',
|
|
112
|
+
nonString: nonStringValue
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
harvester.sendX({
|
|
116
|
+
endpoint: 'jserrors',
|
|
117
|
+
cbFinished: jest.fn()
|
|
118
|
+
});
|
|
119
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
120
|
+
url: expect.stringContaining("&nonString=".concat(nonStringValue)),
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
bar: 'foo',
|
|
123
|
+
nonString: nonStringValue
|
|
124
|
+
})
|
|
125
|
+
}));
|
|
126
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
127
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('send', () => {
|
|
131
|
+
test.each([null, undefined, false])('should not send request when body is empty and sendEmptyBody is %s', sendEmptyBody => {
|
|
132
|
+
const sendCallback = jest.fn();
|
|
133
|
+
const harvester = new _harvest.Harvest();
|
|
134
|
+
harvester.send({
|
|
135
|
+
endpoint: 'rum',
|
|
136
|
+
payload: {
|
|
137
|
+
qs: {},
|
|
138
|
+
body: {}
|
|
139
|
+
},
|
|
140
|
+
opts: {
|
|
141
|
+
sendEmptyBody
|
|
142
|
+
},
|
|
143
|
+
cbFinished: sendCallback
|
|
144
|
+
});
|
|
145
|
+
expect(sendCallback).toHaveBeenCalledWith({
|
|
146
|
+
sent: false
|
|
147
|
+
});
|
|
148
|
+
expect(_submitData.submitData.xhr).not.toHaveBeenCalled();
|
|
149
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
150
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
test('should send request when body is empty and sendEmptyBody is true', () => {
|
|
153
|
+
const harvester = new _harvest.Harvest();
|
|
154
|
+
harvester.send({
|
|
155
|
+
endpoint: 'rum',
|
|
156
|
+
payload: {
|
|
157
|
+
qs: {},
|
|
158
|
+
body: {}
|
|
159
|
+
},
|
|
160
|
+
opts: {
|
|
161
|
+
sendEmptyBody: true
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
165
|
+
url: expect.stringContaining('https://example.com/1/abcd?'),
|
|
166
|
+
body: undefined
|
|
167
|
+
}));
|
|
168
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
169
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
170
|
+
});
|
|
171
|
+
test.each([null, undefined, []])('should remove %s values from the body and query string when sending', emptyValue => {
|
|
172
|
+
const harvester = new _harvest.Harvest();
|
|
173
|
+
harvester.send({
|
|
174
|
+
endpoint: 'rum',
|
|
175
|
+
payload: {
|
|
176
|
+
qs: {
|
|
177
|
+
foo: 'bar',
|
|
178
|
+
empty: emptyValue
|
|
179
|
+
},
|
|
180
|
+
body: {
|
|
181
|
+
bar: 'foo',
|
|
182
|
+
empty: emptyValue
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
187
|
+
url: expect.stringContaining('&foo=bar'),
|
|
188
|
+
body: JSON.stringify({
|
|
189
|
+
bar: 'foo'
|
|
190
|
+
})
|
|
191
|
+
}));
|
|
192
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
193
|
+
url: expect.not.stringContaining('&empty'),
|
|
194
|
+
body: expect.not.stringContaining('empty')
|
|
195
|
+
}));
|
|
196
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
197
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
198
|
+
});
|
|
199
|
+
test.each([1, false, true])('should not remove value %s (when it doesn\'t have a length) from the body and query string when sending', nonStringValue => {
|
|
200
|
+
const harvester = new _harvest.Harvest();
|
|
201
|
+
harvester.send({
|
|
202
|
+
endpoint: 'rum',
|
|
203
|
+
payload: {
|
|
204
|
+
qs: {
|
|
205
|
+
foo: 'bar',
|
|
206
|
+
nonString: nonStringValue
|
|
207
|
+
},
|
|
208
|
+
body: {
|
|
209
|
+
bar: 'foo',
|
|
210
|
+
nonString: nonStringValue
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
expect(_submitData.submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
215
|
+
url: expect.stringContaining("&nonString=".concat(nonStringValue)),
|
|
216
|
+
body: JSON.stringify({
|
|
217
|
+
bar: 'foo',
|
|
218
|
+
nonString: nonStringValue
|
|
219
|
+
})
|
|
220
|
+
}));
|
|
221
|
+
expect(_submitData.submitData.img).not.toHaveBeenCalled();
|
|
222
|
+
expect(_submitData.submitData.beacon).not.toHaveBeenCalled();
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -131,7 +131,7 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
131
131
|
var info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
|
|
132
132
|
if (!info.errorBeacon) return false;
|
|
133
133
|
var agentRuntime = (0, _config.getRuntime)(this.sharedContext.agentIdentifier);
|
|
134
|
-
if (!payload.body) {
|
|
134
|
+
if (!payload.body && !opts?.sendEmptyBody) {
|
|
135
135
|
// no payload body? nothing to send, just run onfinish stuff and return
|
|
136
136
|
if (cbFinished) {
|
|
137
137
|
cbFinished({
|
|
@@ -141,7 +141,7 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
141
141
|
return false;
|
|
142
142
|
}
|
|
143
143
|
let url = '';
|
|
144
|
-
if (customUrl) url = customUrl;else if (raw) url = "".concat(this.getScheme(), "://").concat(info.errorBeacon, "/").concat(endpoint);else url = "".concat(this.getScheme(), "://").concat(info.errorBeacon
|
|
144
|
+
if (customUrl) url = customUrl;else if (raw) url = "".concat(this.getScheme(), "://").concat(info.errorBeacon, "/").concat(endpoint);else url = "".concat(this.getScheme(), "://").concat(info.errorBeacon).concat(endpoint !== 'rum' ? "/".concat(endpoint) : '', "/1/").concat(info.licenseKey);
|
|
145
145
|
var baseParams = !raw && includeBaseParams ? this.baseQueryString() : '';
|
|
146
146
|
var payloadParams = payload.qs ? (0, _encode.obj)(payload.qs, agentRuntime.maxBytes) : '';
|
|
147
147
|
if (!submitMethod) {
|
|
@@ -250,18 +250,11 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
exports.Harvest = Harvest;
|
|
253
|
-
function or(a, b) {
|
|
254
|
-
return a || b;
|
|
255
|
-
}
|
|
256
253
|
function getSubmitMethod(endpoint, opts) {
|
|
257
254
|
opts = opts || {};
|
|
258
255
|
var method;
|
|
259
256
|
var useBody;
|
|
260
|
-
if (opts.
|
|
261
|
-
// currently: only STN needs a response
|
|
262
|
-
useBody = true;
|
|
263
|
-
method = _submitData.submitData.xhr;
|
|
264
|
-
} else if (opts.unload && _globalScope.isBrowserScope) {
|
|
257
|
+
if (opts.unload && _globalScope.isBrowserScope) {
|
|
265
258
|
// all the features' final harvest; neither methods work outside window context
|
|
266
259
|
useBody = haveSendBeacon;
|
|
267
260
|
method = haveSendBeacon ? _submitData.submitData.beacon : _submitData.submitData.img; // really only IE doesn't have Beacon API for web browsers
|
|
@@ -291,7 +284,7 @@ function createAccumulator() {
|
|
|
291
284
|
var accumulator = {};
|
|
292
285
|
var hasData = false;
|
|
293
286
|
return function (key, val) {
|
|
294
|
-
if (val !== null && val !== undefined && val.length) {
|
|
287
|
+
if (val !== null && val !== undefined && val.toString()?.length) {
|
|
295
288
|
accumulator[key] = val;
|
|
296
289
|
hasData = true;
|
|
297
290
|
}
|