unoplatform / Uno.Wasm.Bootstrap

A simple nuget package to run C# code in a WASM-compatible browser
Other
373 stars 57 forks source link

Add detection of missing Wasm support #538

Open jeromelaban opened 2 years ago

jeromelaban commented 2 years ago

"Enhanced security" for Edge allows for disabling WebAssembly, and the default index.html does not notify of that situation.

See https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/issues/1507

Implementation

Fixing this issue requires the addition of a new check in the default index.html:

https://github.com/unoplatform/Uno.Wasm.Bootstrap/blob/fbc462e7c6af3d83a989b957798a30cd9ba458ac/src/Uno.Wasm.Bootstrap/Templates/index.html#L28

which validates for the presence of Wasm similar to the way javascript is detected. If not possible, we should be modifying the bootstrapper to make such validations (e.g. validating that WebAssembly is a known symbol), likely after this block:

https://github.com/unoplatform/Uno.Wasm.Bootstrap/blob/fbc462e7c6af3d83a989b957798a30cd9ba458ac/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts#L65

by adding an error message, and likely unhiding a div that would explain to the use that WebAssembly is required, and explain that protected mode is enabled.

Nirmal4G commented 2 years ago

github.com/unoplatform/Uno.Wasm.Bootstrap/blob/3e7cc247cb2851ef9d8293071ed54433e20bfac2/doc/src/Uno.Wasm.Bootstrap/Templates/index.html

Link is broken!!

Nirmal4G commented 2 years ago

There's an existing lib at wasm-feature-detect to dectect WASM support but do you guys provide any inbuilt API for this? I can't seem to find it!

There's a SA post on how to do this too:

Stack Overflow
How can I check if a browser supports WebAssembly?
With support for WebAssembly coming into all new major browsers, how can I check whether the current browser which is visiting my website supports it?
jeromelaban commented 2 years ago

Link is broken!!

The link is fine, it points the section detailing where javascript is detected.

As for the ways to detect, yes wasm-feature-detect could be used. It's a bit large for what we need, but it could do.

Nirmal4G commented 2 years ago
image
Nirmal4G commented 2 years ago

While this link in the NPE issue comment works just fine. But the link in the markdown file is broken!

github.com/unoplatform/Uno.Wasm.Bootstrap/blob/2ca1f3f426d59c56cf8c4c553470858c53361dd9/src/Uno.Wasm.Bootstrap/Templates/index.html#L28-L30

https://github.com/unoplatform/Uno.Wasm.Bootstrap/blob/2ca1f3f426d59c56cf8c4c553470858c53361dd9/src/Uno.Wasm.Bootstrap/Templates/index.html#L28-L30

jeromelaban commented 2 years ago

Ah! This is in the markdown. Got it, will fix.