Skip to content

Commit

Permalink
web: Throw an error when reference types are unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs committed Dec 2, 2024
1 parent a466802 commit fede393
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions web/packages/core/src/internal/player/inner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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+)?(%)?)/;

Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions web/packages/core/src/internal/ui/panic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 4 additions & 0 deletions web/packages/core/texts/en-US/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fede393

Please sign in to comment.