← Chrome 147 reference

v147 · origin trial · machine learning api

Web Neural Network API (WebNN)

A W3C API that lets web apps run neural network inference directly on a device's hardware — CPU, GPU, or dedicated NPU — through the browser. Frameworks like TensorFlow.js and ONNX Runtime Web use it under the hood; you can also use it directly to construct and execute computational graphs.

Origin trial The WebNN origin trial runs from Chrome 147 through 149. Register at developer.chrome.com/origintrials (search "WebNN") to get a token for production use. The API surface is stable within the current CR snapshot but still evolving — check the W3C spec before shipping. Enable locally: chrome://flags/#web-machine-learning-neural-network.

at a glance

Origin trialChrome 147 – 149 (re-enabled; previous trial ran in Chrome 122-125)
StatusOrigin trial
StandardsW3C Candidate Recommendation
SpecWeb Neural Network API — W3C CR
Explainerwebmachinelearning/webnn explainer
Sampleswebmachinelearning/webnn-samples
ChromeStatus5738583487938560 — Web Neural Network API

why it exists

Running ML models in the browser today requires either sending data to a server (latency, privacy) or using WebGL/WebGPU compute shaders (complex, not portable across frameworks). Native OS ML runtimes — DirectML on Windows, Core ML on macOS/iOS, NNAPI on Android — can run inference an order of magnitude faster than hand-written shader code, but the web has no standard way to reach them. WebNN is the bridge: it exposes a graph-based operator API that maps cleanly onto these native backends, letting frameworks compile an ONNX model once and run it optimally on whatever hardware the user has.

Source: W3C WebNN spec, webnn.io documentation, April 2026.

Standards-status divergence, both sides reported rather than resolved (fetched 2026-10-06): this page calls the specification a W3C Candidate Recommendation, while the linked document at w3.org/TR/webnn/ self-describes as a W3C Candidate Recommendation Draft, one step short of the label used here. The page also carries no declaration grammar of its own: it enumerates the API shape through inline code in a table, so the reference contract’s syntax coverage points at that table and says so plainly rather than dressing the table up as WebIDL.

shape of the API

Core interfaces

InterfaceDescription
navigator.mlEntry point. Available in Window, Worker, and ServiceWorker contexts.
navigator.ml.createContext(options?)Creates an MLContext. options.deviceType can be "cpu", "gpu", or "npu".
MLContextRepresents the hardware backend. Has a compute() method to synchronously dispatch graph execution.
MLGraphBuilderConstructed with an MLContext. Provides methods for every operator (conv2d, relu, matmul, softmax, …). Returns MLOperand nodes forming a DAG.
MLGraphCompiled, immutable graph returned by MLGraphBuilder.build(). Execution is via MLContext.compute(graph, inputs, outputs).
MLTensorHardware buffer for sharing data between graph executions and other APIs (WebGPU, WebGL) without round-tripping through JS.
Source: W3C WebNN Candidate Recommendation, webnn.io API reference, April 2026.

example

Running a simple 2-layer network

// 1. Pick the best available device
const context = await navigator.ml.createContext({ deviceType: 'gpu' });
const builder = new MLGraphBuilder(context);

// 2. Describe the graph symbolically (values are shapes, not data)
const input  = builder.input('x', { dataType: 'float32', shape: [1, 784] });
const w1     = builder.constant({ dataType: 'float32', shape: [784, 128] }, weight1Data);
const b1     = builder.constant({ dataType: 'float32', shape: [128] }, bias1Data);
const fc1    = builder.add(builder.matmul(input, w1), b1);
const relu1  = builder.relu(fc1);
const w2     = builder.constant({ dataType: 'float32', shape: [128, 10] }, weight2Data);
const b2     = builder.constant({ dataType: 'float32', shape: [10] }, bias2Data);
const output = builder.add(builder.matmul(relu1, w2), b2);

// 3. Compile
const graph = await builder.build({ output });

// 4. Run
const inputTensor  = new Float32Array(784);
const outputTensor = new Float32Array(10);
// ... fill inputTensor with pixel values ...
await context.compute(graph,
  { x: inputTensor },
  { output: outputTensor }
);
console.log('Class probabilities:', outputTensor);
Source: W3C WebNN explainer and webnn-samples GitHub, April 2026.

Tensor-backed execution using MLTensor hardware buffers (allocated with context.createTensor()):

// 1. Allocate reusable MLTensor hardware buffers
const inputTensor = await context.createTensor({
  dataType: 'float32',
  shape: [1, 784],
  writable: true
});
const outputTensor = await context.createTensor({
  dataType: 'float32',
  shape: [1, 10],
  readable: true
});

// 2. Write input data directly into the MLTensor buffer
context.writeTensor(inputTensor, pixelData);

// 3. Dispatch execution with MLTensor buffers
context.dispatch(graph, { x: inputTensor }, { output: outputTensor });

// 4. Read back inference results from the output MLTensor
const results = new Float32Array(await context.readTensor(outputTensor));
console.log('Class probabilities:', results);
Source: W3C WebNN §8.3.1.1 Executing an MLGraph using MLTensors, April 2026.

browser support

BrowserSupport
Chrome 147 – 149Origin trial (flag: #web-machine-learning-neural-network)
EdgeSupported (Chromium-based, same flag)
FirefoxNo position
SafariNo position
Source: webnn.io browser compatibility, April 2026.

see also