@newrelic/browser-agent 1.261.0 → 1.261.2

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 CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.261.2](https://github.com/newrelic/newrelic-browser-agent/compare/v1.261.1...v1.261.2) (2024-07-01)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * recordReplay will restart replays on same session page loads ([#1093](https://github.com/newrelic/newrelic-browser-agent/issues/1093)) ([cecddbe](https://github.com/newrelic/newrelic-browser-agent/commit/cecddbebc445dabcf3ce48c1fc88311198be6d0a))
12
+
13
+ ## [1.261.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.261.0...v1.261.1) (2024-06-26)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * Unhandled promise rejection for session import ([#1088](https://github.com/newrelic/newrelic-browser-agent/issues/1088)) ([03efcf3](https://github.com/newrelic/newrelic-browser-agent/commit/03efcf36656ac883c4431829fda1bad6445373a1))
19
+
6
20
  ## [1.261.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.260.1...v1.261.0) (2024-06-26)
7
21
 
8
22
 
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = exports.VERSION = "1.261.0";
15
+ const VERSION = exports.VERSION = "1.261.2";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = exports.VERSION = "1.261.0";
15
+ const VERSION = exports.VERSION = "1.261.2";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -32,7 +32,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
32
32
  session = JSON.parse(localStorage.getItem("".concat(_constants.PREFIX, "_").concat(_constants.DEFAULT_KEY)));
33
33
  } catch (err) {}
