From fede393f3b63afce0e6d1b8c33aa045347aac5a2 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Mon, 2 Dec 2024 15:33:38 -0500 Subject: [PATCH] web: Throw an error when reference types are unsupported --- web/packages/core/src/internal/player/inner.tsx | 11 +++++++++++ web/packages/core/src/internal/ui/panic.tsx | 13 +++++++++++++ web/packages/core/texts/en-US/messages.ftl | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/web/packages/core/src/internal/player/inner.tsx b/web/packages/core/src/internal/player/inner.tsx index d8af904f19b8..ea305e4c6e93 100644 --- a/web/packages/core/src/internal/player/inner.tsx +++ b/web/packages/core/src/internal/player/inner.tsx @@ -26,6 +26,7 @@ import { showPanicScreen } from "../ui/panic"; import { createRuffleBuilder } from "../../load-ruffle"; import { lookupElement } from "../register-element"; import { configureBuilder } from "../builder"; +import { referenceTypes } from "wasm-feature-detect"; const DIMENSION_REGEX = /^\s*(\d+(\.\d+)?(%)?)/; @@ -855,6 +856,16 @@ export class InnerPlayer { this.loadedConfig.backgroundColor; } + // We may theoretically need to check everything listed on https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-unknown-unknown.md#enabled-webassembly-features + // but this is the only extension I know completely breaks our WASM module if unsupported + const necessaryExtensionsSupported: boolean = await referenceTypes(); + if (!necessaryExtensionsSupported) { + const baseError = new Error("Necessary WebAssembly extensions unsupported"); + const loadError = new LoadRuffleWasmError(baseError); + this.panic(loadError); + return; + } + await this.ensureFreshInstance(); if ("url" in options) { diff --git a/web/packages/core/src/internal/ui/panic.tsx b/web/packages/core/src/internal/ui/panic.tsx index 0461358c2c50..75cfbae49451 100644 --- a/web/packages/core/src/internal/ui/panic.tsx +++ b/web/packages/core/src/internal/ui/panic.tsx @@ -308,6 +308,19 @@ function createPanicError(error: Error | null): { }; } + if (message === "necessary webassembly extensions unsupported") { + // Self hosted: User has a browser without support for necessary WebAssembly extensions + return { + body: textAsParagraphs("error-wasm-unsupported-browser"), + actions: [ + CommonActions.openWiki( + "#web", + ), + CommonActions.ShowDetails, + ], + }; + } + // Self hosted: Cannot load `.wasm` file - file not found return { body: textAsParagraphs("error-wasm-not-found"), diff --git a/web/packages/core/texts/en-US/messages.ftl b/web/packages/core/texts/en-US/messages.ftl index a4a950894090..4534186eadaf 100644 --- a/web/packages/core/texts/en-US/messages.ftl +++ b/web/packages/core/texts/en-US/messages.ftl @@ -68,6 +68,10 @@ error-wasm-disabled-on-edge = To fix this, try opening your browser's settings, clicking "Privacy, search, and services", scrolling down, and turning off "Enhance your security on the web". This will allow your browser to load the required ".wasm" files. If the issue persists, you might have to use a different browser. +error-wasm-unsupported-browser = + The browser you are using does not support the WebAssembly extensions Ruffle requires to run. + Please switch to a supported browser. + You can find a list of supported browsers on the Wiki. error-javascript-conflict = Ruffle has encountered a major issue whilst trying to initialize. It seems like this page uses JavaScript code that conflicts with Ruffle.