From fa6fd6e2b9d81588116a0903203550244050c3b3 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Sun, 6 Sep 2020 16:44:33 +0800 Subject: [PATCH] catch unexpected errors during replay media interactions --- src/replay/index.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index 65ab27eb..35bbee47 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -646,16 +646,24 @@ export class Replayer { return this.debugNodeNotFound(d, d.id); } const mediaEl = (target as Node) as HTMLMediaElement; - if (d.type === MediaInteractions.Pause) { - mediaEl.pause(); - } - if (d.type === MediaInteractions.Play) { - if (mediaEl.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) { - mediaEl.play(); - } else { - mediaEl.addEventListener('canplay', () => { + try { + if (d.type === MediaInteractions.Pause) { + mediaEl.pause(); + } + if (d.type === MediaInteractions.Play) { + if (mediaEl.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) { mediaEl.play(); - }); + } else { + mediaEl.addEventListener('canplay', () => { + mediaEl.play(); + }); + } + } + } catch (error) { + if (this.config.showWarning) { + console.warn( + `Failed to replay media interactions: ${error.message || error}`, + ); } } break;