@newrelic/browser-agent 1.312.1-rc.3 → 1.312.1-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.312.1-rc.3";
20
+ const VERSION = exports.VERSION = "1.312.1-rc.5";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.312.1-rc.3";
20
+ const VERSION = exports.VERSION = "1.312.1-rc.5";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.TimeKeeper = void 0;
7
+ var _constants = require("../../features/metrics/constants");
7
8
  var _runtime = require("../constants/runtime");
8
9
  var _monkeyPatched = require("../util/monkey-patched");
10
+ var _handle = require("../event-emitter/handle");
11
+ var _features = require("../../loaders/features/features");
9
12
  /**
10
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
13
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
11
14
  * SPDX-License-Identifier: Apache-2.0
12
15
  */
13
16
 
@@ -42,11 +45,31 @@ class TimeKeeper {
42
45
  * @type {boolean}
43
46
  */
44
47
  #ready = false;
48
+ #reportedDrift = false;
45
49
  constructor(sessionObj) {
46
50
  this.#session = sessionObj;
47
51
  this.processStoredDiff();
48
52
  (0, _monkeyPatched.isNative)(performance.now, Date.now); // will warn the user if these are not native functions. We need these to be native for time in the agent to be accurate in general.
49
53
  }
54
+ #detectDrift() {
55
+ if (this.#reportedDrift) return;
56
+ try {
57
+ // Drift detection: measures if performance.now() and Date.now() have become desynchronized
58
+ // This can happen when a machine sleeps and the performance timer freezes while Date continues
59
+ // this can also happen when a user sets their clock forward during the page lifecycle,
60
+ // but we have no way of distinguishing that from actual clock drift so we will just treat it as drift.
61
+ // In either case, the performance timestamps would be inaccurate at that point so we want to detect and report a count of it.
62
+ // We only detect positive drift (performance clock falling behind Date clock)
63
+ // Note: localTimeDiff (server time offset) is NOT part of drift - that's a legitimate offset
64
+ const drift = Date.now() - _runtime.originTime - performance.now();
65
+ if (drift > 1000) {
66
+ this.#reportedDrift = true;
67
+ (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ['Generic/TimeKeeper/ClockDrift/Detected', drift], undefined, _features.FEATURE_NAMES.metrics, this.#session.agentRef.ee);
68
+ }
69
+ } catch (err) {
70
+ // Silently ignore drift detection errors to avoid breaking normal operation
71
+ }
72
+ }
50
73
  get ready() {
51
74
  return this.#ready;
52
75
  }
@@ -91,6 +114,7 @@ class TimeKeeper {
91
114
  * @returns {number} Corrected unix/epoch timestamp
92
115
  */
93
116
  convertRelativeTimestamp(relativeTime) {
117
+ this.#detectDrift();
94
118
  return _runtime.originTime + relativeTime;
95
119
  }
96
120
 
@@ -101,6 +125,7 @@ class TimeKeeper {
101
125
  * @returns {number}
102
126
  */
103
127
  convertAbsoluteTimestamp(timestamp) {
128
+ this.#detectDrift();
104
129
  return timestamp - _runtime.originTime;
105
130
  }
106
131
 
@@ -110,6 +135,7 @@ class TimeKeeper {
110
135
  * @return {number} Corrected unix/epoch timestamp
111
136
  */
112
137
  correctAbsoluteTimestamp(timestamp) {
138
+ this.#detectDrift();
113
139
  return timestamp - this.#localTimeDiff;
114
140
  }
115
141
 
@@ -119,6 +145,7 @@ class TimeKeeper {
119
145
  * @returns {number}
120
146
  */
121
147
  correctRelativeTimestamp(relativeTime) {
148
+ this.#detectDrift();
122
149
  return this.correctAbsoluteTimestamp(this.convertRelativeTimestamp(relativeTime));
123
150
  }
124
151
 
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.312.1-rc.3";
14
+ export const VERSION = "1.312.1-rc.5";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.312.1-rc.3";
14
+ export const VERSION = "1.312.1-rc.5";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -1,9 +1,12 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
+ import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants';
5
6
  import { originTime } from '../constants/runtime';
6
7
  import { isNative } from '../util/monkey-patched';
8
+ import { handle } from '../event-emitter/handle';
9
+ import { FEATURE_NAMES } from '../../loaders/features/features';
7
10
 
8
11
  /**
9
12
  * Class used to adjust the timestamp of harvested data to New Relic server time. This
@@ -36,11 +39,31 @@ export class TimeKeeper {
36
39
  * @type {boolean}
37
40
  */
38
41
  #ready = false;
42
+ #reportedDrift = false;
39
43
  constructor(sessionObj) {
40
44
  this.#session = sessionObj;
41
45
  this.processStoredDiff();
42
46
  isNative(performance.now, Date.now); // will warn the user if these are not native functions. We need these to be native for time in the agent to be accurate in general.
43
47
  }
48
+ #detectDrift() {
49
+ if (this.#reportedDrift) return;
50
+ try {
51
+ // Drift detection: measures if performance.now() and Date.now() have become desynchronized
52
+ // This can happen when a machine sleeps and the performance timer freezes while Date continues
53
+ // this can also happen when a user sets their clock forward during the page lifecycle,
54
+ // but we have no way of distinguishing that from actual clock drift so we will just treat it as drift.
55
+ // In either case, the performance timestamps would be inaccurate at that point so we want to detect and report a count of it.
56
+ // We only detect positive drift (performance clock falling behind Date clock)
57
+ // Note: localTimeDiff (server time offset) is NOT part of drift - that's a legitimate offset
58
+ const drift = Date.now() - originTime - performance.now();
59
+ if (drift > 1000) {
60
+ this.#reportedDrift = true;
61
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['Generic/TimeKeeper/ClockDrift/Detected', drift], undefined, FEATURE_NAMES.metrics, this.#session.agentRef.ee);
62
+ }
63
+ } catch (err) {
64
+ // Silently ignore drift detection errors to avoid breaking normal operation
65
+ }
66
+ }
44
67
  get ready() {
45
68
  return this.#ready;
46
69
  }
@@ -85,6 +108,7 @@ export class TimeKeeper {
85
108
  * @returns {number} Corrected unix/epoch timestamp
86
109
  */
87
110
  convertRelativeTimestamp(relativeTime) {
111
+ this.#detectDrift();
88
112
  return originTime + relativeTime;
89
113
  }
90
114
 
@@ -95,6 +119,7 @@ export class TimeKeeper {
95
119
  * @returns {number}
96
120
  */
97
121
  convertAbsoluteTimestamp(timestamp) {
122
+ this.#detectDrift();
98
123
  return timestamp - originTime;
99
124
  }
100
125
 
@@ -104,6 +129,7 @@ export class TimeKeeper {
104
129
  * @return {number} Corrected unix/epoch timestamp
105
130
  */
106
131
  correctAbsoluteTimestamp(timestamp) {
132
+ this.#detectDrift();
107
133
  return timestamp - this.#localTimeDiff;
108
134
  }
109
135
 
@@ -113,6 +139,7 @@ export class TimeKeeper {
113
139
  * @returns {number}
114
140
  */
115
141
  correctRelativeTimestamp(relativeTime) {
142
+ this.#detectDrift();
116
143
  return this.correctAbsoluteTimestamp(this.convertRelativeTimestamp(relativeTime));
117
144
  }
118
145
 
@@ -1 +1 @@
1
- {"version":3,"file":"time-keeper.d.ts","sourceRoot":"","sources":["../../../../src/common/timing/time-keeper.js"],"names":[],"mappings":"AAOA;;;;GAIG;AACH;IA2BE,6BAIC;IAED,qBAEC;IAED,kCAEC;IAED,4BAEC;IAED;;;;;;OAMG;IACH,8BALsB,cAAc,aACf,MAAM,WACR,MAAM,gBACD,MAAM,QAqB7B;IAED;;;;;OAKG;IACH,uCAHwB,MAAM,GACjB,MAAM,CAIlB;IAED;;;;;OAKG;IACH,0CAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,oCAHqB,MAAM,GACf,MAAM,CAIjB;IAED;;;;OAIG;IACH,uCAHW,mBAAmB,GACjB,MAAM,CAIlB;IAED,+FAA+F;IAC/F,0BASC;;CACF"}
1
+ {"version":3,"file":"time-keeper.d.ts","sourceRoot":"","sources":["../../../../src/common/timing/time-keeper.js"],"names":[],"mappings":"AAUA;;;;GAIG;AACH;IA6BE,6BAIC;IAsBD,qBAEC;IAED,kCAEC;IAED,4BAEC;IAED;;;;;;OAMG;IACH,8BALsB,cAAc,aACf,MAAM,WACR,MAAM,gBACD,MAAM,QAqB7B;IAED;;;;;OAKG;IACH,uCAHwB,MAAM,GACjB,MAAM,CAKlB;IAED;;;;;OAKG;IACH,0CAFa,MAAM,CAKlB;IAED;;;;OAIG;IACH,oCAHqB,MAAM,GACf,MAAM,CAKjB;IAED;;;;OAIG;IACH,uCAHW,mBAAmB,GACjB,MAAM,CAKlB;IAED,+FAA+F;IAC/F,0BASC;;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.312.1-rc.3",
3
+ "version": "1.312.1-rc.5",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -1,9 +1,12 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
+ import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants'
5
6
  import { originTime } from '../constants/runtime'
6
7
  import { isNative } from '../util/monkey-patched'
8
+ import { handle } from '../event-emitter/handle'
9
+ import { FEATURE_NAMES } from '../../loaders/features/features'
7
10
 
8
11
  /**
9
12
  * Class used to adjust the timestamp of harvested data to New Relic server time. This
@@ -37,12 +40,34 @@ export class TimeKeeper {
37
40
  */
38
41
  #ready = false
39
42
 
43
+ #reportedDrift = false
44
+
40
45
  constructor (sessionObj) {
41
46
  this.#session = sessionObj
42
47
  this.processStoredDiff()
43
48
  isNative(performance.now, Date.now) // will warn the user if these are not native functions. We need these to be native for time in the agent to be accurate in general.
44
49
  }
45
50
 
51
+ #detectDrift () {
52
+ if (this.#reportedDrift) return
53
+ try {
54
+ // Drift detection: measures if performance.now() and Date.now() have become desynchronized
55
+ // This can happen when a machine sleeps and the performance timer freezes while Date continues
56
+ // this can also happen when a user sets their clock forward during the page lifecycle,
57
+ // but we have no way of distinguishing that from actual clock drift so we will just treat it as drift.
58
+ // In either case, the performance timestamps would be inaccurate at that point so we want to detect and report a count of it.
59
+ // We only detect positive drift (performance clock falling behind Date clock)
60
+ // Note: localTimeDiff (server time offset) is NOT part of drift - that's a legitimate offset
61
+ const drift = (Date.now() - originTime) - performance.now()
62
+ if (drift > 1000) {
63
+ this.#reportedDrift = true
64
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['Generic/TimeKeeper/ClockDrift/Detected', drift], undefined, FEATURE_NAMES.metrics, this.#session.agentRef.ee)
65
+ }
66
+ } catch (err) {
67
+ // Silently ignore drift detection errors to avoid breaking normal operation
68
+ }
69
+ }
70
+
46
71
  get ready () {
47
72
  return this.#ready
48
73
  }
@@ -90,6 +115,7 @@ export class TimeKeeper {
90
115
  * @returns {number} Corrected unix/epoch timestamp
91
116
  */
92
117
  convertRelativeTimestamp (relativeTime) {
118
+ this.#detectDrift()
93
119
  return originTime + relativeTime
94
120
  }
95
121
 
@@ -100,6 +126,7 @@ export class TimeKeeper {
100
126
  * @returns {number}
101
127
  */
102
128
  convertAbsoluteTimestamp (timestamp) {
129
+ this.#detectDrift()
103
130
  return timestamp - originTime
104
131
  }
105
132
 
@@ -109,6 +136,7 @@ export class TimeKeeper {
109
136
  * @return {number} Corrected unix/epoch timestamp
110
137
  */
111
138
  correctAbsoluteTimestamp (timestamp) {
139
+ this.#detectDrift()
112
140
  return timestamp - this.#localTimeDiff
113
141
  }
114
142
 
@@ -118,6 +146,7 @@ export class TimeKeeper {
118
146
  * @returns {number}
119
147
  */
120
148
  correctRelativeTimestamp (relativeTime) {
149
+ this.#detectDrift()
121
150
  return this.correctAbsoluteTimestamp(this.convertRelativeTimestamp(relativeTime))
122
151
  }
123
152