From 1e61093e32e25dec5c0a0343a5a930249e52dae6 Mon Sep 17 00:00:00 2001 From: Toad06 Date: Thu, 3 Dec 2020 19:09:07 +0100 Subject: [PATCH] web: Fix issues with iframe polyfill --- web/packages/core/src/polyfills.ts | 308 ++++++++++++---------------- web/packages/core/src/public-api.ts | 4 +- web/packages/core/src/source-api.ts | 6 +- 3 files changed, 142 insertions(+), 176 deletions(-) diff --git a/web/packages/core/src/polyfills.ts b/web/packages/core/src/polyfills.ts index f64fe5e23..c120f39db 100644 --- a/web/packages/core/src/polyfills.ts +++ b/web/packages/core/src/polyfills.ts @@ -4,35 +4,24 @@ import { installPlugin, FLASH_PLUGIN } from "./plugin-polyfill"; import { publicPath } from "./public-path"; import { Config } from "./config"; -if (!window.RufflePlayer) { - window.RufflePlayer = {}; -} -let topLevelRuffleConfig: Config; -let ruffleScriptSrc = publicPath({}, "ruffle.js"); -if (window.RufflePlayer.config) { - topLevelRuffleConfig = window.RufflePlayer.config; - ruffleScriptSrc = publicPath(window.RufflePlayer.config, "ruffle.js"); -} -/* publicPath returns the directory where the file is, * - * so we need to append the filename. We don't need to * - * worry about the directory not having a slash because * - * publicPath appends a slash. */ -ruffleScriptSrc += "ruffle.js"; +let isExtension: boolean; +const globalConfig: Config = window.RufflePlayer?.config ?? {}; +const jsScriptUrl = publicPath(globalConfig, "ruffle.js") + "ruffle.js"; /** - * Polyfill native elements with Ruffle equivalents. + * Polyfill native Flash elements with Ruffle equivalents. * * This polyfill isn't fool-proof: If there's a chance site JavaScript has * access to a pre-polyfill element, then this will break horribly. We can * keep native objects out of the DOM, and thus out of JavaScript's grubby * little hands, but only if we load first. */ -let objects: HTMLCollectionOf; -let embeds: HTMLCollectionOf; +let objects: HTMLCollectionOf; +let embeds: HTMLCollectionOf; /** * */ -function replaceFlashInstances(): void { +function polyfillFlashInstances(): void { try { // Create live collections to track embed tags. objects = objects || document.getElementsByTagName("object"); @@ -47,191 +36,164 @@ function replaceFlashInstances(): void { } for (const elem of Array.from(embeds)) { if (RuffleEmbed.isInterdictable(elem)) { - const ruffleObject = RuffleEmbed.fromNativeEmbedElement(elem); - elem.replaceWith(ruffleObject); + const ruffleEmbed = RuffleEmbed.fromNativeEmbedElement(elem); + elem.replaceWith(ruffleEmbed); } } } catch (err) { console.error( - "Serious error encountered when polyfilling native Flash elements: " + - err + `Serious error encountered when polyfilling native Flash elements: ${err}` ); } } /** + * Inject Ruffle into