From fabb11a78222a06991f428dd7fccffde8e2221cf Mon Sep 17 00:00:00 2001 From: Robert DeLuca Date: Tue, 29 Mar 2022 12:45:42 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Wrap=20`serializeVideos`=20in=20?= =?UTF-8?q?try/catch=20to=20catch=20security=20errors=20(#848)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes it's not possible to serialize videos into poster due to security (`Tainted canvases may not be exported.`). Wrapping the `serializeVideos` function call in a try/catch will allow the DOM serialization to continue --- packages/dom/src/serialize-video.js | 3 ++- packages/dom/test/serialize-videos.test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/dom/src/serialize-video.js b/packages/dom/src/serialize-video.js index fa7532568..0f84b3c92 100644 --- a/packages/dom/src/serialize-video.js +++ b/packages/dom/src/serialize-video.js @@ -9,10 +9,11 @@ export function serializeVideos(dom, clone) { let canvas = document.createElement('canvas'); let width = canvas.width = video.videoWidth; let height = canvas.height = video.videoHeight; + let dataUrl; canvas.getContext('2d').drawImage(video, 0, 0, width, height); + try { dataUrl = canvas.toDataURL(); } catch {} - let dataUrl = canvas.toDataURL(); // If the canvas produces a blank image, skip if (!dataUrl || dataUrl === 'data:,') continue; diff --git a/packages/dom/test/serialize-videos.test.js b/packages/dom/test/serialize-videos.test.js index 31cecbea6..4270d2bf9 100644 --- a/packages/dom/test/serialize-videos.test.js +++ b/packages/dom/test/serialize-videos.test.js @@ -37,4 +37,15 @@ describe('serializeVideos', () => { $ = parseDOM(serializeDOM()); expect($('#video')[0].getAttribute('poster')).toBe(null); }); + + it('does not hang serialization when there is an error thrown', () => { + withExample(` +