@cloudcare/browser-rum 3.0.5 → 3.0.7

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.
Files changed (58) hide show
  1. package/bundle/dataflux-rum.js +1 -1
  2. package/cjs/boot/buildEnv.js +1 -1
  3. package/cjs/boot/recorderApi.js +1 -1
  4. package/cjs/boot/rum.js +16 -7
  5. package/cjs/boot/rumPublicApi.js +27 -55
  6. package/cjs/domain/assembly.js +2 -2
  7. package/cjs/domain/configuration.js +1 -0
  8. package/cjs/domain/contexts/commonContext.js +14 -0
  9. package/cjs/domain/performanceCollection.js +3 -3
  10. package/cjs/domain/replay/record/serialize.js +7 -5
  11. package/cjs/domain/replay/segmentCollection/segmentCollection.js +2 -2
  12. package/cjs/domain/replay/segmentCollection/startDeflateWorker.js +2 -2
  13. package/cjs/domain/rumEventsCollection/actions/clickChain.js +3 -3
  14. package/cjs/domain/rumEventsCollection/view/trackInitialViewTimings.js +34 -10
  15. package/cjs/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  16. package/cjs/domain/rumEventsCollection/view/trackViews.js +45 -67
  17. package/cjs/domain/rumEventsCollection/view/viewCollection.js +2 -1
  18. package/cjs/domain/rumSessionManager.js +3 -1
  19. package/cjs/domain/waitPageActivityEnd.js +9 -9
  20. package/cjs/transport/startRumBatch.js +20 -6
  21. package/esm/boot/buildEnv.js +1 -1
  22. package/esm/boot/recorderApi.js +1 -1
  23. package/esm/boot/rum.js +15 -7
  24. package/esm/boot/rumPublicApi.js +25 -54
  25. package/esm/domain/assembly.js +2 -2
  26. package/esm/domain/configuration.js +1 -0
  27. package/esm/domain/contexts/commonContext.js +7 -0
  28. package/esm/domain/performanceCollection.js +2 -2
  29. package/esm/domain/replay/record/serialize.js +7 -5
  30. package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
  31. package/esm/domain/replay/segmentCollection/startDeflateWorker.js +3 -3
  32. package/esm/domain/rumEventsCollection/actions/clickChain.js +1 -1
  33. package/esm/domain/rumEventsCollection/view/trackInitialViewTimings.js +33 -10
  34. package/esm/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  35. package/esm/domain/rumEventsCollection/view/trackViews.js +46 -68
  36. package/esm/domain/rumEventsCollection/view/viewCollection.js +2 -1
  37. package/esm/domain/rumSessionManager.js +3 -1
  38. package/esm/domain/waitPageActivityEnd.js +3 -3
  39. package/esm/transport/startRumBatch.js +21 -7
  40. package/package.json +31 -31
  41. package/src/boot/recorderApi.js +1 -0
  42. package/src/boot/rum.js +29 -9
  43. package/src/boot/rumPublicApi.js +37 -51
  44. package/src/domain/assembly.js +2 -2
  45. package/src/domain/configuration.js +4 -0
  46. package/src/domain/contexts/commonContext.js +11 -0
  47. package/src/domain/performanceCollection.js +4 -2
  48. package/src/domain/replay/record/serialize.js +6 -5
  49. package/src/domain/replay/segmentCollection/segmentCollection.js +3 -1
  50. package/src/domain/replay/segmentCollection/startDeflateWorker.js +8 -3
  51. package/src/domain/rumEventsCollection/actions/clickChain.js +6 -1
  52. package/src/domain/rumEventsCollection/view/trackInitialViewTimings.js +42 -11
  53. package/src/domain/rumEventsCollection/view/trackViewEventCounts.js +1 -1
  54. package/src/domain/rumEventsCollection/view/trackViews.js +69 -77
  55. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -1
  56. package/src/domain/rumSessionManager.js +3 -1
  57. package/src/domain/waitPageActivityEnd.js +8 -5
  58. package/src/transport/startRumBatch.js +35 -12
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildEnv = void 0;
7
7
  var buildEnv = {
8
- sdkVersion: '3.0.5',
8
+ sdkVersion: '3.0.7',
9
9
  sdkName: 'df_web_rum_sdk'
10
10
  };
