Skip to main content
net10.0net8.0

Adds a way to run WebAssembly to AngleSharp.

Published
Nov 23, 2026
yesterday
Total Downloads
42.5K
42,525

Install

dotnet add package AngleSharp.Wasm --version 1.2.0-beta.44
ProductVersions
.NET
net10.0net8.0

README

logo

AngleSharp.Wasm

CI GitHub Tag NuGet Count Issues Open CLA Assistant

AngleSharp.Wasm extends the core AngleSharp library with the ability to run WebAssembly. This repository is the home of the source for the AngleSharp.Wasm NuGet package.

Documentation

Further documentation is available in the docs folder:

Basic Configuration

If you just want a configuration that works you should use the following code:

var config = Configuration.Default
    .WithWasm(); // from AngleSharp.Wasm

This will register everything related for running WebAssembly.

Host Imports

If your module imports host functions, register imports via WithWasmImports(...):

var config = Configuration.Default
    .WithWasm()
    .WithWasmImports(_ =>
    {
        return new[]
        {
            new WasmImportFunction(
                "host",
                "answer",
                Array.Empty<WasmValueType>(),
                new[] { WasmValueType.Int32 },
                _ => 41),
        };
    });

DOM / JS Integration

With AngleSharp.Js, scripts get the WebAssembly JavaScript API as in browsers:

const memory = new WebAssembly.Memory({ initial: 1 });
const { instance } = await WebAssembly.instantiateStreaming(fetch('program.wasm'), {
  env: { memory, log: (value) => console.log(value) },
});
new Uint8Array(memory.buffer)[0] = 42;
instance.exports.run();
  • WebAssembly is a namespace object with validate, compile, instantiate, compileStreaming and instantiateStreaming (giving promises) and the interfaces Module, Instance, Memory, Table, Global, Tag, Exception, CompileError, LinkError and RuntimeError.
  • Import objects take functions of scripts, numbers and BigInts (for globals), and memories, tables and globals; instance.exports holds functions scripts call and the objects of memories, tables and globals.
  • memory.buffer is an ArrayBuffer sharing the bytes of the memory (the default Wasmtime backend keeps the memories in pinned .NET arrays), so writes of scripts and of WebAssembly see each other.

The objects of a browsing context live in one Wasmtime store, so they can be imported by any of its modules.

For C#, the synchronous bridge methods remain:

var module = WebAssembly.Compile(context.Current!, wasmBytes);
var instance = WebAssembly.Instantiate(context.Current!, module);
var result = instance.Invoke("answer");

Runtime Backend

The current default backend uses Wasmtime and targets modern .NET runtimes.

Target Frameworks

The current package targets net8.0 and net10.0.

Features

  • Runtime registration via WithWasm()
  • Optional host import registration via WithWasmImports(...)
  • Default Wasmtime backend
  • Module metadata extraction
    • exports()
    • imports()
    • customSections(name)
  • Module validation via validate(bytes)
  • Response-based compilation and instantiation via compileStreaming(response) and instantiateStreaming(response)
  • Compile option routing for builtins and importedStringConstants
  • Instance export access
    • exports lookup by export name
    • export key enumeration
  • Export invocation helpers
    • instance.Invoke(...)
    • WasmJsExportedFunction.Invoke(...)
  • WebAssembly object projections
    • memory buffer, read, write, and grow
    • table length, get, set, and grow
    • global value and valueOf
    • tag type().parameters
    • exception is(tag) and getArg(tag, index)
    • CompileError, LinkError, and RuntimeError
  • Multi-target support for net8.0 and net10.0

Current Scope and Limitations

AngleSharp.Wasm currently provides a practical subset of the WebAssembly JS API.

  • Streaming APIs read the whole response before compiling, because module metadata requires the complete binary.
  • Shared memories (shared: true) are not supported.
  • The JavaScript API needs the default Wasmtime backend; custom runtimes are used by the C# bridge methods.
  • Compile options are validated and forwarded to capable runtimes. Wasmtime 44 does not expose JavaScript string builtins or imported string constants, so requesting either option with the default backend throws NotSupportedException.
  • Exported memories, tables, globals, and tags have object projections; other non-function exports remain descriptors (name, kind).
  • Host-created tags and exceptions are supported. Wasmtime 44 does not expose native Tag or Exception handles or enable exception modules through its .NET API, so runtime-thrown Wasm exceptions are not yet projected.

See Spec Coverage Matrix for a section-by-section status overview.

Participating

Participation in the project is highly welcome. For this project the same rules as for the AngleSharp core project may be applied.

If you have any question, concern, or spot an issue then please report it before opening a pull request. An initial discussion is appreciated regardless of the nature of the problem.

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.

For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.

License

AngleSharp.Wasm is released using the MIT license. For more information see the license file.

Changes from Previous Version

No structural changes between v1.1.1 and v1.2.0-beta.44.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.