34
34
  if ((0, _utils.hasReplayPrerequisite)(agentIdentifier)) {
35
- this.ee.on('recordReplay', () => this.#apiStartOrRestartReplay());
35
+ this.ee.on(_constants2.SR_EVENT_EMITTER_TYPES.RECORD, () => this.#apiStartOrRestartReplay());
36
36
  }
37
37
  if (this.#canPreloadRecorder(session)) {
38
38
  this.#mode = session?.sessionReplayMode;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.buildNRMetaNode = buildNRMetaNode;
7
- exports.canImportReplayAgg = canImportReplayAgg;
8
7
  exports.hasReplayPrerequisite = hasReplayPrerequisite;
9
8
  exports.isPreloadAllowed = isPreloadAllowed;
10
9
  var _config = require("../../../common/config/config");
@@ -20,10 +19,6 @@ function hasReplayPrerequisite(agentId) {
20
19
  function isPreloadAllowed(agentId) {
21
20
  return (0, _config.getConfigurationValue)(agentId, 'session_replay.preload') === true && hasReplayPrerequisite(agentId);
22
21
  }
23
- function canImportReplayAgg(agentId, sessionMgr) {
24
- if (!hasReplayPrerequisite(agentId)) return false;
25
- return !!sessionMgr?.isNew || !!sessionMgr?.state.sessionReplayMode; // Session Replay should only try to run if already running from a previous page, or at the beginning of a session
26
- }
27
22
  function buildNRMetaNode(timestamp, timeKeeper) {
28
23
  const correctedTimestamp = timeKeeper.correctAbsoluteTimestamp(timestamp);
29
24
  return {
@@ -23,7 +23,7 @@ class AggregateBase extends _featureBase.FeatureBase {
23
23
  */
24
24
  waitForFlags() {
25
25
  let flagNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
26
- return new Promise((resolve, reject) => {
26
+ const flagsPromise = new Promise((resolve, reject) => {
27
27
  if (_featureFlags.activatedFeatures[this.agentIdentifier]) {
28
28
  resolve(buildOutput(_featureFlags.activatedFeatures[this.agentIdentifier]));
29
29
  } else {
@@ -39,6 +39,9 @@ class AggregateBase extends _featureBase.FeatureBase {
39
39
  });
40
40
  }
41
41
  });
42
+ return flagsPromise.catch(err => {
43
+ this.ee.emit('internal-error', [err]);
44
+ });
42
45
  }
43
46
  drain() {
44
47
  (0, _drain.drain)(this.agentIdentifier, this.featureName);
@@ -93,6 +93,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
93
93
  }
94
94
  } catch (e) {
95
95
  (0, _console.warn)('A problem occurred when starting up session manager. This page will not start or extend any session.', e);
96
+ this.ee.emit('internal-error', [e]);
96
97
  if (this.featureName === _features.FEATURE_NAMES.sessionReplay) this.abortHandler?.(); // SR should stop recording if session DNE
97
98
  }
98
99
 
@@ -136,8 +137,15 @@ class InstrumentBase extends _featureBase.FeatureBase {
136
137
  * @returns
137
138
  */
138
139
  #shouldImportAgg(featureName, session) {
139
- if (featureName === _features.FEATURE_NAMES.sessionReplay) return (0, _utils.canImportReplayAgg)(this.agentIdentifier, session);
140
- return true;
140
+ switch (featureName) {
141
+ case _features.FEATURE_NAMES.sessionReplay:
142
+ // the session manager must be initialized successfully for Replay & Trace features
143
+ return (0, _utils.hasReplayPrerequisite)(this.agentIdentifier) && !!session;
144
+ case _features.FEATURE_NAMES.sessionTrace:
145
+ return !!session;
146
+ default:
147
+ return true;
148
+ }
141
149
  }
142
150
  }
143
151
  exports.InstrumentBase = InstrumentBase;
@@ -6,7 +6,7 @@
6
6
  /**
7
7
  * Exposes the version of the agent
8
8
  */
9
- export const VERSION = "1.261.0";
9
+ export const VERSION = "1.261.2";
10
10
 
11
11
  /**
12
12
  * Exposes the build type of the agent
@@ -6,7 +6,7 @@
6
6
  /**
7
7
  * Exposes the version of the agent
8
8
  */
9
- export const VERSION = "1.261.0";
9
+ export const VERSION = "1.261.2";
10
10
 
11
11
  /**
12
12
  * Exposes the build type of the agent
@@ -26,7 +26,7 @@ export class Instrument extends InstrumentBase {
26
26
  session = JSON.parse(localStorage.getItem("".concat(PREFIX, "_").concat(DEFAULT_KEY)));
27
27
  } catch (err) {}
28
28
  if (hasReplayPrerequisite(agentIdentifier)) {
29
- this.ee.on('recordReplay', () => this.#apiStartOrRestartReplay());
29
+ this.ee.on(SR_EVENT_EMITTER_TYPES.RECORD, () => this.#apiStartOrRestartReplay());
30
30
  }
31
31
  if (this.#canPreloadRecorder(session)) {
32
32
  this.#mode = session?.sessionReplayMode;
@@ -11,10 +11,6 @@ export function hasReplayPrerequisite(agentId) {
11
11
  export function isPreloadAllowed(agentId) {
12
12
  return getConfigurationValue(agentId, 'session_replay.preload') === true && hasReplayPrerequisite(agentId);
13
13
  }
14
- export function canImportReplayAgg(agentId, sessionMgr) {
15
- if (!hasReplayPrerequisite(agentId)) return false;
16
- return !!sessionMgr?.isNew || !!sessionMgr?.state.sessionReplayMode; // Session Replay should only try to run if already running from a previous page, or at the beginning of a session
17
- }
18
14
  export function buildNRMetaNode(timestamp, timeKeeper) {
19
15
  const correctedTimestamp = timeKeeper.correctAbsoluteTimestamp(timestamp);
20
16
  return {
@@ -17,7 +17,7 @@ export class AggregateBase extends FeatureBase {
17
17
  */
18
18
  waitForFlags() {
19
19
  let flagNames = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
20
- return new Promise((resolve, reject) => {
20
+ const flagsPromise = new Promise((resolve, reject) => {
21
21
  if (activatedFeatures[this.agentIdentifier]) {
22
22
  resolve(buildOutput(activatedFeatures[this.agentIdentifier]));
23
23
  } else {
@@ -33,6 +33,9 @@ export class AggregateBase extends FeatureBase {
33
33
  });
34
34
  }
35
35
  });
36
+ return flagsPromise.catch(err => {
37
+ this.ee.emit('internal-error', [err]);
38
+ });
36
39
  }
37
40
  drain() {
38
41
  drain(this.agentIdentifier, this.featureName);
@@ -11,7 +11,7 @@ import { isBrowserScope } from '../../common/constants/runtime';
11
11
  import { warn } from '../../common/util/console';
12
12
  import { FEATURE_NAMES } from '../../loaders/features/features';
13
13
  import { getConfigurationValue } from '../../common/config/config';
14
- import { canImportReplayAgg } from '../session_replay/shared/utils';
14
+ import { hasReplayPrerequisite } from '../session_replay/shared/utils';
15
15
  import { canEnableSessionTracking } from './feature-gates';
16
16
  import { single } from '../../common/util/invoke';
17
17
 
@@ -88,6 +88,7 @@ export class InstrumentBase extends FeatureBase {
88
88
  }
89
89
  } catch (e) {
90
90
  warn('A problem occurred when starting up session manager. This page will not start or extend any session.', e);
91
+ this.ee.emit('internal-error', [e]);
91
92
  if (this.featureName === FEATURE_NAMES.sessionReplay) this.abortHandler?.(); // SR should stop recording if session DNE
92
93
  }
93
94
 
@@ -131,7 +132,14 @@ export class InstrumentBase extends FeatureBase {
131
132
  * @returns
132
133
  */
133
134
  #shouldImportAgg(featureName, session) {
134
- if (featureName === FEATURE_NAMES.sessionReplay) return canImportReplayAgg(this.agentIdentifier, session);
135
- return true;
135
+ switch (featureName) {
136
+ case FEATURE_NAMES.sessionReplay:
137
+ // the session manager must be initialized successfully for Replay & Trace features
138
+ return hasReplayPrerequisite(this.agentIdentifier) && !!session;
139
+ case FEATURE_NAMES.sessionTrace:
140
+ return !!session;
141
+ default:
142
+ return true;
143
+ }
136
144
  }
137
145
  }
@@ -1,6 +1,5 @@
1
1
  export function hasReplayPrerequisite(agentId: any): boolean;
2
2
  export function isPreloadAllowed(agentId: any): boolean;
3
- export function canImportReplayAgg(agentId: any, sessionMgr: any): boolean;
4
3
  export function buildNRMetaNode(timestamp: any, timeKeeper: any): {
5
4
  originalTimestamp: any;
6
5
  correctedTimestamp: any;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/features/session_replay/shared/utils.js"],"names":[],"mappings":"AAIA,6DAIC;AAED,wDAEC;AAED,2EAGC;AAED;;;;;;;EAUC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/features/session_replay/shared/utils.js"],"names":[],"mappings":"AAIA,6DAIC;AAED,wDAEC;AAED;;;;;;;EAUC"}
@@ -1 +1 @@
1
- {"version":3,"file":"aggregate-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/aggregate-base.js"],"names":[],"mappings":"AAOA;IACE,4BAGC;IAED;;;;OAIG;IACH,yBAHW,MAAM,EAAE,gBAmBlB;IAED,cAGC;IADC,6BAAmB;IAGrB;;;OAGG;IACH,2BAqBC;CACF;4BAnE2B,gBAAgB"}
1
+ {"version":3,"file":"aggregate-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/aggregate-base.js"],"names":[],"mappings":"AAOA;IACE,4BAGC;IAED;;;;OAIG;IACH,yBAHW,MAAM,EAAE,gBAsBlB;IAED,cAGC;IADC,6BAAmB;IAGrB;;;OAGG;IACH,2BAqBC;CACF;4BAtE2B,gBAAgB"}
@@ -1 +1 @@
1
- {"version":3,"file":"instrument-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/instrument-base.js"],"names":[],"mappings":"AAiBA;;;GAGG;AACH;IACE;;;;;;;;OAQG;IACH,6BAPW,MAAM,cACN,OAAO,mCAAmC,EAAE,UAAU,eACtD,MAAM,8BAqChB;IA9BC,cAAgB;IAEhB,8IAA8I;IAC9I,cADW,WAAW,SAAS,CACF;IAE7B;;;MAGE;IACF,eAHU,OAAO,kBAAkB,EAAE,aAAa,CAGpB;IAE9B;;;MAGE;IACF,kCAAoC;IAiBtC;;;;;OAKG;IACH,mEAgDC;;CAYF;4BA5H2B,gBAAgB"}
1
+ {"version":3,"file":"instrument-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/instrument-base.js"],"names":[],"mappings":"AAiBA;;;GAGG;AACH;IACE;;;;;;;;OAQG;IACH,6BAPW,MAAM,cACN,OAAO,mCAAmC,EAAE,UAAU,eACtD,MAAM,8BAqChB;IA9BC,cAAgB;IAEhB,8IAA8I;IAC9I,cADW,WAAW,SAAS,CACF;IAE7B;;;MAGE;IACF,eAHU,OAAO,kBAAkB,EAAE,aAAa,CAGpB;IAE9B;;;MAGE;IACF,kCAAoC;IAiBtC;;;;;OAKG;IACH,mEAiDC;;CAkBF;4BAnI2B,gBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.261.0",
3
+ "version": "1.261.2",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -28,7 +28,7 @@ export class Instrument extends InstrumentBase {
28
28
  } catch (err) { }
29
29
 
30
30
  if (hasReplayPrerequisite(agentIdentifier)) {
31
- this.ee.on('recordReplay', () => this.#apiStartOrRestartReplay())
31
+ this.ee.on(SR_EVENT_EMITTER_TYPES.RECORD, () => this.#apiStartOrRestartReplay())
32
32
  }
33
33
 
34
34
  if (this.#canPreloadRecorder(session)) {
@@ -12,11 +12,6 @@ export function isPreloadAllowed (agentId) {
12
12
  return getConfigurationValue(agentId, 'session_replay.preload') === true && hasReplayPrerequisite(agentId)
13
13
  }
14
14
 
15
- export function canImportReplayAgg (agentId, sessionMgr) {
16
- if (!hasReplayPrerequisite(agentId)) return false
17
- return !!sessionMgr?.isNew || !!sessionMgr?.state.sessionReplayMode // Session Replay should only try to run if already running from a previous page, or at the beginning of a session
18
- }
19
-
20
15
  export function buildNRMetaNode (timestamp, timeKeeper) {
21
16
  const correctedTimestamp = timeKeeper.correctAbsoluteTimestamp(timestamp)
22
17
  return {
@@ -1 +1,3 @@
1
- export const setupAgentSession = jest.fn()
1
+ export const setupAgentSession = jest.fn(() => {
2
+ return {}
3
+ })
@@ -5,7 +5,8 @@ export const FeatureBase = jest.fn(function (agentIdentifier, aggregator, featur
5
5
 
6
6
  this.ee = {
7
7
  abort: jest.fn(),
8
- on: jest.fn()
8
+ on: jest.fn(),
9
+ emit: jest.fn()
9
10
  }
10
11
  this.blocked = false
11
12
  })
@@ -17,7 +17,7 @@ export class AggregateBase extends FeatureBase {
17
17
  * @returns {Promise}
18
18
  */
19
19
  waitForFlags (flagNames = []) {
20
- return new Promise((resolve, reject) => {
20
+ const flagsPromise = new Promise((resolve, reject) => {
21
21
  if (activatedFeatures[this.agentIdentifier]) {
22
22
  resolve(buildOutput(activatedFeatures[this.agentIdentifier]))
23
23
  } else {
@@ -32,6 +32,9 @@ export class AggregateBase extends FeatureBase {
32
32
  })
33
33
  }
34
34
  })
35
+ return flagsPromise.catch(err => {
36
+ this.ee.emit('internal-error', [err])
37
+ })
35
38
  }
36
39
 
37
40
  drain () {
@@ -11,7 +11,7 @@ import { isBrowserScope } from '../../common/constants/runtime'
11
11
  import { warn } from '../../common/util/console'
12
12
  import { FEATURE_NAMES } from '../../loaders/features/features'
13
13
  import { getConfigurationValue } from '../../common/config/config'
14
- import { canImportReplayAgg } from '../session_replay/shared/utils'
14
+ import { hasReplayPrerequisite } from '../session_replay/shared/utils'
15
15
  import { canEnableSessionTracking } from './feature-gates'
16
16
  import { single } from '../../common/util/invoke'
17
17
 
@@ -86,6 +86,7 @@ export class InstrumentBase extends FeatureBase {
86
86
  }
87
87
  } catch (e) {
88
88
  warn('A problem occurred when starting up session manager. This page will not start or extend any session.', e)
89
+ this.ee.emit('internal-error', [e])
89
90
  if (this.featureName === FEATURE_NAMES.sessionReplay) this.abortHandler?.() // SR should stop recording if session DNE
90
91
  }
91
92
 
@@ -126,7 +127,13 @@ export class InstrumentBase extends FeatureBase {
126
127
  * @returns
127
128
  */
128
129
  #shouldImportAgg (featureName, session) {
129
- if (featureName === FEATURE_NAMES.sessionReplay) return canImportReplayAgg(this.agentIdentifier, session)
130
- return true
130
+ switch (featureName) {
131
+ case FEATURE_NAMES.sessionReplay: // the session manager must be initialized successfully for Replay & Trace features
132
+ return hasReplayPrerequisite(this.agentIdentifier) && !!session
133
+ case FEATURE_NAMES.sessionTrace:
134
+ return !!session
135
+ default:
136
+ return true
137
+ }
131
138
  }
132
139
  }
@@ -1 +0,0 @@
1
- export const canImportReplayAgg = jest.fn()