Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 4 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,8 @@ on: [push, pull_request]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCS_PATH: ${{ secrets.DOCS_PATH }}
DOCS_BRANCH: ${{ secrets.DOCS_BRANCH }}

jobs:
can_document:
runs-on: ubuntu-latest
outputs:
value: ${{ steps.check_job.outputs.value }}
steps:
- name: Checks whether documentation can be built
id: check_job
run: |
echo "value: ${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}"
echo "::set-output name=value::${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}"

documentation:
needs: [can_document]
runs-on: ubuntu-latest
if: needs.can_document.outputs.value == 'true'

steps:
- uses: actions/checkout@v5

- name: Use Node.js
uses: actions/setup-node@v5
with:
node-version: "20.x"
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: |
cd $DOCS_PATH
npm install

- name: Deploy Doclet
run: |
cd $DOCS_PATH
npx pilet publish --fresh --url https://feed.piral.cloud/api/v1/pilet/anglesharp --api-key ${{ secrets.PIRAL_FEED_KEY }}

linux:
runs-on: ubuntu-latest

Expand All @@ -56,7 +19,7 @@ jobs:
10.0.x

- name: Build
run: ./build.sh -AngleSharpVersion 1.5.0
run: ./build.sh -AngleSharpVersion 1.11.0

windows:
runs-on: windows-latest
Expand Down Expand Up @@ -87,9 +50,9 @@ jobs:
NUGET_API_KEY: ${{ steps.nuget_login.outputs.NUGET_API_KEY }}
run: |
if ($env:GITHUB_REF -eq "refs/heads/main") {
.\build.ps1 -Target Publish -AngleSharpVersion 1.5.0
.\build.ps1 -Target Publish -AngleSharpVersion 1.11.0
} elseif ($env:GITHUB_REF -eq "refs/heads/devel") {
.\build.ps1 -Target PrePublish -AngleSharpVersion 1.5.0
.\build.ps1 -Target PrePublish -AngleSharpVersion 1.11.0
} else {
.\build.ps1 -AngleSharpVersion 1.5.0
.\build.ps1 -AngleSharpVersion 1.11.0
}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 1.2.0

Released on Tuesday, November 24 2026.

- Updated `WebAssembly` to no longer appear as members or global members
- Updated minimum version of AngleSharp to 1.11.0
- Added the WebAssembly JavaScript API as in browsers for scripts
- Added `memory.buffer` sharing the bytes of the memory with scripts
- Added import objects of scripts
- Added `WasmDom.Register`, the DOM of this library declared for a scripting engine

# 1.1.1

Released on Thursday, November 12 2026.
Expand Down
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,24 @@ var config = Configuration.Default

## DOM / JS Integration

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`.
With AngleSharp.Js, scripts get the WebAssembly JavaScript API as in browsers:

```js
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();
```

Available bridge capabilities include:
- `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.

- Compile module bytes
- Instantiate compiled modules
- Inspect module imports / exports / custom sections
- Access instance exports and invoke exported functions
The objects of a browsing context live in one Wasmtime store, so they can be imported by any of its modules.

Typical flow:
For C#, the synchronous bridge methods remain:

```cs
var module = WebAssembly.Compile(context.Current!, wasmBytes);
Expand Down Expand Up @@ -110,9 +118,9 @@ The current package targets `net8.0` and `net10.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.
- Streaming APIs synchronously buffer AngleSharp response streams because module metadata requires the complete binary.
- 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.
Expand Down
14 changes: 13 additions & 1 deletion docs/general/01-Basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ You need to have AngleSharp installed already. This could be done via NuGet:
Install-Package AngleSharp
```

If you want JavaScript-side access to `window.WebAssembly`, you also need a scripting setup (for example, AngleSharp.Js) that discovers exported DOM members from loaded assemblies.
If you want JavaScript-side access to `window.WebAssembly`, you also need a scripting setup (for example, AngleSharp.Js) that discovers exported DOM members from loaded assemblies, or is given the registration of this library (see below).

## Getting AngleSharp.Wasm over NuGet

Expand Down Expand Up @@ -60,6 +60,18 @@ var config = Configuration.Default
});
```

