Skip to content

Commit 34c5ed7

Browse files
committed
feat(replay): try/catch around stopRecording
There were rare instances where stopping rrweb.record would cause an exception to bubble up from rrweb.
1 parent 4b1bc47 commit 34c5ed7

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
@@ -214,12 +214,18 @@ export class ReplayContainer implements ReplayContainerInterface {
214214
* Returns true if it was stopped, else false.
215215
*/
216216
public stopRecording(): boolean {
217-
if (this._stopRecording) {
218-
this._stopRecording();
219-
return true;
220-
}
217+
try {
218+
if (this._stopRecording) {
219+
this._stopRecording();
220+
this._stopRecording = undefined;
221+
return true;
222+
}
221223

222-
return false;
224+
return false;
225+
} catch (err) {
226+
this._handleException(err);
227+
return false;
228+
}
223229
}
224230

225231
/**
@@ -231,7 +237,7 @@ export class ReplayContainer implements ReplayContainerInterface {
231237
__DEBUG_BUILD__ && logger.log('[Replay] Stopping Replays');
232238
this._isEnabled = false;
233239
this._removeListeners();
234-
this._stopRecording && this._stopRecording();
240+
this.stopRecording();
235241
this.eventBuffer && this.eventBuffer.destroy();
236242
this.eventBuffer = null;
237243
this._debouncedFlush.cancel();
@@ -247,14 +253,7 @@ export class ReplayContainer implements ReplayContainerInterface {
247253
*/
248254
public pause(): void {
249255
this._isPaused = true;
250-
try {
251-
if (this._stopRecording) {
252-
this._stopRecording();
253-
this._stopRecording = undefined;
254-
}
255-
} catch (err) {
256-
this._handleException(err);
257-
}
256+
this.stopRecording();
258257
}
259258

260259
/**
@@ -658,8 +657,12 @@ export class ReplayContainer implements ReplayContainerInterface {
658657
* create a new Replay event.
659658
*/
660659
private _triggerFullSnapshot(): void {
661-
__DEBUG_BUILD__ && logger.log('[Replay] Taking full rrweb snapshot');
662-
record.takeFullSnapshot(true);
660+
try {
661+
__DEBUG_BUILD__ && logger.log('[Replay] Taking full rrweb snapshot');
662+
record.takeFullSnapshot(true);
663+
} catch (err) {
664+
this._handleException(err);
665+
}
663666
}
664667

665668
/**

0 commit comments

Comments
 (0)