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.
Further documentation is available in the docs folder:
If you just want a configuration that works you should use the following code:
var config = Configuration.Default
.WithWasm(); // from AngleSharp.WasmThis will register everything related for running WebAssembly.
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),
};
});When using a scripting setup that discovers DOM-annotated members (for example, AngleSharp.Js with registered assemblies), AngleSharp.Wasm exposes a WebAssembly surface under window.WebAssembly.
Available bridge capabilities include:
- Compile module bytes
- Instantiate compiled modules
- Inspect module imports / exports / custom sections
- Access instance exports and invoke exported functions
Typical flow:
var module = WebAssembly.Compile(context.Current!, wasmBytes);
var instance = WebAssembly.Instantiate(context.Current!, module);
var result = instance.Invoke("answer");The current default backend uses Wasmtime and targets modern .NET runtimes.
The current package targets net8.0 and net10.0.
- Runtime registration via
WithWasm() - Optional host import registration via
WithWasmImports(...) - Default Wasmtime backend
- Module metadata extraction
exports()imports()customSections(name)
- Instance export access
exportslookup by export name- export key enumeration
- Export invocation helpers
instance.Invoke(...)WasmJsExportedFunction.Invoke(...)
- Multi-target support for
net8.0andnet10.0
AngleSharp.Wasm currently provides a practical subset of the WebAssembly JS API.
- Bridge methods are synchronous from the caller perspective.
- Promise-based namespace operations are not currently exposed.
validate(...)and streaming APIs are not yet implemented.- Compile options such as builtins / imported string constants are not yet implemented.
- Non-function exports are currently represented as descriptors (
name,kind) rather than fullMemory/Table/Global/Tagobjects.
See Spec Coverage Matrix for a section-by-section status overview.
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.
This project is supported by the .NET Foundation.
AngleSharp.Wasm is released using the MIT license. For more information see the license file.
