WebAssembly

The WebAssembly JavaScript object acts as the namespace for all WebAssembly-related functionality.

Unlike most other global objects, WebAssembly is not a constructor (it is not a function object). You can compare it to Math, which is also a namespace object for mathematical constants and functions, or to Intl which is the namespace object for internationalization constructors and other language-sensitive functions.

Description

The primary uses for the WebAssembly object are:

Constructor properties

WebAssembly.CompileError()
Indicates an error during WebAssembly decoding or validation.
WebAssembly.Global()
Represents a global variable instance, accessible from both JavaScript and importable/exportable across one or more WebAssembly.Module instances. This allows dynamic linking of multiple modules.
WebAssembly.Instance()
Is a stateful, executable instance of a WebAssembly.Module
WebAssembly.LinkError()
Indicates an error during module instantiation (besides traps from the start function).
WebAssembly.Memory()
An object whose buffer property is a resizable ArrayBuffer that holds the raw bytes of memory accessed by a WebAssembly Instance.
WebAssembly.Module()
Contains stateless WebAssembly code that has already been compiled by the browser and can be efficiently shared with Workers, and instantiated multiple times.
WebAssembly.RuntimeError()
Error type that is thrown whenever WebAssembly specifies a trap.
WebAssembly.Table()
An array-like structure representing a WebAssembly Table, which stores function references.

Static methods

WebAssembly.instantiate()
The primary API for compiling and instantiating WebAssembly code, returning both a Module and its first Instance.
WebAssembly.instantiateStreaming()
Compiles and instantiates a WebAssembly module directly from a streamed underlying source, returning both a Module and its first Instance.
WebAssembly.compile()
Compiles a WebAssembly.Module from WebAssembly binary code, leaving instantiation as a separate step.
WebAssembly.compileStreaming()
compiles a WebAssembly.Module directly from a streamed underlying source, leaving instantiation as a separate step.
WebAssembly.validate()
Validates a given typed array of WebAssembly binary code, returning whether the bytes are valid WebAssembly code (true) or not (false).

Examples

Stream a .wasm module then compile and instantiate it

The following example (see our instantiate-streaming.html demo on GitHub, and view it live also) directly streams a .wasm module from an underlying source then compiles and instantiates it, the promise fulfilling with a ResultObject. Because the instantiateStreaming() function accepts a promise for a Response object, you can directly pass it a WindowOrWorkerGlobalScope.fetch() call, and it will pass the response into the function when it fulfills.

var importObject = { imports: { imported_func: arg => console.log(arg) } };

WebAssembly.instantiateStreaming(fetch('simple.wasm'), importObject)
.then(obj => obj.instance.exports.exported_func());

The ResultObject's instance member is then accessed, and the contained exported function invoked.

Specifications

Specification
WebAssembly JavaScript Interface
The definition of 'WebAssembly' in that specification.

Browser compatibility

DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
WebAssemblyChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
CompileErrorChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
GlobalChrome Full support 69Edge No support NoFirefox Full support 62IE No support NoOpera No support NoSafari No support NoWebView Android Full support 69Chrome Android Full support 69Firefox Android Full support 62Opera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 10.0nodejs No support No
InstanceChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
LinkErrorChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
MemoryChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
ModuleChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
RuntimeErrorChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
TableChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
compileChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
compileStreamingChrome Full support 61Edge Full support 16Firefox Full support 58IE No support NoOpera Full support 47Safari No support NoWebView Android Full support 61Chrome Android Full support 61Firefox Android Full support 58Opera Android Full support 45Safari iOS No support NoSamsung Internet Android Full support 8.0nodejs No support No
instantiateChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0
instantiateStreamingChrome Full support 61Edge Full support 16Firefox Full support 58IE No support NoOpera Full support 47Safari No support NoWebView Android Full support 61Chrome Android Full support 61Firefox Android Full support 58Opera Android Full support 45Safari iOS No support NoSamsung Internet Android Full support 8.0nodejs No support No
validateChrome Full support 57Edge Full support 16Firefox Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
IE No support NoOpera Full support 44Safari Full support 11WebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52
Notes
Full support 52
Notes
Notes Disabled in the Firefox 52 Extended Support Release (ESR).
Opera Android Full support 43Safari iOS Full support 11Samsung Internet Android Full support 7.0nodejs Full support 8.0.0

Legend

Full support
Full support
No support
No support
See implementation notes.
See implementation notes.

See also