SpawnDev has two libraries that let C# call browser APIs: BlazorJS, tied to Blazor's interop, and SpawnJS, built on JSImport/JSExport. The author recommends SpawnJS for new projects and shows that a migration stays a four-step change.
Key points
- SpawnJS routes calls through .NET's JSImport and JSExport instead of Blazor's JSON-based interop.
- It runs outside Blazor: plain .NET WebAssembly, Web Workers, browser extensions and Node console apps.
- Migration is four mechanical steps: packages, Program.cs startup calls, namespaces and the injected runtime type.
- Custom wrappers move from JSObject to SpawnJSObject and from IJSInProcessObjectReference to SpawnJSObjectReference.
- JS.Call now names every argument type, as in JS.Call<string, string>("btoa", "Hello").
- SpawnJS ships trimming descriptors; the sample app measured 19.5 MB against 22.5 MB compressed.
Why it matters
The interesting part is the transport change, not the rename: dropping the JSON hop for a JSImport/JSExport path and gaining C# code that can also run in a Web Worker, a browser extension or a Node-hosted console app. Teams publishing Blazor WebAssembly will notice first, on download size and trimming. Before moving, check that every SpawnDev companion package you use has a SpawnJS twin in a matching version, and repeat the size measurement on your own publish output — the article's numbers come from one sample. Apps that already run fine have no deadline.
Real-world use
- A Blazor WebAssembly app that needs smaller published downloads through trimming.
- A .NET WebAssembly console app under Node.js running the same GPU test suite as the browser.
- A Web Worker or browser extension that must reach browser APIs without a Blazor host.
- A recipe page that keeps the screen awake and copies text to the clipboard.
This summary was generated by the agent from the original post on DEV Community: #blazor. The full text and all rights belong to its author and publisher. Go to original