11
11
  exports.buildEnv = buildEnv;
@@ -156,6 +156,6 @@ function isBrowserSupported() {
156
156
  return (// Array.from is a bit less supported by browsers than CSSSupportsRule, but has higher chances
157
157
  // to be polyfilled. Test for both to be more confident. We could add more things if we find out
158
158
  // this test is not sufficient.
159
- typeof Array.from === 'function' && typeof CSSSupportsRule === 'function' && 'forEach' in NodeList.prototype
159
+ typeof Array.from === 'function' && typeof CSSSupportsRule === 'function' && typeof URL.createObjectURL === 'function' && 'forEach' in NodeList.prototype
160
160
  );
161
161
  }
package/cjs/boot/rum.js CHANGED
@@ -34,6 +34,8 @@ var _urlContexts = require("../domain/contexts/urlContexts");
34
34
 
35
35
  var _viewContexts = require("../domain/contexts/viewContexts");
36
36
 
37
+ var _commonContext = require("../domain/contexts/commonContext");
38
+
37
39
  var _errorCollection = require("../domain/rumEventsCollection/error/errorCollection");
38
40
 
39
41
  var _viewCollection = require("../domain/rumEventsCollection/view/viewCollection");
@@ -42,7 +44,7 @@ var _requestCollection = require("../domain/requestCollection");
42
44
 
43
45
  var _resourceCollection = require("../domain/rumEventsCollection/resource/resourceCollection");
44
46
 
