GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — WebAssembly.Module - WebAssembly | MDN

WebAssembly.Module

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.

  • See full compatibility
  • Learn more

A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser — this can be efficiently shared with Workers, and instantiated multiple times.

WebAssembly.Module is a subclass of the hidden AbstractModuleSource class, in environments that support AbstractModuleSource.

Note: The WebAssembly.Module object is unrelated to the Module object used in Emscripten.

Constructor

WebAssembly.Module()

Creates a new Module object.

Static methods

WebAssembly.Module.customSections()

Given a Module and string, returns a copy of the contents of all custom sections in the module with the given string name.

WebAssembly.Module.exports()

Given a Module, returns an array containing descriptions of all the declared exports.

WebAssembly.Module.imports()

Given a Module, returns an array containing descriptions of all the declared imports.

Examples

Sending a compiled module to a worker

The following example compiles the loaded simple.wasm byte code using the WebAssembly.compileStreaming() method and sends the resulting Module instance to a worker using postMessage().

See the index-compile.html source code or view it live.

js
const worker = new Worker("wasm_worker.js");

WebAssembly.compileStreaming(fetch("simple.wasm")).then((mod) =>
  worker.postMessage(mod),
);

The worker function wasm_worker.js defines an import object for the module to use. The function then sets up an event handler to receive the module from the main thread. When the module is received, we create an instance from it using the WebAssembly.instantiate() method and invoke an exported function from inside it.

js
const importObject = {
  my_namespace: {
    imported_func(arg) {
      console.log(arg);
    },
  },
};

onmessage = (e) => {
  console.log("module received from main thread");
  const mod = e.data;

  WebAssembly.instantiate(mod, importObject).then((instance) => {
    instance.exports.exported_func();
  });
};

Obtaining the module using import source

In environments that support source phase imports, you can obtain a WebAssembly.Module object using the import source statement or the import.source() operator. Both avoid the need to call fetch() or WebAssembly.compileStreaming(), relying instead on the default module loader machinery.

js
import source modSource from "./simple.wasm";

const worker = new Worker("wasm_worker.js");
worker.postMessage(modSource);

Specifications

Specification
WebAssembly JavaScript Interface
# modules

Browser compatibility

See also

  • WebAssembly overview
  • WebAssembly concepts
  • Using the WebAssembly JavaScript API

Help improve MDN

Learn how to contribute

This page was last modified on Sep 11, 2026 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.