@sentry/replay 7.41.0 → 7.42.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 +2 -4
- package/cjs/index.js +187 -116
- package/cjs/index.js.map +1 -1
- package/esm/index.js +187 -116
- package/esm/index.js.map +1 -1
- package/package.json +6 -6
- package/types/replay.d.ts +12 -13
- package/types/replay.d.ts.map +1 -1
- package/types/session/getSession.d.ts +3 -6
- package/types/session/getSession.d.ts.map +1 -1
- package/types/types.d.ts +11 -0
- package/types/types.d.ts.map +1 -1
- package/types/util/addEvent.d.ts +2 -1
- package/types/util/addEvent.d.ts.map +1 -1
- package/types/util/handleRecordingEmit.d.ts +10 -0
- package/types/util/handleRecordingEmit.d.ts.map +1 -0
- package/types/util/isSessionExpired.d.ts +2 -2
- package/types/util/isSessionExpired.d.ts.map +1 -1
- package/types/util/sendReplay.d.ts.map +1 -1
- package/types/util/sendReplayRequest.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
[](https://www.npmjs.com/package/@sentry/replay)
|
|
11
11
|
[](https://www.npmjs.com/package/@sentry/replay)
|
|
12
12
|
|
|
13
|
-
**Note: Session Replay is currently in beta.** Functionality may change outside of major version bumps - while we try our best to avoid any breaking changes, semver cannot be guaranteed before Replay is out of beta. You can find more information about upgrading in [MIGRATION.md](./MIGRATION.md).
|
|
14
|
-
|
|
15
13
|
## Pre-requisites
|
|
16
14
|
|
|
17
15
|
`@sentry/replay` requires Node 12+, and browsers newer than IE11.
|
|
@@ -112,11 +110,11 @@ The `replay.(min.)js` bundle will be removed in v8 of the JS SDKs.
|
|
|
112
110
|
|
|
113
111
|
```html
|
|
114
112
|
<script
|
|
115
|
-
src="https://browser.sentry-cdn.com/7.
|
|
113
|
+
src="https://browser.sentry-cdn.com/7.41.0/bundle.min.js"
|
|
116
114
|
crossorigin="anonymous"
|
|
117
115
|
></script>
|
|
118
116
|
<script
|
|
119
|
-
src="https://browser.sentry-cdn.com/7.
|
|
117
|
+
src="https://browser.sentry-cdn.com/7.41.0/replay.min.js"
|
|
120
118
|
crossorigin="anonymous"
|
|
121
119
|
></script>
|
|
122
120
|
```
|
package/cjs/index.js
CHANGED
|
@@ -266,7 +266,7 @@ function getHref() {
|
|
|
266
266
|
a.href = '';
|
|
267
267
|
return a.href;
|
|
268
268
|
}
|
|
269
|
-
function transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn) {
|
|
269
|
+
function transformAttribute(doc, element, tagName, name, value, maskAllText, maskTextFn) {
|
|
270
270
|
if (!value) {
|
|
271
271
|
return value;
|
|
272
272
|
}
|
|
@@ -290,7 +290,11 @@ function transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn)
|
|
|
290
290
|
return absoluteToDoc(doc, value);
|
|
291
291
|
}
|
|
292
292
|
else if (maskAllText &&
|
|
293
|
-
['placeholder', 'title', 'aria-label'].indexOf(name) > -1
|
|
293
|
+
(['placeholder', 'title', 'aria-label'].indexOf(name) > -1 ||
|
|
294
|
+
(tagName === 'input' &&
|
|
295
|
+
name === 'value' &&
|
|
296
|
+
element.getAttribute('type') &&
|
|
297
|
+
['submit', 'button'].indexOf(element.getAttribute('type').toLowerCase()) > -1))) {
|
|
294
298
|
return maskTextFn ? maskTextFn(value) : defaultMaskFn(value);
|
|
295
299
|
}
|
|
296
300
|
return value;
|
|
@@ -428,7 +432,7 @@ function serializeNode(n, options) {
|
|
|
428
432
|
let attributes = {};
|
|
429
433
|
for (const { name, value } of Array.from(n.attributes)) {
|
|
430
434
|
if (!skipAttribute(tagName, name)) {
|
|
431
|
-
attributes[name] = transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn);
|
|
435
|
+
attributes[name] = transformAttribute(doc, n, tagName, name, value, maskAllText, maskTextFn);
|
|
432
436
|
}
|
|
433
437
|
}
|
|
434
438
|
if (tagName === 'link' && inlineStylesheet) {
|
|
@@ -1588,7 +1592,8 @@ class MutationBuffer {
|
|
|
1588
1592
|
}
|
|
1589
1593
|
}
|
|
1590
1594
|
else {
|
|
1591
|
-
|
|
1595
|
+
const element = m.target;
|
|
1596
|
+
item.attributes[m.attributeName] = transformAttribute(this.doc, element, element.tagName, m.attributeName, value, this.maskAllText, this.maskTextFn);
|
|
1592
1597
|
}
|
|
1593
1598
|
break;
|
|
1594
1599
|
}
|
|
@@ -1775,7 +1780,12 @@ function initMutationObserver(options, rootEl) {
|
|
|
1775
1780
|
window[angularZoneSymbol]) {
|
|
1776
1781
|
mutationObserverCtor = window[angularZoneSymbol];
|
|
1777
1782
|
}
|
|
1778
|
-
const observer = new mutationObserverCtor(callbackWrapper(
|
|
1783
|
+
const observer = new mutationObserverCtor(callbackWrapper((mutations) => {
|
|
1784
|
+
if (options.onMutation && options.onMutation(mutations) === false) {
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
mutationBuffer.processMutations(mutations);
|
|
1788
|
+
}));
|
|
1779
1789
|
observer.observe(rootEl, {
|
|
1780
1790
|
attributes: true,
|
|
1781
1791
|
attributeOldValue: true,
|
|
@@ -2824,7 +2834,7 @@ let wrappedEmit;
|
|
|
2824
2834
|
let takeFullSnapshot;
|
|
2825
2835
|
const mirror = createMirror();
|
|
2826
2836
|
function record(options = {}) {
|
|
2827
|
-
const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, unblockSelector = null, ignoreClass = 'rr-ignore', ignoreSelector = null, maskTextClass = 'rr-mask', maskTextSelector = null, maskInputSelector = null, unmaskTextSelector = null, unmaskInputSelector = null, inlineStylesheet = true, maskAllText = false, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, mousemoveWait, recordCanvas = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, } = options;
|
|
2837
|
+
const { emit, checkoutEveryNms, checkoutEveryNth, blockClass = 'rr-block', blockSelector = null, unblockSelector = null, ignoreClass = 'rr-ignore', ignoreSelector = null, maskTextClass = 'rr-mask', maskTextSelector = null, maskInputSelector = null, unmaskTextSelector = null, unmaskInputSelector = null, inlineStylesheet = true, maskAllText = false, maskAllInputs, maskInputOptions: _maskInputOptions, slimDOMOptions: _slimDOMOptions, maskInputFn, maskTextFn, hooks, packFn, sampling = {}, mousemoveWait, recordCanvas = false, userTriggeredOnInput = false, collectFonts = false, inlineImages = false, plugins, keepIframeSrcFn = () => false, onMutation, } = options;
|
|
2828
2838
|
if (!emit) {
|
|
2829
2839
|
throw new Error('emit function is required');
|
|
2830
2840
|
}
|
|
@@ -2940,6 +2950,7 @@ function record(options = {}) {
|
|
|
2940
2950
|
mutationCb: wrappedMutationEmit,
|
|
2941
2951
|
scrollCb: wrappedScrollEmit,
|
|
2942
2952
|
bypassOptions: {
|
|
2953
|
+
onMutation,
|
|
2943
2954
|
blockClass,
|
|
2944
2955
|
blockSelector,
|
|
2945
2956
|
unblockSelector,
|
|
@@ -3040,6 +3051,7 @@ function record(options = {}) {
|
|
|
3040
3051
|
const observe = (doc) => {
|
|
3041
3052
|
var _a;
|
|
3042
3053
|
return callbackWrapper(initObservers)({
|
|
3054
|
+
onMutation,
|
|
3043
3055
|
mutationCb: wrappedMutationEmit,
|
|
3044
3056
|
mousemoveCb: (positions, source) => wrappedEmit(wrapEvent({
|
|
3045
3057
|
type: EventType.IncrementalSnapshot,
|
|
@@ -3662,13 +3674,13 @@ function isExpired(
|
|
|
3662
3674
|
/**
|
|
3663
3675
|
* Checks to see if session is expired
|
|
3664
3676
|
*/
|
|
3665
|
-
function isSessionExpired(session,
|
|
3677
|
+
function isSessionExpired(session, timeouts, targetTime = +new Date()) {
|
|
3666
3678
|
return (
|
|
3667
3679
|
// First, check that maximum session length has not been exceeded
|
|
3668
|
-
isExpired(session.started,
|
|
3680
|
+
isExpired(session.started, timeouts.maxSessionLife, targetTime) ||
|
|
3669
3681
|
// check that the idle timeout has not been exceeded (i.e. user has
|
|
3670
3682
|
// performed an action within the last `idleTimeout` ms)
|
|
3671
|
-
isExpired(session.lastActivity,
|
|
3683
|
+
isExpired(session.lastActivity, timeouts.sessionIdle, targetTime)
|
|
3672
3684
|
);
|
|
3673
3685
|
}
|
|
3674
3686
|
|
|
@@ -3781,7 +3793,7 @@ function fetchSession() {
|
|
|
3781
3793
|
* Get or create a session
|
|
3782
3794
|
*/
|
|
3783
3795
|
function getSession({
|
|
3784
|
-
|
|
3796
|
+
timeouts,
|
|
3785
3797
|
currentSession,
|
|
3786
3798
|
stickySession,
|
|
3787
3799
|
sessionSampleRate,
|
|
@@ -3794,7 +3806,7 @@ function getSession({
|
|
|
3794
3806
|
// If there is a session, check if it is valid (e.g. "last activity" time
|
|
3795
3807
|
// should be within the "session idle time", and "session started" time is
|
|
3796
3808
|
// within "max session time").
|
|
3797
|
-
const isExpired = isSessionExpired(session,
|
|
3809
|
+
const isExpired = isSessionExpired(session, timeouts);
|
|
3798
3810
|
|
|
3799
3811
|
if (!isExpired) {
|
|
3800
3812
|
return { type: 'saved', session };
|
|
@@ -3818,7 +3830,8 @@ function getSession({
|
|
|
3818
3830
|
}
|
|
3819
3831
|
|
|
3820
3832
|
/**
|
|
3821
|
-
* Add an event to the event buffer
|
|
3833
|
+
* Add an event to the event buffer.
|
|
3834
|
+
* `isCheckout` is true if this is either the very first event, or an event triggered by `checkoutEveryNms`.
|
|
3822
3835
|
*/
|
|
3823
3836
|
async function addEvent(
|
|
3824
3837
|
replay,
|
|
@@ -3844,7 +3857,7 @@ async function addEvent(
|
|
|
3844
3857
|
// page has been left open and idle for a long period of time and user
|
|
3845
3858
|
// comes back to trigger a new session. The performance entries rely on
|
|
3846
3859
|
// `performance.timeOrigin`, which is when the page first opened.
|
|
3847
|
-
if (timestampInMs +
|
|
3860
|
+
if (timestampInMs + replay.timeouts.sessionIdle < new Date().getTime()) {
|
|
3848
3861
|
return null;
|
|
3849
3862
|
}
|
|
3850
3863
|
|
|
@@ -3890,7 +3903,7 @@ function addBreadcrumbEvent(replay, breadcrumb) {
|
|
|
3890
3903
|
return;
|
|
3891
3904
|
}
|
|
3892
3905
|
|
|
3893
|
-
if (
|
|
3906
|
+
if (['ui.click', 'ui.input'].includes(breadcrumb.category )) {
|
|
3894
3907
|
replay.triggerUserActivity();
|
|
3895
3908
|
} else {
|
|
3896
3909
|
replay.checkAndHandleExpiredSession();
|
|
@@ -4592,6 +4605,85 @@ function debounce(func, wait, options) {
|
|
|
4592
4605
|
return debounced;
|
|
4593
4606
|
}
|
|
4594
4607
|
|
|
4608
|
+
/**
|
|
4609
|
+
* Handler for recording events.
|
|
4610
|
+
*
|
|
4611
|
+
* Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
|
|
4612
|
+
*/
|
|
4613
|
+
function getHandleRecordingEmit(replay) {
|
|
4614
|
+
let hadFirstEvent = false;
|
|
4615
|
+
|
|
4616
|
+
return (event, _isCheckout) => {
|
|
4617
|
+
// If this is false, it means session is expired, create and a new session and wait for checkout
|
|
4618
|
+
if (!replay.checkAndHandleExpiredSession()) {
|
|
4619
|
+
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.warn('[Replay] Received replay event after session expired.');
|
|
4620
|
+
|
|
4621
|
+
return;
|
|
4622
|
+
}
|
|
4623
|
+
|
|
4624
|
+
// `_isCheckout` is only set when the checkout is due to `checkoutEveryNms`
|
|
4625
|
+
// We also want to treat the first event as a checkout, so we handle this specifically here
|
|
4626
|
+
const isCheckout = _isCheckout || !hadFirstEvent;
|
|
4627
|
+
hadFirstEvent = true;
|
|
4628
|
+
|
|
4629
|
+
// The handler returns `true` if we do not want to trigger debounced flush, `false` if we want to debounce flush.
|
|
4630
|
+
replay.addUpdate(() => {
|
|
4631
|
+
// The session is always started immediately on pageload/init, but for
|
|
4632
|
+
// error-only replays, it should reflect the most recent checkout
|
|
4633
|
+
// when an error occurs. Clear any state that happens before this current
|
|
4634
|
+
// checkout. This needs to happen before `addEvent()` which updates state
|
|
4635
|
+
// dependent on this reset.
|
|
4636
|
+
if (replay.recordingMode === 'error' && isCheckout) {
|
|
4637
|
+
replay.setInitialState();
|
|
4638
|
+
}
|
|
4639
|
+
|
|
4640
|
+
// We need to clear existing events on a checkout, otherwise they are
|
|
4641
|
+
// incremental event updates and should be appended
|
|
4642
|
+
void addEvent(replay, event, isCheckout);
|
|
4643
|
+
|
|
4644
|
+
// Different behavior for full snapshots (type=2), ignore other event types
|
|
4645
|
+
// See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
|
|
4646
|
+
if (!isCheckout) {
|
|
4647
|
+
return false;
|
|
4648
|
+
}
|
|
4649
|
+
|
|
4650
|
+
// If there is a previousSessionId after a full snapshot occurs, then
|
|
4651
|
+
// the replay session was started due to session expiration. The new session
|
|
4652
|
+
// is started before triggering a new checkout and contains the id
|
|
4653
|
+
// of the previous session. Do not immediately flush in this case
|
|
4654
|
+
// to avoid capturing only the checkout and instead the replay will
|
|
4655
|
+
// be captured if they perform any follow-up actions.
|
|
4656
|
+
if (replay.session && replay.session.previousSessionId) {
|
|
4657
|
+
return true;
|
|
4658
|
+
}
|
|
4659
|
+
|
|
4660
|
+
// See note above re: session start needs to reflect the most recent
|
|
4661
|
+
// checkout.
|
|
4662
|
+
if (replay.recordingMode === 'error' && replay.session) {
|
|
4663
|
+
const { earliestEvent } = replay.getContext();
|
|
4664
|
+
if (earliestEvent) {
|
|
4665
|
+
replay.session.started = earliestEvent;
|
|
4666
|
+
|
|
4667
|
+
if (replay.getOptions().stickySession) {
|
|
4668
|
+
saveSession(replay.session);
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4671
|
+
}
|
|
4672
|
+
|
|
4673
|
+
// Flush immediately so that we do not miss the first segment, otherwise
|
|
4674
|
+
// it can prevent loading on the UI. This will cause an increase in short
|
|
4675
|
+
// replays (e.g. opening and closing a tab quickly), but these can be
|
|
4676
|
+
// filtered on the UI.
|
|
4677
|
+
if (replay.recordingMode === 'session') {
|
|
4678
|
+
// We want to ensure the worker is ready, as otherwise we'd always send the first event uncompressed
|
|
4679
|
+
void replay.flushImmediate();
|
|
4680
|
+
}
|
|
4681
|
+
|
|
4682
|
+
return true;
|
|
4683
|
+
});
|
|
4684
|
+
};
|
|
4685
|
+
}
|
|
4686
|
+
|
|
4595
4687
|
let _originalRecordDroppedEvent;
|
|
4596
4688
|
|
|
4597
4689
|
/**
|
|
@@ -4846,8 +4938,17 @@ async function sendReplayRequest({
|
|
|
4846
4938
|
|
|
4847
4939
|
try {
|
|
4848
4940
|
response = await transport.send(envelope);
|
|
4849
|
-
} catch (
|
|
4850
|
-
|
|
4941
|
+
} catch (err) {
|
|
4942
|
+
const error = new Error(UNABLE_TO_SEND_REPLAY);
|
|
4943
|
+
|
|
4944
|
+
try {
|
|
4945
|
+
// In case browsers don't allow this property to be writable
|
|
4946
|
+
// @ts-ignore This needs lib es2022 and newer
|
|
4947
|
+
error.cause = err;
|
|
4948
|
+
} catch (e) {
|
|
4949
|
+
// nothing to do
|
|
4950
|
+
}
|
|
4951
|
+
throw error;
|
|
4851
4952
|
}
|
|
4852
4953
|
|
|
4853
4954
|
// TODO (v8): we can remove this guard once transport.send's type signature doesn't include void anymore
|
|
@@ -4909,7 +5010,17 @@ async function sendReplay(
|
|
|
4909
5010
|
// If an error happened here, it's likely that uploading the attachment
|
|
4910
5011
|
// failed, we'll can retry with the same events payload
|
|
4911
5012
|
if (retryConfig.count >= RETRY_MAX_COUNT) {
|
|
4912
|
-
|
|
5013
|
+
const error = new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);
|
|
5014
|
+
|
|
5015
|
+
try {
|
|
5016
|
+
// In case browsers don't allow this property to be writable
|
|
5017
|
+
// @ts-ignore This needs lib es2022 and newer
|
|
5018
|
+
error.cause = err;
|
|
5019
|
+
} catch (e) {
|
|
5020
|
+
// nothing to do
|
|
5021
|
+
}
|
|
5022
|
+
|
|
5023
|
+
throw error;
|
|
4913
5024
|
}
|
|
4914
5025
|
|
|
4915
5026
|
// will retry in intervals of 5, 10, 30
|
|
@@ -4948,43 +5059,52 @@ class ReplayContainer {
|
|
|
4948
5059
|
*/
|
|
4949
5060
|
__init3() {this.recordingMode = 'session';}
|
|
4950
5061
|
|
|
5062
|
+
/**
|
|
5063
|
+
* These are here so we can overwrite them in tests etc.
|
|
5064
|
+
* @hidden
|
|
5065
|
+
*/
|
|
5066
|
+
__init4() {this.timeouts = {
|
|
5067
|
+
sessionIdle: SESSION_IDLE_DURATION,
|
|
5068
|
+
maxSessionLife: MAX_SESSION_LIFE,
|
|
5069
|
+
}; }
|
|
5070
|
+
|
|
4951
5071
|
/**
|
|
4952
5072
|
* Options to pass to `rrweb.record()`
|
|
4953
5073
|
*/
|
|
4954
5074
|
|
|
4955
|
-
|
|
5075
|
+
__init5() {this._performanceObserver = null;}
|
|
4956
5076
|
|
|
4957
|
-
|
|
5077
|
+
__init6() {this._flushLock = null;}
|
|
4958
5078
|
|
|
4959
5079
|
/**
|
|
4960
5080
|
* Timestamp of the last user activity. This lives across sessions.
|
|
4961
5081
|
*/
|
|
4962
|
-
|
|
5082
|
+
__init7() {this._lastActivity = new Date().getTime();}
|
|
4963
5083
|
|
|
4964
5084
|
/**
|
|
4965
5085
|
* Is the integration currently active?
|
|
4966
5086
|
*/
|
|
4967
|
-
|
|
5087
|
+
__init8() {this._isEnabled = false;}
|
|
4968
5088
|
|
|
4969
5089
|
/**
|
|
4970
5090
|
* Paused is a state where:
|
|
4971
5091
|
* - DOM Recording is not listening at all
|
|
4972
5092
|
* - Nothing will be added to event buffer (e.g. core SDK events)
|
|
4973
5093
|
*/
|
|
4974
|
-
|
|
5094
|
+
__init9() {this._isPaused = false;}
|
|
4975
5095
|
|
|
4976
5096
|
/**
|
|
4977
5097
|
* Have we attached listeners to the core SDK?
|
|
4978
5098
|
* Note we have to track this as there is no way to remove instrumentation handlers.
|
|
4979
5099
|
*/
|
|
4980
|
-
|
|
5100
|
+
__init10() {this._hasInitializedCoreListeners = false;}
|
|
4981
5101
|
|
|
4982
5102
|
/**
|
|
4983
5103
|
* Function to stop recording
|
|
4984
5104
|
*/
|
|
4985
|
-
|
|
5105
|
+
__init11() {this._stopRecording = null;}
|
|
4986
5106
|
|
|
4987
|
-
|
|
5107
|
+
__init12() {this._context = {
|
|
4988
5108
|
errorIds: new Set(),
|
|
4989
5109
|
traceIds: new Set(),
|
|
4990
5110
|
urls: [],
|
|
@@ -5034,7 +5154,7 @@ class ReplayContainer {
|
|
|
5034
5154
|
* _performanceObserver, Recording, Sentry SDK, etc)
|
|
5035
5155
|
*/
|
|
5036
5156
|
start() {
|
|
5037
|
-
this.
|
|
5157
|
+
this.setInitialState();
|
|
5038
5158
|
|
|
5039
5159
|
if (!this._loadAndCheckSession()) {
|
|
5040
5160
|
return;
|
|
@@ -5086,7 +5206,24 @@ class ReplayContainer {
|
|
|
5086
5206
|
// Without this, it would record forever, until an error happens, which we don't want
|
|
5087
5207
|
// instead, we'll always keep the last 60 seconds of replay before an error happened
|
|
5088
5208
|
...(this.recordingMode === 'error' && { checkoutEveryNms: ERROR_CHECKOUT_TIME }),
|
|
5089
|
-
emit: this
|
|
5209
|
+
emit: getHandleRecordingEmit(this),
|
|
5210
|
+
onMutation: (mutations) => {
|
|
5211
|
+
if (this._options._experiments.captureMutationSize) {
|
|
5212
|
+
const count = mutations.length;
|
|
5213
|
+
|
|
5214
|
+
if (count > 500) {
|
|
5215
|
+
const breadcrumb = createBreadcrumb({
|
|
5216
|
+
category: 'replay.mutations',
|
|
5217
|
+
data: {
|
|
5218
|
+
count,
|
|
5219
|
+
},
|
|
5220
|
+
});
|
|
5221
|
+
this._createCustomBreadcrumb(breadcrumb);
|
|
5222
|
+
}
|
|
5223
|
+
}
|
|
5224
|
+
// `true` means we use the regular mutation handling by rrweb
|
|
5225
|
+
return true;
|
|
5226
|
+
},
|
|
5090
5227
|
});
|
|
5091
5228
|
} catch (err) {
|
|
5092
5229
|
this._handleException(err);
|
|
@@ -5257,7 +5394,7 @@ class ReplayContainer {
|
|
|
5257
5394
|
// MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
|
|
5258
5395
|
// session+recording. This creates noisy replays that do not have much
|
|
5259
5396
|
// content in them.
|
|
5260
|
-
if (this._lastActivity && isExpired(this._lastActivity,
|
|
5397
|
+
if (this._lastActivity && isExpired(this._lastActivity, this.timeouts.maxSessionLife)) {
|
|
5261
5398
|
// Pause recording
|
|
5262
5399
|
this.pause();
|
|
5263
5400
|
return;
|
|
@@ -5282,6 +5419,25 @@ class ReplayContainer {
|
|
|
5282
5419
|
return false;
|
|
5283
5420
|
}
|
|
5284
5421
|
|
|
5422
|
+
/**
|
|
5423
|
+
* Capture some initial state that can change throughout the lifespan of the
|
|
5424
|
+
* replay. This is required because otherwise they would be captured at the
|
|
5425
|
+
* first flush.
|
|
5426
|
+
*/
|
|
5427
|
+
setInitialState() {
|
|
5428
|
+
const urlPath = `${WINDOW.location.pathname}${WINDOW.location.hash}${WINDOW.location.search}`;
|
|
5429
|
+
const url = `${WINDOW.location.origin}${urlPath}`;
|
|
5430
|
+
|
|
5431
|
+
this.performanceEvents = [];
|
|
5432
|
+
|
|
5433
|
+
// Reset _context as well
|
|
5434
|
+
this._clearContext();
|
|
5435
|
+
|
|
5436
|
+
this._context.initialUrl = url;
|
|
5437
|
+
this._context.initialTimestamp = new Date().getTime();
|
|
5438
|
+
this._context.urls.push(url);
|
|
5439
|
+
}
|
|
5440
|
+
|
|
5285
5441
|
/** A wrapper to conditionally capture exceptions. */
|
|
5286
5442
|
_handleException(error) {
|
|
5287
5443
|
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay]', error);
|
|
@@ -5297,7 +5453,7 @@ class ReplayContainer {
|
|
|
5297
5453
|
*/
|
|
5298
5454
|
_loadAndCheckSession() {
|
|
5299
5455
|
const { type, session } = getSession({
|
|
5300
|
-
|
|
5456
|
+
timeouts: this.timeouts,
|
|
5301
5457
|
stickySession: Boolean(this._options.stickySession),
|
|
5302
5458
|
currentSession: this.session,
|
|
5303
5459
|
sessionSampleRate: this._options.sessionSampleRate,
|
|
@@ -5307,7 +5463,7 @@ class ReplayContainer {
|
|
|
5307
5463
|
// If session was newly created (i.e. was not loaded from storage), then
|
|
5308
5464
|
// enable flag to create the root replay
|
|
5309
5465
|
if (type === 'new') {
|
|
5310
|
-
this.
|
|
5466
|
+
this.setInitialState();
|
|
5311
5467
|
}
|
|
5312
5468
|
|
|
5313
5469
|
const currentSessionId = this.getSessionId();
|
|
@@ -5325,25 +5481,6 @@ class ReplayContainer {
|
|
|
5325
5481
|
return true;
|
|
5326
5482
|
}
|
|
5327
5483
|
|
|
5328
|
-
/**
|
|
5329
|
-
* Capture some initial state that can change throughout the lifespan of the
|
|
5330
|
-
* replay. This is required because otherwise they would be captured at the
|
|
5331
|
-
* first flush.
|
|
5332
|
-
*/
|
|
5333
|
-
_setInitialState() {
|
|
5334
|
-
const urlPath = `${WINDOW.location.pathname}${WINDOW.location.hash}${WINDOW.location.search}`;
|
|
5335
|
-
const url = `${WINDOW.location.origin}${urlPath}`;
|
|
5336
|
-
|
|
5337
|
-
this.performanceEvents = [];
|
|
5338
|
-
|
|
5339
|
-
// Reset _context as well
|
|
5340
|
-
this._clearContext();
|
|
5341
|
-
|
|
5342
|
-
this._context.initialUrl = url;
|
|
5343
|
-
this._context.initialTimestamp = new Date().getTime();
|
|
5344
|
-
this._context.urls.push(url);
|
|
5345
|
-
}
|
|
5346
|
-
|
|
5347
5484
|
/**
|
|
5348
5485
|
* Adds listeners to record events for the replay
|
|
5349
5486
|
*/
|
|
@@ -5395,72 +5532,6 @@ class ReplayContainer {
|
|
|
5395
5532
|
}
|
|
5396
5533
|
}
|
|
5397
5534
|
|
|
5398
|
-
/**
|
|
5399
|
-
* Handler for recording events.
|
|
5400
|
-
*
|
|
5401
|
-
* Adds to event buffer, and has varying flushing behaviors if the event was a checkout.
|
|
5402
|
-
*/
|
|
5403
|
-
__init12() {this._handleRecordingEmit = (
|
|
5404
|
-
event,
|
|
5405
|
-
isCheckout,
|
|
5406
|
-
) => {
|
|
5407
|
-
// If this is false, it means session is expired, create and a new session and wait for checkout
|
|
5408
|
-
if (!this.checkAndHandleExpiredSession()) {
|
|
5409
|
-
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && utils.logger.error('[Replay] Received replay event after session expired.');
|
|
5410
|
-
|
|
5411
|
-
return;
|
|
5412
|
-
}
|
|
5413
|
-
|
|
5414
|
-
this.addUpdate(() => {
|
|
5415
|
-
// The session is always started immediately on pageload/init, but for
|
|
5416
|
-
// error-only replays, it should reflect the most recent checkout
|
|
5417
|
-
// when an error occurs. Clear any state that happens before this current
|
|
5418
|
-
// checkout. This needs to happen before `addEvent()` which updates state
|
|
5419
|
-
// dependent on this reset.
|
|
5420
|
-
if (this.recordingMode === 'error' && event.type === 2) {
|
|
5421
|
-
this._setInitialState();
|
|
5422
|
-
}
|
|
5423
|
-
|
|
5424
|
-
// We need to clear existing events on a checkout, otherwise they are
|
|
5425
|
-
// incremental event updates and should be appended
|
|
5426
|
-
void addEvent(this, event, isCheckout);
|
|
5427
|
-
|
|
5428
|
-
// Different behavior for full snapshots (type=2), ignore other event types
|
|
5429
|
-
// See https://github.com/rrweb-io/rrweb/blob/d8f9290ca496712aa1e7d472549480c4e7876594/packages/rrweb/src/types.ts#L16
|
|
5430
|
-
if (event.type !== 2) {
|
|
5431
|
-
return false;
|
|
5432
|
-
}
|
|
5433
|
-
|
|
5434
|
-
// If there is a previousSessionId after a full snapshot occurs, then
|
|
5435
|
-
// the replay session was started due to session expiration. The new session
|
|
5436
|
-
// is started before triggering a new checkout and contains the id
|
|
5437
|
-
// of the previous session. Do not immediately flush in this case
|
|
5438
|
-
// to avoid capturing only the checkout and instead the replay will
|
|
5439
|
-
// be captured if they perform any follow-up actions.
|
|
5440
|
-
if (this.session && this.session.previousSessionId) {
|
|
5441
|
-
return true;
|
|
5442
|
-
}
|
|
5443
|
-
|
|
5444
|
-
// See note above re: session start needs to reflect the most recent
|
|
5445
|
-
// checkout.
|
|
5446
|
-
if (this.recordingMode === 'error' && this.session && this._context.earliestEvent) {
|
|
5447
|
-
this.session.started = this._context.earliestEvent;
|
|
5448
|
-
this._maybeSaveSession();
|
|
5449
|
-
}
|
|
5450
|
-
|
|
5451
|
-
// Flush immediately so that we do not miss the first segment, otherwise
|
|
5452
|
-
// it can prevent loading on the UI. This will cause an increase in short
|
|
5453
|
-
// replays (e.g. opening and closing a tab quickly), but these can be
|
|
5454
|
-
// filtered on the UI.
|
|
5455
|
-
if (this.recordingMode === 'session') {
|
|
5456
|
-
// We want to ensure the worker is ready, as otherwise we'd always send the first event uncompressed
|
|
5457
|
-
void this.flushImmediate();
|
|
5458
|
-
}
|
|
5459
|
-
|
|
5460
|
-
return true;
|
|
5461
|
-
});
|
|
5462
|
-
};}
|
|
5463
|
-
|
|
5464
5535
|
/**
|
|
5465
5536
|
* Handle when visibility of the page content changes. Opening a new tab will
|
|
5466
5537
|
* cause the state to change to hidden because of content of current page will
|
|
@@ -5509,7 +5580,7 @@ class ReplayContainer {
|
|
|
5509
5580
|
return;
|
|
5510
5581
|
}
|
|
5511
5582
|
|
|
5512
|
-
const expired = isSessionExpired(this.session,
|
|
5583
|
+
const expired = isSessionExpired(this.session, this.timeouts);
|
|
5513
5584
|
|
|
5514
5585
|
if (breadcrumb && !expired) {
|
|
5515
5586
|
this._createCustomBreadcrumb(breadcrumb);
|