Skip to content

Commit 3aed9a7

Browse files
authored
feat(replay): try/catch around stopRecording (#6856)
There were rare instances where stopping rrweb.record would cause an exception to bubble up from rrweb.
1 parent f2e00b1 commit 3aed9a7

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

packages/replay/src/replay.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,18 @@ export class ReplayContainer implements ReplayContainerInterface {
209209
* Returns true if it was stopped, else false.
210210
*/
211211
public stopRecording(): boolean {
212-
if (this._stopRecording) {
213-
this._stopRecording();
214-
return true;
215-
}
212+
try {
213+
if (this._stopRecording) {
214+
this._stopRecording();
215+
this._stopRecording = undefined;
216+
return true;
217+
}
216218

217-
return false;
219+
return false;
220+
} catch (err) {
221+
this._handleException(err);
222+
return false;
223+
}
218224
}
219225

220226
/**
@@ -226,7 +232,7 @@ export class ReplayContainer implements ReplayContainerInterface {
226232
__DEBUG_BUILD__ && logger.log('[Replay] Stopping Replays');
227233
this._isEnabled = false;
228234
this._removeListeners();
229-
this._stopRecording && this._stopRecording();
235+
this.stopRecording();
230236
this.eventBuffer && this.eventBuffer.destroy();
231237
this.eventBuffer = null;
232238
this._debouncedFlush.cancel();
@@ -242,14 +248,7 @@ export class ReplayContainer implements ReplayContainerInterface {
242248
*/
243249
public pause(): void {
244250
this._isPaused = true;
245-
try {
246-
if (this._stopRecording) {
247-
this._stopRecording();
248-
this._stopRecording = undefined;
249-
}
250-
} catch (err) {
251-
this._handleException(err);
252-
}
251+
this.stopRecording();
253252
}
254253

255254
/**
@@ -634,8 +633,12 @@ export class ReplayContainer implements ReplayContainerInterface {
634633
* create a new Replay event.
635634
*/
636635
private _triggerFullSnapshot(): void {
637-
__DEBUG_BUILD__ && logger.log('[Replay] Taking full rrweb snapshot');
638-
record.takeFullSnapshot(true);
636+
try {
637+
__DEBUG_BUILD__ && logger.log('[Replay] Taking full rrweb snapshot');
638+
record.takeFullSnapshot(true);
639+
} catch (err) {
640+
this._handleException(err);
641+
}
639642
}
640643

641644
/**

0 commit comments

Comments
 (0)