v147 · JavaScript · Machine Learning · Origin Trial

Compatibility Lab

Probes navigator.ml, MLContext, MLGraphBuilder, and device-type availability. Runs a live navigator.ml.createContext() call and compiles a minimal add graph, reporting which backend was selected. Provides the WASM + WebGPU fallback detection chain for non-WebNN environments.

Origin trial. WebNN requires the MachineLearningNeuralNetwork origin trial or chrome://flags/#enable-experimental-web-platform-features. The probe below will report UNSUPPORTED without it.

API probes

Live context + graph test

navigator.ml.createContext() → MLGraphBuilder → compile → run
Click "Run WebNN test" to probe the API…

Fallback tier chain

Runtime detection waterfall
Tier 1
WebNN (navigator.ml)Hardware-accelerated — CPU/GPU/NPU via native OS ML frameworks. Best performance.
Tier 2
WebGPU compute shadersGPU via navigator.gpu. Near-native for matrix ops. Widely available in Chrome 113+.
Tier 3
WASM SIMDCPU via WebAssembly + SIMD instructions. 4-8× faster than scalar WASM. Safari/Firefox compatible.
Tier 4
Plain WASM / JSScalar fallback. All browsers. Slowest — use only for very small models.
Detecting available tiers…

Fallback pattern

/* WebNN + fallback detection chain */ async function getBestMLBackend() { // Tier 1: WebNN if ('ml' in navigator) { try { const ctx = await navigator.ml.createContext({ deviceType: 'gpu' }); if (ctx) return { tier: 'webnn', ctx }; } catch { /* fall through */ } try { const ctx = await navigator.ml.createContext({ deviceType: 'cpu' }); if (ctx) return { tier: 'webnn-cpu', ctx }; } catch { /* fall through */ } } // Tier 2: WebGPU if ('gpu' in navigator) { try { const adapter = await navigator.gpu.requestAdapter(); if (adapter) return { tier: 'webgpu', adapter }; } catch { /* fall through */ } } // Tier 3: WASM SIMD if (typeof WebAssembly !== 'undefined') { // Detect SIMD via compile const simdBytes = new Uint8Array([ 0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,253,15,253,98,11 ]); const simd = await WebAssembly.validate(simdBytes).catch(() => false); return { tier: simd ? 'wasm-simd' : 'wasm', wasm: true }; } // Tier 4: JS only return { tier: 'js-only' }; } /* Usage */ getBestMLBackend().then(({ tier }) => { console.log('ML backend:', tier); // Load appropriate ONNX Runtime Web backend: // 'webnn' → { executionProviders: ['webnn'] } // 'webgpu' → { executionProviders: ['webgpu'] } // 'wasm-simd' → { executionProviders: ['wasm'] } // 'js-only' → { executionProviders: ['cpu'] } });

see also

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