Supported Browsers
The output of wasm-bindgen
includes a JS file, and as a result it's good to
know what browsers that file is expected to be used in! By default the output
uses ES modules which isn't implemented in all browsers today, but when using a
bundler (like Webpack) you should be able to produce output suitable for all
browsers.
Firefox, Chrome, Safari, and Edge browsers are all supported by
wasm-bindgen
. If you find a problem in one of these browsers please report
it as we'd like to fix the bug! If you find a bug in another browser we would
also like to be aware of it!
Caveats
-
IE 11 -
wasm-bindgen
by default requires support forWebAssembly
, but no version of IE currently supportsWebAssembly
. You can support IE by compiling wasm files to JS usingwasm2js
(you can see an example of doing this too). Note that at this time no bundler will do this by default, but we'd love to document plugins which do this if you are aware of one! -
Edge before 79+ - the
TextEncoder
andTextDecoder
APIs, whichwasm-bindgen
uses to encode/decode strings between JS and Rust, were not available before version 79. You can polyfill this with at least one of two strategies:-
If using a bundler, you can likely configure the bundler to polyfill these types by default. For example if you're using Webpack you can use the
ProvidePlugin
interface like so after also addingtext-encoding
to yourpackage.json
const webpack = require('webpack'); module.exports = { plugins: [ new webpack.ProvidePlugin({ TextDecoder: ['text-encoding', 'TextDecoder'], TextEncoder: ['text-encoding', 'TextEncoder'] }) ] // ... other configuration options };
Warning: doing this implies the polyfill will always be used, even if native APIs are available. This has a very significant performance impact (the polyfill was measured to be 100x slower in Chromium)!
-
If you're not using a bundler you can also include support manually by adding a
<script>
tag which defines theTextEncoder
andTextDecoder
globals. This StackOverflow question has some example usage and MDN has aTextEncoder
polyfill implementation to get you started as well.
-
-
BigInt and
u64
- currently the WebAssembly specification for the web forbids the usage of 64-bit integers (Rust typesi64
andu64
) in exported/imported functions. When usingwasm-bindgen
, however,u64
is allowed! The reason for this is that it's translated to theBigInt
type in JS. TheBigInt
class is supported by all major browsers starting in the following versions: Chrome 67+, Firefox 68+, Edge 79+, and Safari 14+.
If you find other incompatibilities please report them to us! We'd love to either keep this list up-to-date or fix the underlying bugs :)