A small library (~560B gzip’d) to detect which features of WebAssembly are supported in your current browser.
npm install -g wasm-feature-detect
<script type="module">
import { simd } from "https://unpkg.com/wasm-feature-detect?module";
simd().then(simdSupported => {
if (simdSupported) {
/* SIMD support */
} else {
/* No SIMD support */
}
});
</script>
If required, there’s also a UMD version
<script src="https://unpkg.com/wasm-feature-detect/dist/umd/index.js"></script>
<script>
wasmFeatureDetect.simd().then(/* same as above */);
</script>
All detectors return a Promise<bool>
.
Function | Proposal |
---|---|
bulkMemory() |
Bulk memory operations |
exceptions() |
Exception handling |
multiValue() |
Multi-value |
mutableGlobals() |
Importable/Exportable mutable globals |
referenceTypes() |
Reference Types |
saturatedFloatToInt() |
Non-trapping float-to-int conversions |
signExtensions() |
Sign-extension operators |
simd() |
Fixed-Width SIMD |
tailCall() |
Tail call |
threads() |
Threads |
The technical reason is that some tests might have to be augmented to be asynchronous in the future. For example, Firefox is planning to make a change that would require a postMessage
call to detect SABs, which are required for threads.
The other reason is that you should be using WebAssembly.compile
, WebAssembly.instantiate
, or their streaming versions WebAssembly.compileStreaming
and WebAssembly.instantiateStreaming
, which are all asynchronous. You should already be prepared for asynchronous code when using WebAssembly!
License Apache-2.0