import { RuffleObject } from "./ruffle-object"; import { RuffleEmbed } from "./ruffle-embed"; import { installPlugin, FLASH_PLUGIN } from "./plugin-polyfill"; import { publicPath } from "./public-path"; import { Config } from "./config"; let isExtension: boolean; const globalConfig: Config = window.RufflePlayer?.config ?? {}; const jsScriptUrl = publicPath(globalConfig, "ruffle.js") + "ruffle.js"; /** * 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; /** * */ function polyfillFlashInstances(): void { try { // Create live collections to track embed tags. objects = objects || document.getElementsByTagName("object"); embeds = embeds || document.getElementsByTagName("embed"); // Replace first, because often wraps . for (const elem of Array.from(objects)) { if (RuffleObject.isInterdictable(elem)) { const ruffleObject = RuffleObject.fromNativeObjectElement(elem); elem.replaceWith(ruffleObject); } } for (const elem of Array.from(embeds)) { if (RuffleEmbed.isInterdictable(elem)) { const ruffleEmbed = RuffleEmbed.fromNativeEmbedElement(elem); elem.replaceWith(ruffleEmbed); } } } catch (err) { console.error( `Serious error encountered when polyfilling native Flash elements: ${err}` ); } } /** * Inject Ruffle into