v147 · web api · origin trial
WebNN
The Web Neural Network API lets web apps and frameworks run neural network inference against the device's hardware accelerators — CPU, GPU, or a dedicated NPU — without tying the code to any platform-specific backend. navigator.ml is the entry point; the rest is a graph builder API that compiles to whatever hardware is available.
MLTensor buffer-sharing API are still stabilising. Check the spec before shipping anything.
To test locally without the origin trial: enable chrome://flags/#web-machine-learning-neural-network (the preference BCD records since Chrome 112), and feature-detect with "ml" in navigator before any navigator.ml.createContext() call.
at a glance
| Shipping target | Chrome 147 (origin trial; exact GA milestone TBD) |
|---|---|
| Status | Origin trial / Proposed |
| Flag | chrome://flags/#web-machine-learning-neural-network |
| Standards position | Firefox: Positive · Safari: No signal (Apple active in WG) |
| Spec | Web Neural Network API (W3C WebML Working Group, Candidate Recommendation) |
| Explainer | webmachinelearning / webnn / explainer.md |
| Samples | webnn-samples · Microsoft developer preview |
| ChromeStatus | 5176273954144256 — WebNN |
Snapshot divergence, both sides reported rather than resolved (fetched 2026-10-06): this page describes an earlier
snapshot of the specification it cites, and the current draft has moved on. The page spells its operator runs
matMul, which appears zero times in the fetched draft (its IDL spells it matmul,
192 occurrences); the page’s descriptor examples use dimensions where the draft uses
shape; and the page names 13 operators plus “~70 more” where the draft defines 91. The
page’s compute() call is likewise the historical name — the draft’s IDL defines
dispatch (50 occurrences) and mentions compute( only twice. On status, ChromeStatus
feature 5176273954144256 reads “Proposed” with maturity “Specification currently under
development in a Working Group”, so neither this page’s Candidate Recommendation label nor its Chrome 147
origin-trial framing is carried by the record.
why it exists
Neural network inference on the web has historically meant one of two things: a heavyweight WASM runtime that can't touch the GPU, or WebGL/WebGPU compute shaders that require hand-rolling matrix math and shader strings. Neither path can reach a device's Neural Processing Unit. WebNN is a hardware-agnostic graph API — the browser maps it onto Windows DirectML, macOS ML Compute, Android NNAPI, or whatever native stack is present. The Chromium implementation is a three-way collaboration between Google, Intel, and Microsoft; Edge ships WebNN at the same time as Chrome from the same code.
Source: chromestatus motivation and the WebNN explainer §1 ("Background").shape of the API
Four core interfaces; the workflow is always: create a context → build a graph → compile → compute.
navigator.ml → ML
navigator.ml.createContext(options?) | Returns Promise<MLContext>. Options can specify a device preference ("cpu", "gpu", "npu") and a power preference ("high-performance", "low-power", "default"). |
|---|
MLContext
compute(graph, inputs, outputs) | Runs a compiled MLGraph. inputs and outputs are plain objects keyed by operand name; values are ArrayBufferView. Returns Promise<MLComputeResult>. |
|---|---|
createTensor(descriptor, writable?, readable?) | Allocates a device-side MLTensor for zero-copy buffer sharing between the graph and WebGPU (if available). |
dispatch(graph, inputs, outputs) | Fire-and-forget version of compute for MLTensor-backed buffers; does not transfer data back to JS until readTensor() is called. |
MLGraphBuilder
new MLGraphBuilder(context) | Constructor. Binds the builder to a context. |
|---|---|
input(name, descriptor) | Declares an input operand. Descriptor: { dataType, dimensions }. |
constant(descriptor, data) | Embeds a constant (e.g. model weights) into the graph at build time. |
| Operators | add, mul, matMul, conv2d, relu, sigmoid, softmax, transpose, reshape, gather, layerNormalization, gru, lstm, and ~70 more. Each returns an MLOperand. |
build(outputs) | Compiles the graph. outputs is an object mapping output names to MLOperand. Returns Promise<MLGraph>. |
MLGraph
Opaque compiled representation. Pass to context.compute() or context.dispatch(). Immutable after construction. |
example: add two matrices
const context = await navigator.ml.createContext({ deviceType: 'gpu' });
const builder = new MLGraphBuilder(context);
// Declare two 2×2 float32 inputs
const A = builder.input('A', { dataType: 'float32', dimensions: [2, 2] });
const B = builder.input('B', { dataType: 'float32', dimensions: [2, 2] });
// Build a computation: C = A + B
const C = builder.add(A, B);
const graph = await builder.build({ C });
// Run inference
const inputs = {
A: new Float32Array([1, 2, 3, 4]),
B: new Float32Array([5, 6, 7, 8]),
};
const outputs = { C: new Float32Array(4) };
await context.compute(graph, inputs, outputs);
// outputs.C → [6, 8, 10, 12]
example: softmax classifier (weights as constants)
const context = await navigator.ml.createContext();
const builder = new MLGraphBuilder(context);
// Embed weights and bias as graph constants
const W = builder.constant(
{ dataType: 'float32', dimensions: [4, 128] },
Float32Array.from(modelWeights) // pre-loaded Uint8Array / Float32Array
);
const b = builder.constant(
{ dataType: 'float32', dimensions: [4] },
Float32Array.from(modelBias)
);
// Single input: a 128-d feature vector
const x = builder.input('x', { dataType: 'float32', dimensions: [128] });
// Linear layer + softmax
const logits = builder.add(builder.matMul(x, builder.transpose(W)), b);
const probs = builder.softmax(logits, 0);
const graph = await builder.build({ probs });
// Reuse the graph for every prediction — graph compilation is the slow step
async function predict(featureVector) {
const out = { probs: new Float32Array(4) };
await context.compute(graph, { x: featureVector }, out);
return out.probs;
}
navigator.ml is unavailable; running inference needs the flag or origin trial above — no model is auto-downloaded.Source: chrome-platform-showcasebrowser support
| Chrome | Origin trial in 147 (Google + Intel + Microsoft collaboration); BCD api/ML.json records the ML interface behind the #web-machine-learning-neural-network preference since 112 (fetched 2026-11-01) |
|---|---|
| Edge | Launches alongside Chrome (same Chromium code; BCD mirror) |
| Firefox | Positive — Mozilla standards position #1215; not shipped (BCD false) |
| Safari | No signal (Apple active in W3C WebML Working Group); not shipped (BCD false) |
The webstatus.dev webnn web-feature is Baseline limited with no shipped implementations recorded (queried 2026-11-01) — consistent with the origin-trial/flag state above.
see also
- W3C WebNN Candidate Recommendation
- webnn.io — community documentation and API reference
- webnn-samples — official sample collection
- Microsoft WebNN developer preview
- WebNN explainer
- Mozilla standards-positions — WebNN (#1215)
- chromestatus — WebNN (5176273954144256)
- chrome-platform-showcase: WebNN demos (live — embedded above)