Skip to content

Commit

Permalink
web: Check error message on browsers without reference types support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhjacobs authored and torokati44 committed Jan 10, 2025
1 parent d9e40eb commit 7af4d6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
11 changes: 0 additions & 11 deletions web/packages/core/src/internal/player/inner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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+)?(%)?)/;

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

0 comments on commit 7af4d6b

Please sign in to comment.