WebAssembly.validate()

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.

* Some parts of this feature may have varying levels of support.

The WebAssembly.validate() static method validates a given typed array of WebAssembly binary code, returning whether the bytes form a valid Wasm module (true) or not (false).

Syntax

js
WebAssembly.validate(bufferSource)
WebAssembly.validate(bufferSource, compileOptions)

Parameters

bufferSource

A typed array or ArrayBuffer containing WebAssembly binary code to be validated.

compileOptions Optional

An object containing compilation options. This parameter is included on the validate() method so that it can be used to validate modules when the compilation options are present (for example, to implement feature detection). Properties can include:

builtins Optional

An array of strings that enables the usage of JavaScript builtins in the compiled Wasm module. The strings define the builtins you want to enable. Currently the only available value is "js-string", which enables JavaScript string builtins.

importedStringConstants Optional

A string specifying a namespace for imported global string constants. This property needs to be specified if you wish to use imported global string constants in the Wasm module.

Return value

A boolean that specifies whether bufferSource is valid Wasm code (true) or not (false).

Exceptions

If bufferSource is not a typed array or ArrayBuffer, a TypeError is thrown.

Examples

Using validate

The following example (see the validate.html source code, and see it live too) fetches a Wasm module and converts it into a typed array. The validate() method is then used to check whether the module is valid.

js
fetch("simple.wasm")
  .then((response) => response.arrayBuffer())
  .then((bytes) => {
    const valid = WebAssembly.validate(bytes);
    console.log(
      `The given bytes are ${valid ? "" : "not "}a valid Wasm module`,
    );
  });

Validating a module with JavaScript builtins and global string imports enabled

This example validates a Wasm module with JavaScript string builtins and imported global string constants enabled, logging "Wasm module valid: true" to the console if it is valid, and "Wasm module valid: false" if it isn't. See it running live.

js
const compileOptions = {
  builtins: ["js-string"], // Enable JavaScript string builtins
  importedStringConstants: "string_constants", // Enable imported global string constants
};

fetch("log-concat.wasm")
  .then((response) => response.arrayBuffer())
  .then((bytes) => WebAssembly.validate(bytes, compileOptions))
  .then((result) => console.log(`Wasm module valid: ${result}`));

Specifications

Specification
WebAssembly JavaScript Interface
# dom-webassembly-validate

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
validate() static method
Chrome – Full support
Chrome 57 (Release date: 2017-03-09)
footnote Full support
Edge – Full support
Edge 16 (Release date: 2017-10-17)
footnote Full support
Firefox – Full support
Firefox 52 (Release date: 2017-03-07)
footnote Full support
Opera – Full support
Opera 44 (Release date: 2017-03-21)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 57 (Release date: 2017-03-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 52 (Release date: 2017-03-07)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 57 (Release date: 2017-03-16)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 8 (Release date: 2017-05-30)
footnote Full support
compileOptions parameter
Chrome – Full support
Chrome 130 (Release date: 2024-10-15)
footnote Full support
Edge – Full support
Edge 130 (Release date: 2024-10-17)
footnote Full support
Firefox – Full support
Firefox 134 (Release date: 2025-01-07)
footnote Full support
Opera – Full support
Opera 115 (Release date: 2024-11-27)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 130 (Release date: 2024-10-15)
footnote Full support
Firefox for Android – Full support
Firefox for Android 134 (Release date: 2025-01-07)
footnote Full support
Opera Android – Full support
Opera Android 86 (Release date: 2024-12-02)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 28 (Release date: 2025-04-02)
footnote Full support
WebView Android – Full support
WebView Android 130 (Release date: 2024-10-15)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Bun – No support
Bun
footnote No support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also