Natrix.StdWeb
0.2.0
dotnet add package Natrix.StdWeb --version 0.2.0
NuGet\Install-Package Natrix.StdWeb -Version 0.2.0
<PackageReference Include="Natrix.StdWeb" Version="0.2.0" />
<PackageVersion Include="Natrix.StdWeb" Version="0.2.0" />
<PackageReference Include="Natrix.StdWeb" />
paket add Natrix.StdWeb --version 0.2.0
#r "nuget: Natrix.StdWeb, 0.2.0"
#:package Natrix.StdWeb@0.2.0
#addin nuget:?package=Natrix.StdWeb&version=0.2.0
#tool nuget:?package=Natrix.StdWeb&version=0.2.0
Natrix.StdWeb
Natrix.StdWeb provides strongly typed C# wrappers for standard browser APIs. The bindings are generated from WebIDL definitions and are intended for .NET WebAssembly applications that need direct access to the browser platform without a Blazor dependency.
What It Provides
- Generated wrappers for DOM, Fetch, Canvas, WebGL, Web Audio, WebRTC, and other standard Web APIs.
- Typed C# access to browser globals, interfaces, dictionaries, enums, callbacks, and events.
- Integration with Natrix.JSCore for proxy creation, type marshalling, JavaScript object lifetime, and callback interop.
- Generated code based on W3C WebIDL data from webref.
Quick Start
Create a browser WebAssembly project and add the package:
dotnet new wasmbrowser
dotnet add package Natrix.StdWeb
Initialize the StdWeb proxy factory before using generated browser types:
using System.Runtime.InteropServices.JavaScript;
using Natrix.JSCore;
using Natrix.StdWeb;
public static class Program
{
public static async Task Main()
{
await StdWebProxyFactory.InitializeAsync();
var window = JSObjectProxyFactory.GetProxy<Window>(JSHost.GlobalThis);
var document = window.Document;
var message = document.CreateElement("div");
message.TextContent = "Hello from C#!";
document.Body?.AppendChild(message);
var button = document.CreateElement("button");
button.TextContent = "Click me";
document.Body?.AppendChild(button);
button.AddEventListener("click", new EventListener(ev =>
{
window.Console.Log("Button clicked", ev.JSObject);
}), false);
await Task.Delay(Timeout.Infinite);
}
}
Common Patterns
Access browser globals through JSObjectProxyFactory:
var window = JSObjectProxyFactory.GetProxy<Window>(JSHost.GlobalThis);
var document = window.Document;
Cast created elements to their more specific generated type when you need type-specific members:
var input = (HTMLInputElement)document.CreateElement("input");
input.Value = "Initial value";
Keep callback objects alive for as long as JavaScript may invoke them. For one-off application-level handlers, assigning the callback to a field is usually the simplest approach.
Generation
The generated sources live under AutoGen and are produced by ../Natrix.WebIDLGenerator. The generator consumes curated WebIDL definitions from the repository's ../../submodules/webref submodule.
Examples
- ../../examples/Natrix.TodoExample creates and updates DOM nodes directly through StdWeb.
- ../../examples/Natrix.CanvasExample uses generated Canvas bindings for animation.
Requirements
- .NET 9.0 or later
- Browser with WebAssembly support
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Natrix.JSCore (>= 0.2.0)
-
net9.0
- Natrix.JSCore (>= 0.2.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Natrix.StdWeb:
| Package | Downloads |
|---|---|
|
Natrix.Browser.Abstractions
Browser rendering abstractions for Natrix. |
|
|
Natrix.TailwindCss
Tailwind CSS integration for Natrix with source generator support for strongly-typed utility usage. |
GitHub repositories
This package is not used by any popular GitHub repositories.