A small library to detect which features of WebAssembly are supported in your current browser.
npm install wasm-feature-detectA small library to detect which features of WebAssembly are supported.
- ✅ Runs in browsers, Node and Deno
- ✅ Tree-shakable (only bundle the detectors you use)
- ✅ Provided as an ES6, CommonJS and UMD module.
- ✅ CSP compatible
- ✅ All detectors add up to only ~970B gzipped
```
npm install -g wasm-feature-detect
`html`
`html`
If required, there’s also a UMD version
`html`
All detectors return a Promise.
| Function | Proposal |
| --------------------------- | ------------------------------------------------------------------------------------------------------------ |
| bigInt() | BigInt integration |bulkMemory()
| | Bulk memory operations |exceptions()
| | Legacy Exception Handling |exceptionsFinal()
| | Exception Handling with exnref |extendedConst()
| | Extented Const Expressesions |gc()
| | Garbage Collection |jsStringBuiltins()
| | JS String Builtins Proposal for WebAssembly |jspi()
| | JavaScript Promise Integration |memory64()
| | Memory64 |multiMemory()
| | Multiple Memories |multiValue()
| | Multi-value |mutableGlobals()
| | [Importable/Exportable mutable globals]() |referenceTypes()
| | Reference Types |relaxedSimd()
| | Relaxed SIMD |saturatedFloatToInt()
| | Non-trapping float-to-int conversions |signExtensions()
| | Sign-extension operators |simd()
| | Fixed-Width SIMD |streamingCompilation()
| | Streaming Compilation |tailCall()
| | Tail call |threads()
| | Threads |typeReflection()
| | Type Reflection |typedFunctionReferences()
| | Typed function references |
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][ff coop] 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!
If you want to contribute a new feature test, all you need to do is create a new folder in src/detectors and it will be automatically picked up. The folder may contain a module.wat file, which will be compiled using wabt.js.
`wat
;; Name:
;; Proposal:
;; Features:
(module
;; More WAT code here
)
`
The folder can also contain an optional index.js file, whose default export must be an async function. This function can do additional testing in JavaScript and must return a boolean. See the “threads” detector as an example.module.wat
It must contain at least one of or index.js`.
[ff coop]: https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
[wat2wasm]: https://github.com/webassembly/wabt
---
License Apache-2.0