Skip to content

Latest commit

 

History

History
133 lines (102 loc) · 10.7 KB

File metadata and controls

133 lines (102 loc) · 10.7 KB

SpawnDev.BlazorJS API Reference

Complete C# API documentation for browser APIs via Blazor WebAssembly. SpawnDev.BlazorJS provides 1,021 strongly typed C# wrappers that mirror the MDN Web API surface, giving Blazor WebAssembly applications full access to every browser API without writing a single line of JavaScript.

MDN Mapping: Every type listed in this documentation maps directly to its equivalent on MDN Web Docs. Where an MDN page exists for a JavaScript API, the corresponding SpawnDev.BlazorJS wrapper implements the same properties, methods, and events with C#-idiomatic naming. When in doubt, check the MDN page for the underlying JS behavior.

NuGet

Supported .NET Versions: .NET 8, 9, and 10

Live Demo: blazorjs.spawndev.com


Getting Started

Two changes to Program.cs are all you need:

using SpawnDev.BlazorJS;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

// 1. Add BlazorJSRuntime
builder.Services.AddBlazorJSRuntime();

// 2. Use BlazorJSRunAsync instead of RunAsync
await builder.Build().BlazorJSRunAsync();

Then inject BlazorJSRuntime into any component or service:

[Inject]
BlazorJSRuntime JS { get; set; }

For full setup details including worker scope detection and WebWorkerService, see Getting Started.


Core Concepts

These guides cover the foundational types and patterns that every SpawnDev.BlazorJS developer should understand.

Guide Description
Getting Started Installation, Program.cs setup, scope detection, first component
BlazorJSRuntime The central interop service - Get, Set, Call, CallAsync, New, and more
JSObject Base class for all typed JS wrappers - constructors, properties, methods, disposal
Events (ActionEvent / FuncEvent) Type-safe event subscription with += / -= operators and automatic ref counting
Callbacks Making .NET methods callable from JavaScript - Create, CreateOne, CallbackGroup
Union Types TypeScript-style discriminated unions - Match, Map, Reduce
Undefinable Distinguishing null from undefined in JavaScript interop
TypedArrays and Data Transfer Uint8Array, Float32Array, ArrayBuffer, and all typed array types
HeapView (Zero-Copy) Pin .NET arrays for zero-copy JavaScript access
Promises JavaScript Promise wrapper - create from Task, lambda, or TaskCompletionSource
Worker Scope Detection IsWindow, IsWorker, GlobalScope detection for multi-context apps
Custom JSObject Wrappers Step-by-step guide to wrapping any JavaScript library
Disposal and Lifetime Managing JSObject, Callback, and IJSInProcessObjectReference lifetimes
EnumString Bidirectional enum-to-string mapping for JavaScript string constants
DynamicJSObject DynamicObject wrapper for JavaScript-like dynamic property access
Blazor Web App Compatibility .NET 8+ hosting model, prerendering, and InteractiveWebAssembly render mode

Web API Reference

Complete Class Index (1,021 types) - Every type documented, organized by category.

Organized by category, mirroring the MDN Web API index and the source folder structure. Each category links to a folder containing every class, interface, enum, and options type for that API.

Category Types Key Classes
DOM 53 Window, Document, Element, Node, EventTarget, HTMLElement, HTMLCanvasElement, HTMLVideoElement
WebGPU 93 GPU, GPUDevice, GPUBuffer, GPURenderPipeline, GPUComputePipeline, GPUShaderModule, GPUQueue, GPUTexture
WebXR 64 XRSystem, XRSession, XRFrame, XRView, XRWebGLLayer, XRHand
WebAudio 45 AudioContext, AudioNode, GainNode, AnalyserNode, OscillatorNode
WebCodecs 35 VideoEncoder, VideoDecoder, VideoFrame, AudioEncoder
WebRTC 31 RTCPeerConnection, RTCDataChannel, RTCSessionDescription, RTCIceCandidate
Cryptography 25 Crypto, SubtleCrypto, CryptoKey, CryptoKeyPair
WebGL 19 WebGLRenderingContext, WebGL2RenderingContext, WebGLBuffer, WebGLProgram
USB 16 USB, USBDevice, USBConfiguration, USBInterface
TypedArrays 13 TypedArray, Uint8Array, Float32Array, Int32Array
Bluetooth 12 Bluetooth, BluetoothDevice, BluetoothRemoteGATTServer
Speech 12 SpeechRecognition, SpeechSynthesis, SpeechSynthesisUtterance
Serial 10 Serial, SerialPort
Presentation 8 Presentation, PresentationConnection
MediaSession 6 MediaSession, MediaMetadata
PaymentRequest 6 PaymentRequest, PaymentResponse
Reporting 7 ReportingObserver, Report
ShapeDetection 5 BarcodeDetector, FaceDetector
WebTransport 5 WebTransport
Performance 4 Performance, PerformanceEntry
IntersectionObserver 3 IntersectionObserver
EyeDropper 3 EyeDropper
Compression 2 CompressionStream, DecompressionStream
PictureInPicture 2 PictureInPictureWindow
IdleDetection 2 IdleDetector
General (Root) 530+ WebSocket, Worker, Blob, File, Request, Response, Navigator, URL, Promise, Array, Atomics, Cache, Notification, MediaStream, Gamepad, and many more...

SpawnDev.BlazorJS Core Types

These are library-specific types that provide the interop foundation.

Type Description
BlazorJSRuntime Central interop service - global JS access, scope detection, script loading
JSObject Base class for all 1,021 typed JavaScript wrappers
Callback Makes .NET methods callable from JavaScript - ref-counted, disposable
ActionEvent Event subscription with += / -= operators for Action delegates
FuncEvent Event subscription with += / -= operators for Func delegates
CallbackGroup Batch disposal container for multiple Callbacks
Union TypeScript-style discriminated union types (Union<T1,T2> through Union<T1...T8>)
Undefinable Distinguish JavaScript null from undefined
EnumString Bidirectional enum-to-JS-string mapping
DynamicJSObject DynamicObject wrapper for JavaScript-like dynamic access
EpochDateTime Unix epoch timestamp conversion
FluentUsing LINQ-style IDisposable extension methods

Additional Resources