@sentry/replay 0.6.9 → 0.6.10

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 CHANGED
@@ -36,12 +36,33 @@ Sentry.init({
36
36
  // This sets the sample rate to be 10%. You may want this to be 100% while
37
37
  // in development and sample at a lower rate in production
38
38
  replaysSamplingRate: 0.1,
39
+
40
+ // Mask all text content with asterisks (*). Passes text
41
+ // content through to `maskTextFn` before sending to server.
42
+ //
43
+ // Defaults to true, uncomment to change
44
+ // maskAllText: true,
45
+
46
+ // Block all media elements (img, svg, video, object,
47
+ // picture, embed, map, audio)
48
+ //
49
+ // Defaults to true, uncomment to change
50
+ // blockAllMedia: true,
39
51
  })
40
52
  ],
41
53
  // ...
42
54
  });
43
55
  ```
44
56
 
57
+ ### Identifying Users
58
+
59
+ If you have only followed the above instructions to setup session replays, you will only see IP addresses in Sentry's UI. In order to associate a user identity to a session replay, use [`setUser`](https://docs.sentry.io/platforms/javascript/enriching-events/identify-user/).
60
+
61
+ ```javascript
62
+ import * as Sentry from "@sentry/browser";
63
+ Sentry.setUser({ email: "jane.doe@example.com" });
64
+ ```
65
+
45
66
  ### Start and Stop Recording
46
67
 
47
68
  Replay recording only starts automatically when it is included in the `integrations` key when calling `Sentry.init`. Otherwise you can initialize the plugin and manually call the `start()` method on the integration instance. To stop recording you can call the `stop()`.
@@ -30,16 +30,22 @@ export declare class Replay implements Integration {
30
30
  private retryCount;
31
31
  private retryInterval;
32
32
  private debouncedFlush;
33
+ private flushLock;
33
34
  /**
34
- * Flag when a new session has been created. Captured replay events behave
35
- * slightly differently in this case: `replay_start_timestamp` is included.
35
+ * Timestamp of the last user activity. This lives across sessions.
36
36
  */
37
- private newSessionCreated;
38
- private flushLock;
37
+ private lastActivity;
39
38
  /**
40
39
  * Is the integration currently active?
41
40
  */
42
41
  private isEnabled;
42
+ /**
43
+ *
44
+ * Paused is a state where:
45
+ * - DOM Recording is not listening at all
46
+ * - Nothing will be added to event buffer (e.g. core SDK events)
47
+ */
48
+ private isPaused;
43
49
  /**
44
50
  * Have we attached listeners to the core SDK?
45
51
  * Note we have to track this as there is no way to remove instrumentation handlers.
@@ -73,18 +79,27 @@ export declare class Replay implements Integration {
73
79
  */
74
80
  start(): void;
75
81
  /**
76
- * We want to batch uploads of replay events. Save events only if
77
- * `<flushMinDelay>` milliseconds have elapsed since the last event
78
- * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
82
+ * Start recording.
79
83
  *
80
- * Accepts a callback to perform side-effects and returns true to stop batch
81
- * processing and hand back control to caller.
84
+ * Note that this will cause a new DOM checkout
82
85
  */
83
- addUpdate(cb?: AddUpdateCallback): void;
86
+ startRecording(): void;
84
87
  /**
85
88
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
86
89
  */
87
90
  stop(): void;
91
+ /**
92
+ * Pause some replay functionality. See comments for `isPaused`.
93
+ * This differs from stop as this only stops DOM recording, it is
94
+ * not as thorough of a shutdown as `stop()`. */
95
+ pause(): void;
96
+ /**
97
+ * Resumes recording, see notes for `pause().
98
+ *
99
+ * Note that calling `startRecording()` here will cause a
100
+ * new DOM checkout.`
101
+ */
102
+ resume(): void;
88
103
  clearSession(): void;
89
104
  /**
90
105
  * Loads a session from storage, or creates a new one if it does not exist or
@@ -107,6 +122,15 @@ export declare class Replay implements Integration {
107
122
  * Cleans up listeners that were created in `addListeners`
108
123
  */
109
124
  removeListeners(): void;
125
+ /**
126
+ * We want to batch uploads of replay events. Save events only if
127
+ * `<flushMinDelay>` milliseconds have elapsed since the last event
128
+ * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
129
+ *
130
+ * Accepts a callback to perform side-effects and returns true to stop batch
131
+ * processing and hand back control to caller.
132
+ */
133
+ addUpdate(cb?: AddUpdateCallback): void;
110
134
  /**
111
135
  * Core Sentry SDK global event handler. Attaches `replayId` to all [non-replay]
112
136
  * events as a tag. Also handles the case where we only want to capture a reply
@@ -168,10 +192,19 @@ export declare class Replay implements Integration {
168
192
  * Add an event to the event buffer
169
193
  */
170
194
  addEvent(event: RecordingEvent, isCheckout?: boolean): void;
195
+ /**
196
+ * Update user activity (across session lifespans)
197
+ */
198
+ updateUserActivity(lastActivity?: number): void;
171
199
  /**
172
200
  * Updates the session's last activity timestamp
173
201
  */
174
- updateLastActivity(lastActivity?: number): void;
202
+ updateSessionActivity(lastActivity?: number): void;
203
+ /**
204
+ * Updates the user activity timestamp and resumes recording. This should be called in an event handler for a user action that we consider as the user being "active" (e.g. a mouse click).
205
+ *
206
+ */
207
+ triggerUserActivity(): Promise<void>;
175
208
  /**
176
209
  * Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
177
210
  */
@@ -191,11 +224,15 @@ export declare class Replay implements Integration {
191
224
  */
192
225
  addMemoryEntry(): Promise<void[]> | undefined;
193
226
  /**
194
- *
227
+ * Checks if recording should be stopped due to user inactivity. Otherwise
228
+ * check if session is expired and create a new session if so. Triggers a new
229
+ * full snapshot on new session.
195
230
  *
196
231
  * Returns true if session is not expired, false otherwise.
197
232
  */
198
- checkAndHandleExpiredSession(expiry?: number): boolean;
233
+ checkAndHandleExpiredSession({ expiry, }?: {
234
+ expiry?: number;
235
+ }): boolean | undefined;
199
236
  /**
200
237
  * Only flush if `captureOnlyOnError` is false.
201
238
  */
@@ -1,4 +1,4 @@
1
1
  import type { Breadcrumb } from '@sentry/types';
2
2
  declare type RequiredProperties = 'category' | 'message';
3
- export default function createBreadcrumb(breadcrumb: Pick<Breadcrumb, RequiredProperties> & Partial<Omit<Breadcrumb, RequiredProperties>>): Breadcrumb;
3
+ export declare function createBreadcrumb(breadcrumb: Pick<Breadcrumb, RequiredProperties> & Partial<Omit<Breadcrumb, RequiredProperties>>): Breadcrumb;
4
4
  export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine if there is browser support for `navigator.sendBeacon`
3
+ */
4
+ export declare function supportsSendBeacon(): boolean;
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentHub, addBreadcrumb, captureException, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
1
+ import { getCurrentHub, captureException, addBreadcrumb, addGlobalEventProcessor, setContext, getEnvelopeEndpointWithUrlEncodedAuth } from '@sentry/core';
2
2
  import { htmlTreeAsString, logger as logger$1, uuid4, browserPerformanceTimeOrigin, addInstrumentationHandler, createEnvelope, serializeEnvelope } from '@sentry/utils';
3
3
  import debounce from 'lodash.debounce';
4
4
  import { record, EventType } from 'rrweb';
@@ -436,6 +436,16 @@ function createSession(_a) {
436
436
  return session;
437
437
  }
438
438
 
439
+ /**
440
+ * Captures exceptions to Sentry only when it occurs on sentry.io
441
+ */
442
+ function captureInternalException(err) {
443
+ if (!isInternal()) {
444
+ return;
445
+ }
446
+ captureException(err);
447
+ }
448
+
439
449
  /**
440
450
  * Fetches a session from storage
441
451
  */
@@ -444,10 +454,17 @@ function fetchSession() {
444
454
  if (!hasSessionStorage) {
445
455
  return null;
446
456
  }
457
+ var sessionStringFromStorage = window.sessionStorage.getItem(REPLAY_SESSION_KEY);
458
+ if (!sessionStringFromStorage) {
459
+ return null;
460
+ }
447
461
  try {
448
- return new Session(
449
- // @ts-expect-error: Type 'null' is not assignable to type 'string'.ts(2345)
450
- JSON.parse(window.sessionStorage.getItem(REPLAY_SESSION_KEY)),
462
+ var sessionObj = JSON.parse(sessionStringFromStorage);
463
+ // NOTE: This shouldn't happen
464
+ if (sessionObj.segmentId === 0) {
465
+ captureInternalException(new Error('Session storage object with segmentId = 0'));
466
+ }
467
+ return new Session(sessionObj,
451
468
  // We are assuming that if there is a saved item, then the session is sticky,
452
469
  // however this could break down if we used a different storage mechanism (e.g. localstorage)
453
470
  { stickySession: true });
@@ -465,8 +482,9 @@ function getSession(_a) {
465
482
  // If session exists and is passed, use it instead of always hitting session storage
466
483
  var session = currentSession || (stickySession && fetchSession());
467
484
  if (session) {
468
- // If there is a session, check if it is valid (e.g. "last activity" time should be within the "session idle time")
469
- // TODO: We should probably set a max age on this as well
485
+ // If there is a session, check if it is valid (e.g. "last activity" time
486
+ // should be within the "session idle time", and "session started" time is
487
+ // within "max session time").
470
488
  var isExpired = isSessionExpired(session, expiry);
471
489
  if (!isExpired) {
472
490
  return { type: 'saved', session: session };
@@ -491,16 +509,6 @@ function addInternalBreadcrumb(arg) {
491
509
  addBreadcrumb(__assign({ category: category || 'console', level: level || 'debug', message: "[debug]: ".concat(message) }, rest));
492
510
  }
493
511
 
494
- /**
495
- * Captures exceptions to Sentry only when it occurs on sentry.io
496
- */
497
- function captureInternalException(err) {
498
- if (!isInternal()) {
499
- return;
500
- }
501
- captureException(err);
502
- }
503
-
504
512
  function createPayload(_a) {
505
513
  var events = _a.events, headers = _a.headers;
506
514
  var payloadWithSequence;
@@ -913,16 +921,22 @@ var Replay = /** @class */ (function () {
913
921
  this.performanceObserver = null;
914
922
  this.retryCount = 0;
915
923
  this.retryInterval = BASE_RETRY_INTERVAL;
924
+ this.flushLock = null;
916
925
  /**
917
- * Flag when a new session has been created. Captured replay events behave
918
- * slightly differently in this case: `replay_start_timestamp` is included.
926
+ * Timestamp of the last user activity. This lives across sessions.
919
927
  */
920
- this.newSessionCreated = false;
921
- this.flushLock = null;
928
+ this.lastActivity = new Date().getTime();
922
929
  /**
923
930
  * Is the integration currently active?
924
931
  */
925
932
  this.isEnabled = false;
933
+ /**
934
+ *
935
+ * Paused is a state where:
936
+ * - DOM Recording is not listening at all
937
+ * - Nothing will be added to event buffer (e.g. core SDK events)
938
+ */
939
+ this.isPaused = false;
926
940
  /**
927
941
  * Have we attached listeners to the core SDK?
928
942
  * Note we have to track this as there is no way to remove instrumentation handlers.
@@ -1078,7 +1092,8 @@ var Replay = /** @class */ (function () {
1078
1092
  if (type === 'history') {
1079
1093
  // Need to collect visited URLs
1080
1094
  _this.context.urls.push(result.name);
1081
- _this.updateLastActivity();
1095
+ _this.updateUserActivity();
1096
+ _this.triggerUserActivity();
1082
1097
  }
1083
1098
  _this.addUpdate(function () {
1084
1099
  _this.createPerformanceSpans([result]);
@@ -1106,7 +1121,10 @@ var Replay = /** @class */ (function () {
1106
1121
  return;
1107
1122
  }
1108
1123
  if (result.category === 'ui.click') {
1109
- _this.updateLastActivity();
1124
+ _this.triggerUserActivity();
1125
+ }
1126
+ else {
1127
+ _this.checkAndHandleExpiredSession();
1110
1128
  }
1111
1129
  _this.addUpdate(function () {
1112
1130
  _this.addEvent({
@@ -1259,7 +1277,7 @@ var Replay = /** @class */ (function () {
1259
1277
  }
1260
1278
  // setup() is generally called on page load or manually - in both cases we
1261
1279
  // should treat it as an activity
1262
- this.updateLastActivity();
1280
+ this.updateSessionActivity();
1263
1281
  this.eventBuffer = createEventBuffer({
1264
1282
  useCompression: Boolean(this.options.useCompression),
1265
1283
  });
@@ -1267,33 +1285,16 @@ var Replay = /** @class */ (function () {
1267
1285
  // Tag all (non replay) events that get sent to Sentry with the current
1268
1286
  // replay ID so that we can reference them later in the UI
1269
1287
  addGlobalEventProcessor(this.handleGlobalEvent);
1270
- this.stopRecording = record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1288
+ this.startRecording();
1271
1289
  this.isEnabled = true;
1272
1290
  };
1273
1291
  /**
1274
- * We want to batch uploads of replay events. Save events only if
1275
- * `<flushMinDelay>` milliseconds have elapsed since the last event
1276
- * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
1292
+ * Start recording.
1277
1293
  *
1278
- * Accepts a callback to perform side-effects and returns true to stop batch
1279
- * processing and hand back control to caller.
1294
+ * Note that this will cause a new DOM checkout
1280
1295
  */
1281
- Replay.prototype.addUpdate = function (cb) {
1282
- // We need to always run `cb` (e.g. in the case of captureOnlyOnError == true)
1283
- var cbResult = cb === null || cb === void 0 ? void 0 : cb();
1284
- // If this option is turned on then we will only want to call `flush`
1285
- // explicitly
1286
- if (this.options.captureOnlyOnError) {
1287
- return;
1288
- }
1289
- // If callback is true, we do not want to continue with flushing -- the
1290
- // caller will need to handle it.
1291
- if (cbResult === true) {
1292
- return;
1293
- }
1294
- // addUpdate is called quite frequently - use debouncedFlush so that it
1295
- // respects the flush delays and does not flush immediately
1296
- this.debouncedFlush();
1296
+ Replay.prototype.startRecording = function () {
1297
+ this.stopRecording = record(__assign(__assign({}, this.recordingOptions), { emit: this.handleRecordingEmit }));
1297
1298
  };
1298
1299
  /**
1299
1300
  * Currently, this needs to be manually called (e.g. for tests). Sentry SDK does not support a teardown
@@ -1310,6 +1311,27 @@ var Replay = /** @class */ (function () {
1310
1311
  (_b = this.eventBuffer) === null || _b === void 0 ? void 0 : _b.destroy();
1311
1312
  this.eventBuffer = null;
1312
1313
  };
1314
+ /**
1315
+ * Pause some replay functionality. See comments for `isPaused`.
1316
+ * This differs from stop as this only stops DOM recording, it is
1317
+ * not as thorough of a shutdown as `stop()`. */
1318
+ Replay.prototype.pause = function () {
1319
+ this.isPaused = true;
1320
+ if (this.stopRecording) {
1321
+ this.stopRecording();
1322
+ this.stopRecording = undefined;
1323
+ }
1324
+ };
1325
+ /**
1326
+ * Resumes recording, see notes for `pause().
1327
+ *
1328
+ * Note that calling `startRecording()` here will cause a
1329
+ * new DOM checkout.`
1330
+ */
1331
+ Replay.prototype.resume = function () {
1332
+ this.isPaused = false;
1333
+ this.startRecording();
1334
+ };
1313
1335
  Replay.prototype.clearSession = function () {
1314
1336
  deleteSession();
1315
1337
  this.session = undefined;
@@ -1330,7 +1352,6 @@ var Replay = /** @class */ (function () {
1330
1352
  // If session was newly created (i.e. was not loaded from storage), then
1331
1353
  // enable flag to create the root replay
1332
1354
  if (type === 'new') {
1333
- this.newSessionCreated = true;
1334
1355
  this.setInitialState();
1335
1356
  }
1336
1357
  if (session.id !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id)) {
@@ -1416,6 +1437,31 @@ var Replay = /** @class */ (function () {
1416
1437
  this.performanceObserver = null;
1417
1438
  }
1418
1439
  };
1440
+ /**
1441
+ * We want to batch uploads of replay events. Save events only if
1442
+ * `<flushMinDelay>` milliseconds have elapsed since the last event
1443
+ * *OR* if `<flushMaxDelay>` milliseconds have elapsed.
1444
+ *
1445
+ * Accepts a callback to perform side-effects and returns true to stop batch
1446
+ * processing and hand back control to caller.
1447
+ */
1448
+ Replay.prototype.addUpdate = function (cb) {
1449
+ // We need to always run `cb` (e.g. in the case of captureOnlyOnError == true)
1450
+ var cbResult = cb === null || cb === void 0 ? void 0 : cb();
1451
+ // If this option is turned on then we will only want to call `flush`
1452
+ // explicitly
1453
+ if (this.options.captureOnlyOnError) {
1454
+ return;
1455
+ }
1456
+ // If callback is true, we do not want to continue with flushing -- the
1457
+ // caller will need to handle it.
1458
+ if (cbResult === true) {
1459
+ return;
1460
+ }
1461
+ // addUpdate is called quite frequently - use debouncedFlush so that it
1462
+ // respects the flush delays and does not flush immediately
1463
+ this.debouncedFlush();
1464
+ };
1419
1465
  /**
1420
1466
  * Tasks to run when we consider a page to be hidden (via blurring and/or visibility)
1421
1467
  */
@@ -1423,8 +1469,8 @@ var Replay = /** @class */ (function () {
1423
1469
  if (!this.session) {
1424
1470
  return;
1425
1471
  }
1426
- var isExpired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
1427
- if (breadcrumb && !isExpired) {
1472
+ var expired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
1473
+ if (breadcrumb && !expired) {
1428
1474
  this.createCustomBreadcrumb(breadcrumb);
1429
1475
  }
1430
1476
  // Send replay when the page/tab becomes hidden. There is no reason to send
@@ -1439,24 +1485,19 @@ var Replay = /** @class */ (function () {
1439
1485
  if (!this.session) {
1440
1486
  return;
1441
1487
  }
1442
- var isExpired = isSessionExpired(this.session, VISIBILITY_CHANGE_TIMEOUT);
1443
- if (isExpired) {
1488
+ var isSessionActive = this.checkAndHandleExpiredSession({
1489
+ expiry: VISIBILITY_CHANGE_TIMEOUT,
1490
+ });
1491
+ if (!isSessionActive) {
1444
1492
  // If the user has come back to the page within VISIBILITY_CHANGE_TIMEOUT
1445
1493
  // ms, we will re-use the existing session, otherwise create a new
1446
1494
  // session
1447
1495
  logger.log('Document has become active, but session has expired');
1448
- this.loadSession({ expiry: VISIBILITY_CHANGE_TIMEOUT });
1449
- this.triggerFullSnapshot();
1450
1496
  return;
1451
1497
  }
1452
1498
  if (breadcrumb) {
1453
1499
  this.createCustomBreadcrumb(breadcrumb);
1454
1500
  }
1455
- // Otherwise if session is not expired...
1456
- // Update with current timestamp as the last session activity
1457
- // Only updating session on visibility change to be conservative about
1458
- // writing to session storage. This could be changed in the future.
1459
- this.updateLastActivity();
1460
1501
  };
1461
1502
  /**
1462
1503
  * Trigger rrweb to take a full snapshot which will cause this plugin to
@@ -1470,10 +1511,15 @@ var Replay = /** @class */ (function () {
1470
1511
  * Add an event to the event buffer
1471
1512
  */
1472
1513
  Replay.prototype.addEvent = function (event, isCheckout) {
1514
+ var _a;
1473
1515
  if (!this.eventBuffer) {
1474
1516
  // This implies that `isEnabled` is false
1475
1517
  return;
1476
1518
  }
1519
+ if (this.isPaused) {
1520
+ // Do not add to event buffer when recording is paused
1521
+ return;
1522
+ }
1477
1523
  // TODO: sadness -- we will want to normalize timestamps to be in ms -
1478
1524
  // requires coordination with frontend
1479
1525
  var isMs = event.timestamp > 9999999999;
@@ -1487,22 +1533,53 @@ var Replay = /** @class */ (function () {
1487
1533
  }
1488
1534
  // Only record earliest event if a new session was created, otherwise it
1489
1535
  // shouldn't be relevant
1490
- if (this.newSessionCreated &&
1536
+ if (((_a = this.session) === null || _a === void 0 ? void 0 : _a.segmentId) === 0 &&
1491
1537
  (!this.context.earliestEvent ||
1492
1538
  timestampInMs < this.context.earliestEvent)) {
1493
1539
  this.context.earliestEvent = timestampInMs;
1494
1540
  }
1495
1541
  this.eventBuffer.addEvent(event, isCheckout);
1496
1542
  };
1543
+ /**
1544
+ * Update user activity (across session lifespans)
1545
+ */
1546
+ Replay.prototype.updateUserActivity = function (lastActivity) {
1547
+ if (lastActivity === void 0) { lastActivity = new Date().getTime(); }
1548
+ this.lastActivity = lastActivity;
1549
+ };
1497
1550
  /**
1498
1551
  * Updates the session's last activity timestamp
1499
1552
  */
1500
- Replay.prototype.updateLastActivity = function (lastActivity) {
1553
+ Replay.prototype.updateSessionActivity = function (lastActivity) {
1501
1554
  if (lastActivity === void 0) { lastActivity = new Date().getTime(); }
1502
1555
  if (this.session) {
1503
1556
  this.session.lastActivity = lastActivity;
1504
1557
  }
1505
1558
  };
1559
+ /**
1560
+ * Updates the user activity timestamp and resumes recording. This should be called in an event handler for a user action that we consider as the user being "active" (e.g. a mouse click).
1561
+ *
1562
+ */
1563
+ Replay.prototype.triggerUserActivity = function () {
1564
+ return __awaiter(this, void 0, void 0, function () {
1565
+ return __generator(this, function (_a) {
1566
+ this.updateUserActivity();
1567
+ // This case means that recording was once stopped due to inactivity.
1568
+ // Ensure that recording is resumed.
1569
+ if (!this.stopRecording) {
1570
+ // Create a new session, otherwise when the user action is flushed, it will get rejected due to an expired session.
1571
+ this.loadSession({ expiry: SESSION_IDLE_DURATION });
1572
+ // Note: This will cause a new DOM checkout
1573
+ this.resume();
1574
+ return [2 /*return*/];
1575
+ }
1576
+ // Otherwise... recording was never suspended, continue as normalish
1577
+ this.checkAndHandleExpiredSession();
1578
+ this.updateSessionActivity();
1579
+ return [2 /*return*/];
1580
+ });
1581
+ });
1582
+ };
1506
1583
  /**
1507
1584
  * Helper to create (and buffer) a replay breadcrumb from a core SDK breadcrumb
1508
1585
  */
@@ -1568,19 +1645,31 @@ var Replay = /** @class */ (function () {
1568
1645
  ]);
1569
1646
  };
1570
1647
  /**
1571
- *
1648
+ * Checks if recording should be stopped due to user inactivity. Otherwise
1649
+ * check if session is expired and create a new session if so. Triggers a new
1650
+ * full snapshot on new session.
1572
1651
  *
1573
1652
  * Returns true if session is not expired, false otherwise.
1574
1653
  */
1575
- Replay.prototype.checkAndHandleExpiredSession = function (expiry) {
1576
- var _a, _b;
1577
- if (expiry === void 0) { expiry = SESSION_IDLE_DURATION; }
1578
- var oldSessionId = (_a = this.session) === null || _a === void 0 ? void 0 : _a.id;
1654
+ Replay.prototype.checkAndHandleExpiredSession = function (_a) {
1655
+ var _b, _c;
1656
+ var _d = _a === void 0 ? {} : _a, _e = _d.expiry, expiry = _e === void 0 ? SESSION_IDLE_DURATION : _e;
1657
+ var oldSessionId = (_b = this.session) === null || _b === void 0 ? void 0 : _b.id;
1658
+ // Prevent starting a new session if the last user activity is older than
1659
+ // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
1660
+ // session+recording. This creates noisy replays that do not have much
1661
+ // content in them.
1662
+ if (this.lastActivity && isExpired(this.lastActivity, MAX_SESSION_LIFE)) {
1663
+ // Pause recording
1664
+ this.pause();
1665
+ return;
1666
+ }
1667
+ // --- There is recent user activity --- //
1579
1668
  // This will create a new session if expired, based on expiry length
1580
1669
  this.loadSession({ expiry: expiry });
1581
1670
  // Session was expired if session ids do not match
1582
- var isExpired = oldSessionId !== ((_b = this.session) === null || _b === void 0 ? void 0 : _b.id);
1583
- if (!isExpired) {
1671
+ var expired = oldSessionId !== ((_c = this.session) === null || _c === void 0 ? void 0 : _c.id);
1672
+ if (!expired) {
1584
1673
  return true;
1585
1674
  }
1586
1675
  // TODO: We could potentially figure out a way to save the last session,
@@ -1639,7 +1728,7 @@ var Replay = /** @class */ (function () {
1639
1728
  Replay.prototype.runFlush = function () {
1640
1729
  var _a;
1641
1730
  return __awaiter(this, void 0, void 0, function () {
1642
- var replayId, newSessionCreated, segmentId, recordingData, err_2;
1731
+ var replayId, segmentId, recordingData, err_2;
1643
1732
  return __generator(this, function (_b) {
1644
1733
  switch (_b.label) {
1645
1734
  case 0:
@@ -1659,7 +1748,6 @@ var Replay = /** @class */ (function () {
1659
1748
  // Only attach memory event if eventBuffer is not empty
1660
1749
  _b.sent();
1661
1750
  replayId = this.session.id;
1662
- newSessionCreated = this.newSessionCreated;
1663
1751
  segmentId = this.session.segmentId++;
1664
1752
  _b.label = 3;
1665
1753
  case 3:
@@ -1671,11 +1759,10 @@ var Replay = /** @class */ (function () {
1671
1759
  replayId: replayId,
1672
1760
  events: recordingData,
1673
1761
  segmentId: segmentId,
1674
- includeReplayStartTimestamp: newSessionCreated,
1762
+ includeReplayStartTimestamp: segmentId === 0,
1675
1763
  })];
1676
1764
  case 5:
1677
1765
  _b.sent();
1678
- this.newSessionCreated = false;
1679
1766
  return [3 /*break*/, 7];
1680
1767
  case 6:
1681
1768
  err_2 = _b.sent();
@@ -1720,7 +1807,7 @@ var Replay = /** @class */ (function () {
1720
1807
  timestamp = new Date().getTime();
1721
1808
  sdkInfo = {
1722
1809
  name: 'sentry.javascript.integration.replay',
1723
- version: "0.6.9",
1810
+ version: "0.6.10",
1724
1811
  };
1725
1812
  return [4 /*yield*/, new Promise(function (resolve) {
1726
1813
  var _a;