From 4ed247006830fbcaedd7bf275e6ba6fb54ec03ff Mon Sep 17 00:00:00 2001 From: Toad06 Date: Sat, 5 Dec 2020 16:48:19 +0100 Subject: [PATCH] web: Fix possible issue with iframe elements no longer existing in the DOM --- web/packages/core/src/polyfills.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/packages/core/src/polyfills.ts b/web/packages/core/src/polyfills.ts index c120f39db..92a8cdb74 100644 --- a/web/packages/core/src/polyfills.ts +++ b/web/packages/core/src/polyfills.ts @@ -123,6 +123,10 @@ async function injectRuffle( let elementDocument: HTMLDocument; try { elementDocument = elementWindow.document; + if (!elementDocument) { + // Don't polyfill if the window has no document: the element may have been removed from the parent window. + return; + } } catch (err) { if (!isExtension) { console.warn(errorMessage + err); @@ -156,7 +160,7 @@ async function injectRuffle( // Merge parent window and frame configurations, will likely be applied too late though. elementWindow.RufflePlayer.config = { ...globalConfig, - ...(elementWindow.RufflePlayer?.config ?? {}), + ...(elementWindow.RufflePlayer.config ?? {}), }; } }