From d9e40ebd5146a5eea6f473faac720fbacf7d4cc8 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Mon, 2 Dec 2024 15:33:38 -0500 Subject: [PATCH 1/2] 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. From 7af4d6bf90834b3d66f1fc7abe40fab8286905a9 Mon Sep 17 00:00:00 2001 From: Daniel Jacobs Date: Fri, 3 Jan 2025 10:58:33 -0500 Subject: [PATCH 2/2] web: Check error message on browsers without reference types support --- .../core/src/internal/player/inner.tsx | 11 -------- web/packages/core/src/internal/ui/panic.tsx | 26 +++++++++---------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/web/packages/core/src/internal/player/inner.tsx b/web/packages/core/src/internal/player/inner.tsx index ea305e4c6e93..d8af904f19b8 100644 --- a/web/packages/core/src/internal/player/inner.tsx +++ b/web/packages/core/src/internal/player/inner.tsx @@ -26,7 +26,6 @@ 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+)?(%)?)/; @@ -856,16 +855,6 @@ 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 75cfbae49451..c8893fc397d2 100644 --- a/web/packages/core/src/internal/ui/panic.tsx +++ b/web/packages/core/src/internal/ui/panic.tsx @@ -246,6 +246,19 @@ function createPanicError(error: Error | null): { }; } + if (error.cause.name === "CompileError" && message.includes("bad type")) { + // 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, + ], + }; + } + if (error.cause.name === "CompileError") { // Self hosted: Cannot load `.wasm` file - incorrect configuration or missing files return { @@ -308,19 +321,6 @@ 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"),