45
- function startRum(configuration, getCommonContext, recorderApi, initialViewOptions) {
47
+ function startRum(configuration, recorderApi, globalContextManager, userContextManager, initialViewOptions) {
46
48
  var lifeCycle = new _browserCore.LifeCycle();
47
49
 
48
50
  var reportError = function reportError(error) {
@@ -55,18 +57,21 @@ function startRum(configuration, getCommonContext, recorderApi, initialViewOptio
55
57
  pageExitObservable.subscribe(function (event) {
56
58
  lifeCycle.notify(_browserCore.LifeCycleEventType.PAGE_EXITED, event);
57
59
  });
58
- (0, _startRumBatch.startRumBatch)(configuration, lifeCycle, reportError, pageExitObservable);
59
60
  var session = (0, _rumSessionManager.startRumSessionManager)(configuration, lifeCycle);
61
+ var batch = (0, _startRumBatch.startRumBatch)(configuration, lifeCycle, reportError, pageExitObservable, session.expireObservable);
60
62
  var userSession = (0, _usr.startCacheUsrCache)(configuration);
61
63
  var domMutationObservable = (0, _domMutationCollection.createDOMMutationObservable)();
62
64
  var locationChangeObservable = (0, _locationChangeObservable.createLocationChangeObservable)(location);
63
65
 
64
- var _startRumEventCollection = startRumEventCollection(location, lifeCycle, configuration, session, userSession, locationChangeObservable, domMutationObservable, getCommonContext, reportError);
66
+ var _startRumEventCollection = startRumEventCollection(lifeCycle, configuration, location, session, userSession, locationChangeObservable, domMutationObservable, function () {
67
+ return (0, _commonContext.buildCommonContext)(globalContextManager, userContextManager, recorderApi);
68
+ }, reportError);
65
69
 
66
70
  var viewContexts = _startRumEventCollection.viewContexts;
67
71
  var urlContexts = _startRumEventCollection.urlContexts;
68
72
  var actionContexts = _startRumEventCollection.actionContexts;
69
73
  var foregroundContexts = _startRumEventCollection.foregroundContexts;
74
+ var addAction = _startRumEventCollection.addAction;
70
75
  (0, _longTaskCollection.startLongTaskCollection)(lifeCycle, session);
71
76
  (0, _resourceCollection.startResourceCollection)(lifeCycle, configuration);
72
77
 
@@ -82,7 +87,7 @@ function startRum(configuration, getCommonContext, recorderApi, initialViewOptio
82
87
  (0, _performanceCollection.startPerformanceCollection)(lifeCycle, configuration);
83
88
  var internalContext = (0, _internalContext.startInternalContext)(configuration.applicationId, session, viewContexts, actionContexts, urlContexts);
84
89
  return {
85
- addAction: _startRumEventCollection.addAction,
90
+ addAction: addAction,
86
91
  addError: addError,
87
92
  addTiming: addTiming,
88
93
  configuration: configuration,
@@ -90,11 +95,14 @@ function startRum(configuration, getCommonContext, recorderApi, initialViewOptio
90
95
  viewContexts: viewContexts,
91
96
  session: session,
92
97
  startView: startView,
98
+ stopSession: function stopSession() {
99
+ session.expire();
100
+ },
93
101
  getInternalContext: internalContext.get
94
102
  };
95
103
  }
96
104
 
97
- function startRumEventCollection(location, lifeCycle, configuration, sessionManager, userSessionManager, locationChangeObservable, domMutationObservable, getCommonContext, reportError) {
105
+ function startRumEventCollection(lifeCycle, configuration, location, sessionManager, userSessionManager, locationChangeObservable, domMutationObservable, buildCommonContext, reportError) {
98
106
  var viewContexts = (0, _viewContexts.startViewContexts)(lifeCycle);
99
107
  var urlContexts = (0, _urlContexts.startUrlContexts)(lifeCycle, locationChangeObservable, location);
100
108
  var foregroundContexts = (0, _foregroundContexts.startForegroundContexts)();
@@ -102,12 +110,13 @@ function startRumEventCollection(location, lifeCycle, configuration, sessionMana
102
110
  var _startActionCollection = (0, _actionCollection.startActionCollection)(lifeCycle, domMutationObservable, configuration, foregroundContexts);
103
111
 
104
112
  var actionContexts = _startActionCollection.actionContexts;
105
- (0, _assembly.startRumAssembly)(configuration, lifeCycle, sessionManager, userSessionManager, viewContexts, urlContexts, actionContexts, getCommonContext, reportError);
113
+ var addAction = _startActionCollection.addAction;
114
+ (0, _assembly.startRumAssembly)(configuration, lifeCycle, sessionManager, userSessionManager, viewContexts, urlContexts, actionContexts, buildCommonContext, reportError);
106
115
  return {
107
116
  viewContexts: viewContexts,
108
117
  urlContexts: urlContexts,
109
118
  foregroundContexts: foregroundContexts,
110
- addAction: _startActionCollection.addAction,
119
+ addAction: addAction,
111
120
  actionContexts: actionContexts,
112
121
  stop: function stop() {
113
122
  viewContexts.stop();
@@ -9,12 +9,27 @@ var _browserCore = require("@cloudcare/browser-core");
9
9
 
10
10
  var _configuration = require("../domain/configuration");
11
11
 
12
+ var _commonContext = require("../domain/contexts/commonContext");
13
+
12
14
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
13
15
 
14
16
  function makeRumPublicApi(startRumImpl, recorderApi) {
15
17
  var isAlreadyInitialized = false;
16
- var globalContextManager = (0, _browserCore.createContextManager)();
17
- var userContextManager = (0, _browserCore.createContextManager)();
18
+ var globalContextManager = (0, _browserCore.createContextManager)(_browserCore.CustomerDataType.GlobalContext);
19
+ var userContextManager = (0, _browserCore.createContextManager)(_browserCore.CustomerDataType.User);
20
+
21
+ var getInternalContextStrategy = function getInternalContextStrategy() {
22
+ return undefined;
23
+ };
24
+
25
+ var getInitConfigurationStrategy = function getInitConfigurationStrategy() {
26
+ return undefined;
27
+ };
28
+
29
+ var stopSessionStrategy = function stopSessionStrategy() {
30
+ return (0, _browserCore.noop)();
31
+ };
32
+
18
33
  var bufferApiCalls = new _browserCore.BoundedBuffer();
19
34
 
20
35
  var _addTimingStrategy = function addTimingStrategy(name, time) {
@@ -39,10 +54,7 @@ function makeRumPublicApi(startRumImpl, recorderApi) {
39
54
 
40
55
  var _addActionStrategy = function addActionStrategy(action, commonContext) {
41
56
  if (typeof commonContext == 'undefined') {
42
- commonContext = {
43
- context: globalContextManager.getContext(),
44
- user: userContextManager.getContext()
45
- };
57
+ commonContext = (0, _commonContext.buildCommonContext)(globalContextManager, userContextManager, recorderApi);
46
58
  }
47
59
 
48
60
  bufferApiCalls.add(function () {
@@ -52,10 +64,7 @@ function makeRumPublicApi(startRumImpl, recorderApi) {
52
64
 
53
65
  var _addErrorStrategy = function addErrorStrategy(providedError, commonContext) {
54
66
  if (typeof commonContext == 'undefined') {
55
- commonContext = {
56
- context: globalContextManager.getContext(),
57
- user: userContextManager.getContext()
58
- };
67
+ commonContext = (0, _commonContext.buildCommonContext)(globalContextManager, userContextManager, recorderApi);
59
68
  }
60
69
 
61
70
  bufferApiCalls.add(function () {
@@ -63,14 +72,6 @@ function makeRumPublicApi(startRumImpl, recorderApi) {
63
72
  });
64
73
  };
65
74
 
66
- var getInternalContextStrategy = function getInternalContextStrategy() {
67
- return undefined;
68
- };
69
-
70
- var getInitConfigurationStrategy = function getInitConfigurationStrategy() {
71
- return undefined;
72
- };
73
-
74
75
  function initRum(initConfiguration) {
75
76
  if (!canHandleSession(initConfiguration)) {
76
77
  return;
@@ -110,18 +111,13 @@ function makeRumPublicApi(startRumImpl, recorderApi) {
110
111
  }
111
112
 
112
113
  function doStartRum(configuration, initialViewOptions) {
113
- var startRumResults = startRumImpl(configuration, function () {
114
- return {
115
- user: userContextManager.getContext(),
116
- context: globalContextManager.getContext(),
117
- hasReplay: recorderApi.isRecording() ? true : undefined
118
- };
119
- }, recorderApi, initialViewOptions);
114
+ var startRumResults = startRumImpl(configuration, recorderApi, globalContextManager, userContextManager, initialViewOptions);
120
115
  _startViewStrategy = startRumResults.startView;
121
116
  _addActionStrategy = startRumResults.addAction;
122
117
  _addErrorStrategy = startRumResults.addError;
123
118
  _addTimingStrategy = startRumResults.addTiming;
124
119
  getInternalContextStrategy = startRumResults.getInternalContext;
120
+ stopSessionStrategy = startRumResults.stopSession;
125
121
  bufferApiCalls.drain();
126
122
  recorderApi.onRumStart(startRumResults.lifeCycle, configuration, startRumResults.session, startRumResults.viewContexts);
127
123
  }
@@ -170,13 +166,6 @@ function makeRumPublicApi(startRumImpl, recorderApi) {
170
166
  type: _browserCore.ActionType.CUSTOM
171
167
  });
172
168
  },
173
-
174
- /**
175
- * @deprecated use addAction instead
176
- */
177
- // addUserAction: function (name, context) {
178
- // rumPublicApi.addAction(name, context)
179
- // },
180
169
  addError: function addError(error, context) {
181
170
  var handlingStack = (0, _browserCore.createHandlingStack)();
182
171
 
@@ -191,17 +180,15 @@ function makeRumPublicApi(startRumImpl, recorderApi) {
191
180
  _addTimingStrategy(name, time);
192
181
  },
193
182
  setUser: function setUser(newUser) {
194
- if (_typeof(newUser) !== 'object' || !newUser) {
195
- _browserCore.display.error('Unsupported user:', newUser);
196
- } else {
197
- userContextManager.setContext(sanitizeUser(newUser));
183
+ if ((0, _browserCore.checkUser)(newUser)) {
184
+ userContextManager.setContext((0, _browserCore.sanitizeUser)(newUser));
198
185
  }
199
186
  },
200
187
  getUser: userContextManager.getContext,
201
188
  setUserProperty: function setUserProperty(key, property) {
202
189
  var newUser = {};
203
190
  newUser[key] = property;
204
- var sanitizedProperty = sanitizeUser(newUser)[key];
191
+ var sanitizedProperty = (0, _browserCore.sanitizeUser)(newUser)[key];
205
192
  userContextManager.setContextProperty(key, sanitizedProperty);
206
193
  },
207
194
  removeUserProperty: userContextManager.removeContextProperty,
@@ -210,29 +197,14 @@ function makeRumPublicApi(startRumImpl, recorderApi) {
210
197
  removeUser: userContextManager.clearContext,
211
198
  clearUser: userContextManager.clearContext,
212
199
  startView: startView,
200
+ stopSession: function stopSession() {
201
+ stopSessionStrategy();
202
+ },
213
203
  startSessionReplayRecording: recorderApi.start,
214
204
  stopSessionReplayRecording: recorderApi.stop
215
205
  });
216
206
  return rumPublicApi;
217
207
 
218
- function sanitizeUser(newUser) {
219
- var shallowClonedUser = (0, _browserCore.assign)(newUser, {});
220
-
221
- if ('id' in shallowClonedUser) {
222
- shallowClonedUser.id = String(shallowClonedUser.id);
223
- }
224
-
225
- if ('name' in shallowClonedUser) {
226
- shallowClonedUser.name = String(shallowClonedUser.name);
227
- }
228
-
229
- if ('email' in shallowClonedUser) {
230
- shallowClonedUser.email = String(shallowClonedUser.email);
231
- }
232
-
233
- return shallowClonedUser;
234
- }
235
-
236
208
  function canHandleSession(initConfiguration) {
237
209
  if (!(0, _browserCore.areCookiesAuthorized)((0, _browserCore.buildCookieOptions)(initConfiguration))) {
238
210
  _browserCore.display.warn('Cookies are not authorized, we will not send any data.');
@@ -16,7 +16,7 @@ var VIEW_EVENTS_MODIFIABLE_FIELD_PATHS = [// Fields with sensitive data
16
16
  var OTHER_EVENTS_MODIFIABLE_FIELD_PATHS = VIEW_EVENTS_MODIFIABLE_FIELD_PATHS.concat([// User-customizable field
17
17
  'tags']);
18
18
 
19
- function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionManager, viewContexts, urlContexts, actionContexts, getCommonContext, reportError) {
19
+ function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionManager, viewContexts, urlContexts, actionContexts, buildCommonContext, reportError) {
20
20
  var eventRateLimiters = {};
21
21
  eventRateLimiters[_browserCore.RumEventType.ERROR] = (0, _browserCore.createEventRateLimiter)(_browserCore.RumEventType.ERROR, configuration.eventRateLimiterThreshold, reportError);
22
22
  eventRateLimiters[_browserCore.RumEventType.ACTION] = (0, _browserCore.createEventRateLimiter)(_browserCore.RumEventType.ACTION, configuration.eventRateLimiterThreshold, reportError);
@@ -32,7 +32,7 @@ function startRumAssembly(configuration, lifeCycle, sessionManager, userSessionM
32
32
 
33
33
  if (session && viewContext && urlContext) {
34
34
  var actionId = actionContexts.findActionId(startTime);
35
- var commonContext = savedCommonContext || getCommonContext();
35
+ var commonContext = savedCommonContext || buildCommonContext();
36
36
  var rumContext = {
37
37
  _dd: {
38
38
  sdkName: configuration.sdkName,
@@ -68,6 +68,7 @@ function validateAndBuildRumConfiguration(initConfiguration) {
68
68
  return (0, _browserCore.assign)({
69
69
  applicationId: initConfiguration.applicationId,
70
70
  actionNameAttribute: initConfiguration.actionNameAttribute,
71
+ sessionReplaySampleRate: (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.sessionReplaySampleRate, 100),
71
72
  tracingSampleRate: initConfiguration.tracingSampleRate,
72
73
  allowedTracingOrigins: (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.allowedTracingOrigins || initConfiguration.allowedDDTracingOrigins, []),
73
74
  excludedActivityUrls: (0, _browserCore.isNullUndefinedDefaultValue)(initConfiguration.excludedActivityUrls, []),
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildCommonContext = buildCommonContext;
7
+
8
+ function buildCommonContext(globalContextManager, userContextManager, recorderApi) {
9
+ return {
10
+ context: globalContextManager.getContext(),
11
+ user: userContextManager.getContext(),
12
+ hasReplay: recorderApi.isRecording() ? true : undefined
13
+ };
14
+ }
@@ -29,7 +29,7 @@ function startPerformanceCollection(lifeCycle, configuration) {
29
29
  var performanceEntries = performance.getEntries(); // Because the performance entry list can be quite large
30
30
  // delay the computation to prevent the SDK from blocking the main thread on init
31
31
 
32
- setTimeout(function () {
32
+ (0, _browserCore.setTimeout)(function () {
33
33
  handleRumPerformanceEntries(lifeCycle, configuration, performanceEntries);
34
34
  });
35
35
  }
@@ -68,7 +68,7 @@ function startPerformanceCollection(lifeCycle, configuration) {
68
68
 
69
69
  if (supportPerformanceObject() && 'addEventListener' in performance) {
70
70
  // https://bugzilla.mozilla.org/show_bug.cgi?id=1559377
71
- performance.addEventListener('resourcetimingbufferfull', function () {
71
+ (0, _browserCore.addEventListener)(performance, 'resourcetimingbufferfull', function () {
72
72
  performance.clearResourceTimings();
73
73
  });
74
74
  }
@@ -122,7 +122,7 @@ function retrieveNavigationTiming(callback) {
122
122
 
123
123
  (0, _browserCore.runOnReadyState)('complete', function () {
124
124
  // Send it a bit after the actual load event, so the "loadEventEnd" timing is accurate
125
- setTimeout(sendFakeTiming);
125
+ (0, _browserCore.setTimeout)(sendFakeTiming);
126
126
  });
127
127
  }
128
128
  /**
@@ -355,17 +355,19 @@ function isSVGElement(el) {
355
355
  }
356
356
 
357
357
  function transformAttribute(doc, tagName, name, value) {
358
- if (name === 'src' || name === 'href' && value && !(tagName === 'use' && value[0] === '#')) {
358
+ if (!value) return value;
359
+
360
+ if (name === 'src' || name === 'href' && !(tagName === 'use' && value[0] === '#')) {
359
361
  return (0, _serializationUtils.absoluteToDoc)(doc, value);
360
- } else if (name === 'xlink:href' && value && value[0] !== '#') {
362
+ } else if (name === 'xlink:href' && value[0] !== '#') {
361
363
  return (0, _serializationUtils.absoluteToDoc)(doc, value);
362
364
  } else if (name === 'background' && value && (tagName === 'table' || tagName === 'td' || tagName === 'th')) {
363
365
  return (0, _serializationUtils.absoluteToDoc)(doc, value);
364
- } else if (name === 'srcset' && value) {
366
+ } else if (name === 'srcset') {
365
367
  return (0, _serializationUtils.getAbsoluteSrcsetString)(doc, value);
366
- } else if (name === 'style' && value) {
368
+ } else if (name === 'style') {
367
369
  return (0, _serializationUtils.switchToAbsoluteUrl)(value, getHref());
368
- } else if (tagName === 'object' && name === 'data' && value) {
370
+ } else if (tagName === 'object' && name === 'data') {
369
371
  return (0, _serializationUtils.absoluteToDoc)(doc, value);
370
372
  } else {
371
373
  return value;
@@ -78,7 +78,7 @@ function doStartSegmentCollection(lifeCycle, getSegmentContext, httpRequest, wor
78
78
  function flushSegment(flushReason) {
79
79
  if (state.status === SegmentCollectionStatus.SegmentPending) {
80
80
  state.segment.flush(flushReason);
81
- clearTimeout(state.expirationTimeoutId);
81
+ (0, _browserCore.clearTimeout)(state.expirationTimeoutId);
82
82
  }
83
83
 
84
84
  if (flushReason !== 'stop') {
@@ -116,7 +116,7 @@ function doStartSegmentCollection(lifeCycle, getSegmentContext, httpRequest, wor
116
116
  state = {
117
117
  status: SegmentCollectionStatus.SegmentPending,
118
118
  segment: segment,
119
- expirationTimeoutId: setTimeout(function () {
119
+ expirationTimeoutId: (0, _browserCore.setTimeout)(function () {
120
120
  flushSegment('segment_duration_limit');
121
121
  }, SEGMENT_DURATION_LIMIT)
122
122
  };
@@ -77,8 +77,8 @@ function doStartDeflateWorker(createDeflateWorkerImpl) {
77
77
 
78
78
  try {
79
79
  var worker = createDeflateWorkerImpl();
80
- worker.addEventListener('error', onError);
81
- worker.addEventListener('message', function (event) {
80
+ (0, _browserCore.addEventListener)(worker, 'error', onError);
81
+ (0, _browserCore.addEventListener)(worker, 'message', function (event) {
82
82
  var data = event.data;
83
83
 
84
84
  if (data.type === 'errored') {
@@ -27,8 +27,8 @@ function createClickChain(firstClick, onFinalize) {
27
27
  function appendClick(click) {
28
28
  click.stopObservable.subscribe(tryFinalize);
29
29
  bufferedClicks.push(click);
30
- clearTimeout(maxDurationBetweenClicksTimeout);
31
- maxDurationBetweenClicksTimeout = setTimeout(dontAcceptMoreClick, MAX_DURATION_BETWEEN_CLICKS);
30
+ (0, _browserCore.clearTimeout)(maxDurationBetweenClicksTimeout);
31
+ maxDurationBetweenClicksTimeout = (0, _browserCore.setTimeout)(dontAcceptMoreClick, MAX_DURATION_BETWEEN_CLICKS);
32
32
  }
33
33
 
34
34
  function tryFinalize() {
@@ -41,7 +41,7 @@ function createClickChain(firstClick, onFinalize) {
41
41
  }
42
42
 
43
43
  function dontAcceptMoreClick() {
44
- clearTimeout(maxDurationBetweenClicksTimeout);
44
+ (0, _browserCore.clearTimeout)(maxDurationBetweenClicksTimeout);
45
45
 
46
46
  if (status === ClickChainStatus.WaitingForMoreClicks) {
47
47
  status = ClickChainStatus.WaitingForClicksToStop;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TIMING_MAXIMUM_DELAY = void 0;
6
+ exports.TIMING_MAXIMUM_DELAY = exports.KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = void 0;
7
7
  exports.trackFirstContentfulPaint = trackFirstContentfulPaint;
8
8
  exports.trackFirstInputTimings = trackFirstInputTimings;
9
9
  exports.trackInitialViewTimings = trackInitialViewTimings;
@@ -17,17 +17,29 @@ var _trackFirstHidden = require("./trackFirstHidden");
17
17
  // Discard LCP and FCP timings above a certain delay to avoid incorrect data
18
18
  // It happens in some cases like sleep mode or some browser implementations
19
19
  var TIMING_MAXIMUM_DELAY = 10 * _browserCore.ONE_MINUTE;
20
+ /**
21
+ * The initial view can finish quickly, before some metrics can be produced (ex: before the page load
22
+ * event, or the first input). Also, we don't want to trigger a view update indefinitely, to avoid
23
+ * updates on views that ended a long time ago. Keep watching for metrics after the view ends for a
24
+ * limited amount of time.
25
+ */
26
+
20
27
  exports.TIMING_MAXIMUM_DELAY = TIMING_MAXIMUM_DELAY;
28
+ var KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = 5 * _browserCore.ONE_MINUTE;
29
+ exports.KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY = KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY;
21
30
 
22
- function trackInitialViewTimings(lifeCycle, callback) {
31
+ function trackInitialViewTimings(lifeCycle, setLoadEvent, scheduleViewUpdate) {
23
32
  var timings = {};
24
33
 
25
34
  function setTimings(newTimings) {
26
35
  timings = (0, _browserCore.extend)(timings, newTimings);
27
- callback(timings);
36
+ scheduleViewUpdate();
28
37
  }
29
38
 
30
- var _trackNavigationTimings = trackNavigationTimings(lifeCycle, setTimings);
39
+ var _trackNavigationTimings = trackNavigationTimings(lifeCycle, function (newTimings) {
40
+ setLoadEvent(newTimings.loadEvent);
41
+ setTimings(newTimings);
42
+ });
31
43
 
32
44
  var stopNavigationTracking = _trackNavigationTimings.stop;
33
45
 
@@ -55,12 +67,19 @@ function trackInitialViewTimings(lifeCycle, callback) {
55
67
  });
56
68
 
57
69
  var stopFIDTracking = _trackFirstInputTimings.stop;
70
+
71
+ function stop() {
72
+ stopNavigationTracking();
73
+ stopFCPTracking();
74
+ stopLCPTracking();
75
+ stopFIDTracking();
76
+ }
77
+
58
78
  return {
59
- stop: function stop() {
60
- stopNavigationTracking();
61
- stopFCPTracking();
62
- stopLCPTracking();
63
- stopFIDTracking();
79
+ stop: stop,
80
+ timings: timings,
81
+ scheduleStop: function scheduleStop() {
82
+ (0, _browserCore.setTimeout)(stop, KEEP_TRACKING_TIMINGS_AFTER_VIEW_DELAY);
64
83
  }
65
84
  };
66
85
  }
@@ -81,7 +100,12 @@ function trackNavigationTimings(lifeCycle, callback) {
81
100
  loadEventEnd: entry.loadEventEnd,
82
101
  loadEventStart: entry.loadEventStart,
83
102
  domContentLoadedEventEnd: entry.domContentLoadedEventEnd,
84
- domContentLoadedEventStart: entry.domContentLoadedEventStart
103
+ domContentLoadedEventStart: entry.domContentLoadedEventStart,
104
+ // In some cases the value reported is negative or is larger
105
+ // than the current page time. Ignore these cases:
106
+ // https://github.com/GoogleChrome/web-vitals/issues/137
107
+ // https://github.com/GoogleChrome/web-vitals/issues/162
108
+ firstByte: entry.responseStart >= 0 && entry.responseStart <= (0, _browserCore.relativeNow)() ? entry.responseStart : undefined
85
109
  });
86
110
  }
87
111
  }
@@ -38,7 +38,7 @@ function trackViewEventCounts(lifeCycle, viewId, onChange) {
38
38
 
39
39
  return {
40
40
  scheduleStop: function scheduleStop() {
41
- setTimeout(_trackEventCounts.stop, KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY);
41
+ (0, _browserCore.setTimeout)(_trackEventCounts.stop, KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY);
42
42
  },
43
43
  eventCounts: _trackEventCounts.eventCounts
44
44
  };