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