> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# WebAssembly

3.8
Starting from Lynx 3.8, Lynx provides basic WebAssembly support on Android through the PrimJS runtime integration.

This capability is designed for common WebAssembly loading and execution scenarios in Lynx applications. It is currently available on the background thread only and is not supported on the main thread. The current implementation focuses on practical interoperability between JavaScript and WebAssembly, rather than full compatibility with the complete WebAssembly JavaScript API.

## What Is Supported

Lynx currently supports the following core flows:

- Create modules with `new WebAssembly.Module(...)`
- Instantiate modules with `new WebAssembly.Instance(...)`
- Call exported WebAssembly functions from JavaScript
- Use `WebAssembly.Memory`, `WebAssembly.Table`, and `WebAssembly.Global` in common cases
- Provide function, memory, table, and global imports during instantiation

## Current Limitations

The current support is intentionally scoped.

- This capability is currently available on Android in Lynx 3.8
- WebAssembly is currently available on the background thread only
- WebAssembly is not supported on the main thread
- The complete WebAssembly JavaScript API is not available yet
- Some static APIs on `WebAssembly`, such as `compile`, `instantiate`, `validate`, and streaming variants, are not supported yet
- Some advanced reflection APIs and behaviors are still partial

In practice, it is recommended to use the constructor-based flow based on `WebAssembly.Module` and `WebAssembly.Instance`.

## Example

```js
const module = new WebAssembly.Module(wasmBytes);
const instance = new WebAssembly.Instance(module, imports);

const result = instance.exports.add(1, 2);
```

Try the complete Lynx example below to see the same flow in a page:

**This is an example below: webassembly**

**Entry:** `src`
**Bundle:** `dist/main.lynx.bundle`

```tsx
import { useCallback, useState } from "@lynx-js/react";

import { addWithWasm } from "./addWasm.js";

import "./App.css";

export function App() {
  const [result, setResult] = useState<number | null>(null);
  const [error, setError] = useState<string | null>(null);

  const calculate = useCallback(() => {
    "background-only";
    setError(null);

    try {
      setResult(addWithWasm(1, 2));
    } catch (err) {
      setResult(null);
      setError(err instanceof Error ? err.message : "Failed to run WebAssembly");
    }
  }, []);

  return (
    <page>
      <view className="App">
        <view className="Panel">
          <text className="Eyebrow">WebAssembly on Lynx</text>
          <text className="Title">1 + 2</text>
          <text className="Formula">Calculated by a Wasm add function</text>

          <view className="Button" bindtap={calculate}>
            <text className="ButtonText">Run add(1, 2)</text>
          </view>

          <view className="ResultBox">
            <text className="ResultLabel">Result</text>
            <text className="ResultValue">
              {error ?? (result == null ? "Tap to calculate" : String(result))}
            </text>
          </view>
        </view>
      </view>
    </page>
  );
}

```

v0.3.0



For more details about the underlying runtime support, see the [PrimJS WebAssembly document](https://github.com/lynx-family/primjs/blob/develop/docs/wasm.md).

## Compatibility

**Compatibility Table**

**Query:** `lynx-api.global.WebAssembly`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/global/WebAssembly.json) · [MDN](https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| WebAssembly | Partial (3.8) | Unknown | Unknown | Unknown | Unknown | Yes |

**`WebAssembly`**

<code>WebAssembly</code>

**Status:** Experimental

**Specifications:**
- [https://webassembly.github.io/spec/js-api/#webassembly-namespace](https://webassembly.github.io/spec/js-api/#webassembly-namespace)

- **Android — From 3.8:** Partial support; Available on the background thread only, not on the main thread, via the PrimJS runtime. Supports common module loading and execution flows such as `new WebAssembly.Module()` and `new WebAssembly.Instance()`. The complete WebAssembly JavaScript API is not exposed; static methods such as `WebAssembly.compile()`, `WebAssembly.instantiate()`, `WebAssembly.validate()`, and the streaming variants are not supported yet.