## Scripting Without Reflection

AngleSharp.Js finds the DOM of this library by reflecting over its DOM attributes by default. A trimmed or natively compiled (AoT) application can instead hand it the registration generated for this library at build time, `AngleSharp.Wasm.WasmDom.Register` (a `DomRegistration` of AngleSharp). It declares the `WebAssembly` namespace with its interfaces (`WebAssembly.Module`, `WebAssembly.Memory`, ...):

```cs
var config = Configuration.Default
.WithWasm()
.WithJs(WasmDom.Register);
```

The registration describes the version of the library in use, so it never has to be kept in sync by hand. Several libraries are combined with `DomRegistrations.Combine`.

## What Works Today

- `WithWasm()` registers a default Wasmtime-backed runtime factory.
Expand Down
26 changes: 13 additions & 13 deletions docs/general/02-Spec-Coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ Status values:

| Spec Area | Status | Notes |
| --- | --- | --- |
| WebAssembly namespace: `compile(bytes)` | Partial | Exposed as synchronous bridge method `WebAssembly.compile(byte[])`. |
| WebAssembly namespace: `instantiate(...)` | Partial | Exposed as synchronous bridge method `WebAssembly.instantiate(WasmJsModule)`. |
| WebAssembly namespace: `compile(bytes)` | Implemented | `WebAssembly.compile(bytes)` gives a promise of a `WebAssembly.Module`, rejected with a `CompileError` for invalid bytes. The synchronous `WebAssembly.Compile(window, bytes)` remains for C#. |
| WebAssembly namespace: `instantiate(...)` | Implemented | `WebAssembly.instantiate(bytes, importObject)` gives a promise of `{ module, instance }`, `instantiate(module, importObject)` one of the instance. Imports are read from the import object (functions, numbers, BigInts, memories, tables and globals); failures reject with a `LinkError` or `RuntimeError`. |
| WebAssembly namespace: `validate(bytes)` | Implemented | Exposed as synchronous `WebAssembly.validate(byte[])`, using native Wasmtime validation or compile-and-dispose fallback for custom runtimes. |
| WebAssembly namespace: streaming APIs | Partial | `compileStreaming(IResponse)` and `instantiateStreaming(IResponse)` synchronously consume successful `application/wasm` AngleSharp responses. Response bodies are buffered for metadata extraction. |
| WebAssembly namespace: streaming APIs | Implemented | `compileStreaming` and `instantiateStreaming` take a `Response` of `fetch()` (or a promise of one, or an AngleSharp `IResponse`), which has to be successful and of the type `application/wasm`; the body is read completely before compiling. |
| WebAssembly namespace: compile options | Partial | `WasmCompileOptions` validates and routes `builtins` and `importedStringConstants` through compile, byte instantiate, and streaming entry points. Wasmtime 44 cannot execute these options. |
| `Module.exports(module)` | Partial | Available as instance method `module.exports()` returning descriptor objects. |
| `Module.imports(module)` | Partial | Available as instance method `module.imports()` returning descriptor objects. |
| `Module.customSections(module, name)` | Partial | Available as instance method `module.customSections(name)` returning `byte[][]`. |
| `Instance.exports` | Partial | Available as `instance.exports`, with function, memory, table, global, and tag wrappers plus descriptor values for other export kinds. |
| Exported function invocation | Implemented | Supported via `instance.invoke(...)` and `WasmJsExportedFunction.invoke(...)`. |
| Host import functions | Implemented | Supported via `WithWasmImports(...)` and `WasmImportFunction`. |
| Memory object API (`Memory`) | Partial | Exported memories expose `buffer`, `read(offset, count)`, `write(offset, bytes)`, and `grow(delta)`. `buffer` is a current `byte[]` snapshot rather than a live JavaScript `ArrayBuffer`; memory construction and imports are not yet exposed. |
| Table object API (`Table`) | Partial | Exported `funcref` and `externref` tables expose `length`, `get(index)`, `set(index, value)`, and `grow(delta, value)`. Table construction and imports are not yet exposed. |
| Global object API (`Global`) | Partial | Exported numeric and reference globals expose a mutable or immutable `value` accessor and `valueOf()`. Global construction and imports are not yet exposed. |
| `Module.exports(module)` | Implemented | `WebAssembly.Module.exports(module)` gives descriptor objects (`name`, `kind`). |
| `Module.imports(module)` | Implemented | `WebAssembly.Module.imports(module)` gives descriptor objects (`module`, `name`, `kind`). |
| `Module.customSections(module, name)` | Implemented | `WebAssembly.Module.customSections(module, name)` gives ArrayBuffers. |
| `Instance.exports` | Implemented | An object with the exports in the order of the module: functions scripts call (the same function for the same export), and `WebAssembly.Memory`, `Table` and `Global` objects. `new WebAssembly.Instance(module, importObject)` instantiates synchronously. |
| Exported function invocation | Implemented | Exported functions are functions of scripts, converting their arguments and results as the standard says (`i64` as BigInt); a trap is a `RuntimeError`, and what a function of a script imported by the module threw reaches the caller as it is. |
| Host import functions | Implemented | Functions of scripts in the import object, and C# functions via `WithWasmImports(...)` and `WasmImportFunction`. |
| Memory object API (`Memory`) | Implemented | `new WebAssembly.Memory({ initial, maximum })`, imports and exports. With the default Wasmtime backend `buffer` is an ArrayBuffer sharing the bytes of the memory (the memories are pinned .NET arrays, via Wasmtime's host memory creator), which is a new one after the memory has grown. Shared memories are not supported. |
| Table object API (`Table`) | Implemented | `new WebAssembly.Table({ element, initial, maximum })`, imports and exports, with `length`, `get(index)`, `set(index, value)` and `grow(delta, value)`. |
| Global object API (`Global`) | Implemented | `new WebAssembly.Global({ value, mutable }, value)`, imports (also of numbers and BigInts) and exports, with `value` and `valueOf()`. |
| Tag object API (`Tag`) | Partial | Host-created and exported tags expose `type().parameters`, including re-exported imported tags. Wasmtime 44 does not expose native Tag handles or enable exception modules through its .NET API. |
| Exception object API (`Exception`) | Partial | Host-created exceptions validate typed payloads and expose `is(tag)` and `getArg(tag, index)`. Runtime-thrown Wasm exceptions cannot be projected through Wasmtime 44. |
| Error constructors (`CompileError`, `LinkError`, `RuntimeError`) | Implemented | Public DOM-named constructors are available, and compile, instantiate/link, and execution failures are translated at bridge boundaries. |
Expand Down Expand Up @@ -66,4 +66,4 @@ The current implementation is validated by runtime and bridge tests in the repos
## Interpretation Notes

This matrix reflects API shape and behavior in AngleSharp.Wasm, not strict one-to-one Web IDL signatures.
Where the specification defines static namespace or Promise-based operations, AngleSharp.Wasm may expose equivalent functionality through synchronous bridge methods.
Scripts (with AngleSharp.Js) see the API of the standard: `WebAssembly` is a namespace object holding the interfaces (`WebAssembly.Module`, `Instance`, `Memory`, `Table`, `Global`, `Tag`, `Exception` and the errors), and its operations give promises. The synchronous bridge methods remain for C#.
28 changes: 0 additions & 28 deletions src/AngleSharp.Wasm.Docs/docs.config.json

This file was deleted.

58 changes: 0 additions & 58 deletions src/AngleSharp.Wasm.Docs/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions src/AngleSharp.Wasm.Docs/src/index.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions src/AngleSharp.Wasm.Docs/tsconfig.json

This file was deleted.

Loading