Merge pull request #27776 from element-hq/dbkr/add_wasm_check

Add a modernizr check for WebAssembly support
pull/27803/head
David Baker 2024-07-18 12:34:08 +00:00 committed by GitHub
commit 1f4006ac13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -79,6 +79,10 @@ function checkBrowserFeatures(): boolean {
// and older Firefox has the former but not the latter, so we add our own. // and older Firefox has the former but not the latter, so we add our own.
window.Modernizr.addTest("intlsegmenter", () => typeof window.Intl?.Segmenter === "function"); window.Modernizr.addTest("intlsegmenter", () => typeof window.Intl?.Segmenter === "function");
// Basic test for WebAssembly support. We could also try instantiating a simple module,
// although this would start to make (more) assumptions about how rust-crypto loads its wasm.
window.Modernizr.addTest("wasm", () => typeof WebAssembly === "object" && typeof WebAssembly.Module === "function");
const featureList = Object.keys(window.Modernizr) as Array<keyof ModernizrStatic>; const featureList = Object.keys(window.Modernizr) as Array<keyof ModernizrStatic>;
let featureComplete = true; let featureComplete = true;
@ -240,6 +244,10 @@ async function start(): Promise<void> {
} }
start().catch((err) => { start().catch((err) => {
// If we get here, things have gone terribly wrong and we cannot load the app javascript at all.
// Show a different, very simple iframed-static error page. Or actually, one of two different ones
// depending on whether the browser is supported (ie. we think we should be able to load but
// failed) or unsupported (where we tried anyway and, lo and behold, we failed).
logger.error(err); logger.error(err);
// show the static error in an iframe to not lose any context / console data // show the static error in an iframe to not lose any context / console data
// with some basic styling to make the iframe full page // with some basic styling to make the iframe full page