Part of the fsharp-wasm platform: the browser. Builds on core. Used by ide, backend (the canvas client), newsletter. All projects · Roadmap · Tests · Benchmarks · Live demos
The official browser runtime for F# compiled to WebAssembly GC (.NET 10 / F# 10).
Write 100% F# browser applications with clean Browser.* APIs.
No JavaScript application code. Thin, modular JS glue only.
open Browser.Elmish.Core
open Browser.Html
let view model dispatch =
article {
class' "counter-demo"
h2 "Counter"
el "p" { class' "count-display"; string model.Count }
div {
button { onClick (fun () -> dispatch Decrement); "−" }
button { onClick (fun () -> dispatch Increment); "+" }
}
}
let start () = run "counter-root" { Init = init; Update = update; View = view }Live: every demo runs in the browser, compiled from F# by fsharp-wasm — see the showcase site. ♥ Sponsor the project.
Browser.*API — DOM, events, canvas, Web Components, fetch/WebSocket, storage, IndexedDB, workers, pub/sub, timers, WebGPU, CSS- HTML builder —
div { class' "card"; h1 "Title"; button { onClick …; "+" } }, plus active patterns for CSS - Elmish loop — model–update–view with commands, ~60 lines of F#
- Native Web Components defined entirely in F#
- No JavaScript application code — ~600 lines of glue in total, one small file per browser API
- Tested in a real browser — each of the twelve demos is driven by Playwright/Chromium (
npm run test:e2e)
F# source
↓ fsharp-wasm (F# → WasmGC)
.wasm module ← a JS import is an F# function marked `nativeOnly`
↓ instantiate with { builtins: ["js-string"] }
runtime/*.js ← glue: DOM, canvas, storage, workers, …
↓
DOM / Browser APIs
WebAssembly cannot reach the DOM, so a thin JS layer is unavoidable; this runtime makes it small, typed and invisible to the F# author. The compiler marshals what is not a plain number:
| F# at the JS boundary | in JavaScript |
|---|---|
string argument / result |
a native JS string (the engine's string builtins); a JS null arrives as "" |
string array result |
a JS array, read element-wise |
int / float / bool / Handle |
a number |
function argument, e.g. cb: string -> unit |
a JS function; calling it re-enters the module through the __cb export |
| callback parameters | int, bool, float, string, string array; up to four |
Everything asynchronous (IndexedDB, workers, timers, pub/sub) therefore takes a callback — in an Elmish program the callback dispatches a message. A module cannot block on a JS promise.
Browser support: WebAssembly GC and the JS String Builtins — Chrome / Edge 130+, Firefox 134+. (To my knowledge Safari has not shipped the string builtins yet.)
- .NET 10 SDK
- Node.js 22+
- fsharp-wasm compiler — our patched Fable CLI with WasmGC backend
Important: this is not the standard
fabledotnet global tool from NuGet. The upstream Fable 4.x only targets JavaScript. You need the compiler from this org.
Use a release of fsharp-wasm: its self-contained binary is downloaded once
into ~/.cache/fsharp-wasm and checked against the release's SHA256SUMS. Needs a .NET 10 SDK on the PATH (the compiler
cracks projects through it), nothing else.
export FSHARP_WASM_VERSION=v0.1.0-experimental # a release tag; or put the tag in a `.fsharp-wasm-version` file
# or an unpacked release:
export FSHARP_WASM_BIN=/path/to/fsharp-wasmWorking on the compiler itself? FSHARP_WASM_DIR=/path/to/fsharp-wasm builds and runs its CLI from a checkout (which needs
its patched F# compiler, see that repository). Nothing in this repository is a submodule of the compiler or the other way
round.
git clone https://github.com/fsharp-wasm/fsharp-wasm-runtime.git
cd fsharp-wasm-runtime
npm installnpm run build # every demo → dist/
node build/build.js --demo todo # one demonpx serve dist -l 8080 # open http://localhost:8080npm run test:e2e # drives every demo and the landing page in Chromium (Playwright)
node tests/e2e/demos.mjs counter # one demosite/ is what GitHub Pages serves: a landing page plus the prebuilt demos, so deploying needs no compiler.
After changing F# or glue code, refresh it:
npm run site # build all demos, copy them (wasm + pages + glue) into site/fsharp-wasm-runtime/
├── runtime/ # JS glue, one ES module per browser API (+ boot.js: imports, instantiate)
├── src/
│ ├── Browser/ # Browser.* API (one F# module per area)
│ ├── Html/ # HTML builder (Elements, Attrs, CE builder)
│ └── Elmish/ # Model–update–view loop
├── demos/ # 10 demo applications (F# project + page each)
├── tests/
│ ├── e2e/ # Chromium end-to-end tests (demos + landing page)
│ ├── Integration/ # Playwright spec (npx playwright test)
│ └── Unit/
├── build/ # build.js (demos → dist/), site.mjs (dist/ → site/)
├── site/ # the deployable showcase: landing page + prebuilt demos
├── docs/
└── index.html # demo gallery
| Module | Description |
|---|---|
Browser.Core |
Handle type, constants |
Browser.Dom |
Element creation, manipulation, queries |
Browser.Events |
Event listeners (click, input, etc.) |
Browser.Canvas |
Canvas 2D drawing API |
Browser.Components |
Native Web Components |
Browser.Net |
Fetch API + WebSocket |
Browser.PubSub |
Local event bus (pub/sub messaging) |
Browser.Storage |
localStorage / sessionStorage |
Browser.IndexedDb |
IndexedDB wrapper |
Browser.Workers |
Web Workers |
Browser.Timing |
setTimeout, setInterval, rAF |
Browser.Gpu |
WebGPU directly: device, WGSL shaders, buffers, render and compute pipelines, bind groups, readback |
Browser.Css |
CSS DSL with active patterns |
Browser.Quotations |
Meta-programming with quotations |
| Demo | Description |
|---|---|
| Counter | Classic Elmish MVU counter |
| Todo | Todo list with input, toggle, remove |
| Canvas Mandelbrot | Pure F# computation → Canvas, next to a JavaScript twin — same picture |
| Web Component | Native <fs-counter> custom element |
| Realtime Pub/Sub | A message bus wired from F# |
| IndexedDB CRUD | Persistent key-value storage |
| Worker Actor | Web Worker message passing |
| WasmOS | One F# program as Windows, macOS, Android or a Linux desktop: windows, a launcher, five apps (the F# project is in fsharp-wasm-embedded) |
| Charts | A line of ten million samples, a stream, a density map of five million points and 200 000 candles from the scene graph, with the benchmark of the pyramid against reading every sample (the F# library is FSharp.Graphics.Charts) |
| Actor Orchestra | An Erlang-style orchestra: supervised Web Workers, mailboxes and a pure orchestrator for a Monte Carlo estimate of π; kill or crash a worker mid-run (docs/actors.md) |
| WebGPU Basic | GPU availability check + canvas |
| WebGPU from F# | Browser.Gpu directly: a triangle drawn into a texture and read back as pixels, an animated one on a canvas, and two compute jobs read back as text and through linear memory (docs/webgpu-direct.md) |
| SCADA — four plants | A control room drawn from F#: an ore crushing circuit, a corrugated board line, a bottle washing and filling line and a sand sorting plant, with animated process pictures, limits on every tag and ISA-18.2 alarms from FSharp.Wasm.Telemetry (raise, acknowledge, return, clear); the colours are read from the page's brand tokens (cssVar); the module is built from fsharp-wasm-scada |
| PLC — Structured Text | A soft PLC for IEC 61131-3 Structured Text (the language of CODESYS), FSharp.Wasm.Plc of fsharp-wasm-core compiled to WasmGC with the page: an editor, scan cycles, TON/TOF/SR/R_TRIG/CTU/PID, a process image, writing and forcing of variables, online change that keeps the state, and a supervisor (FSharp.Wasm.Actors) that restarts a task that faults and gives up when it keeps faulting. It drives a sand sorting plant with a trend; the module is built from fsharp-wasm-scada |
| Canvas 2D from F# | The whole of Browser.Canvas: gradient, transforms, shadow, clip, even-odd fill, curves, dashes, text and a second canvas |
| Benchmark | Thirteen kernels, F# vs JavaScript, timed in a worker; chart, spreads, JSON export — results in docs/benchmarks.md |
| Benchmarks (results) | Speed, size and network load times, recorded and public: /benchmarks/, docs/benchmarks.md |
| Full Dashboard | All features combined |
Welcome. CONTRIBUTING is the organisation's guide and AGENTS.md says how the platform is worked on (the compiler comes first: a fault found here is fixed in the compiler, not worked around here).
- Run the tests:
npm run test:e2edrives every demo in Chromium (build the demos first:npm run build, which needs the compiler). - A good first contribution: Run the end-to-end suite in Firefox or WebKit (Playwright) and report what differs: only Chromium is covered today. Issues labelled
good first issueare the places to start. - A change goes to
developas a pull request, with a test that fails without it. Open an issue first for anything larger than a fix.
Apache License 2.0 — see NOTICE.