From b82a113cc65f1d0776b09e56e229899572b6282c Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Tue, 7 Apr 2026 15:47:51 +0800 Subject: [PATCH 1/4] Fix WASM on old Chrome v95 --- .mise.toml | 7 ++++++- README.md | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.mise.toml b/.mise.toml index bb64685..5086f36 100644 --- a/.mise.toml +++ b/.mise.toml @@ -13,6 +13,7 @@ pipx = "latest" protoc = "latest" rust = "latest" typos = "latest" +"github:wasm-bindgen/wasm-bindgen" = "0.2.114" [tasks] dprint-check = "dprint check" @@ -68,7 +69,11 @@ run = "cargo run" [tasks.build-ws-wasm-agent] description = "Build the WebSocket WASM client" dir = "services/ws-wasm-agent" -run = "wasm-pack build --target web" +run = "wasm-pack build . --target web -- -Z build-std=std,panic_abort" + +[tasks.build-ws-wasm-agent.env] +RUSTUP_TOOLCHAIN = "nightly" +RUSTFLAGS = "-C target-cpu=mvp -C target-feature=+mutable-globals,+sign-ext,+nontrapping-fptoint" [tasks.test-ws-wasm-agent-firefox] description = "Run headless Firefox tests for the WebSocket WASM client" diff --git a/README.md b/README.md index fd164c9..57531f3 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ mise run build-ws-wasm-agent mise run ws-server ``` +The WASM build disables WebAssembly reference types so it can still load on older browsers such as Chrome 95. + Find the IP address of your laptop in the local network, which will normally be something like 192.168.1.x. From 1e42367e88c213ed9ebfd2929c0e318e5791fc31 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Tue, 7 Apr 2026 16:02:47 +0800 Subject: [PATCH 2/4] app.js: Support old Chrome 95 --- services/ws-server/static/app.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/ws-server/static/app.js b/services/ws-server/static/app.js index 8a4f0b3..7613962 100644 --- a/services/ws-server/static/app.js +++ b/services/ws-server/static/app.js @@ -131,6 +131,29 @@ const formatNumber = (value, digits = 3) => ( Number.isFinite(value) ? value.toFixed(digits) : "n/a" ); +const configureOnnxRuntimeWasm = () => { + if (!window.ort?.env?.wasm) { + throw new Error("onnxruntime-web environment is unavailable."); + } + + const ortVersion = window.ort.env.versions?.web; + if (typeof ortVersion !== "string" || ortVersion.length === 0) { + throw new Error("onnxruntime-web version is unavailable."); + } + + const distBaseUrl = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ortVersion}/dist`; + window.ort.env.wasm.proxy = false; + window.ort.env.wasm.numThreads = 1; + window.ort.env.wasm.wasmPaths = { + mjs: `${distBaseUrl}/ort-wasm-simd-threaded.mjs`, + wasm: `${distBaseUrl}/ort-wasm-simd-threaded.wasm`, + }; + + append( + `onnxruntime-web configured: version=${ortVersion} wasm=${window.ort.env.wasm.wasmPaths.wasm} threads=1` + ); +}; + const degreesToRadians = (value) => ( Number.isFinite(value) ? (value * Math.PI) / 180 : 0 ); @@ -797,6 +820,8 @@ try { throw new Error("onnxruntime-web did not load."); } + configureOnnxRuntimeWasm(); + harButton.disabled = true; harButton.textContent = "Loading HAR..."; updateHarStatus(["loading model..."]); From 8a1a2a90068dc412f16dc54fc0580e6bae5d1a95 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Tue, 7 Apr 2026 16:10:38 +0800 Subject: [PATCH 3/4] More dynamic old Chrome support --- services/ws-server/static/app.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/ws-server/static/app.js b/services/ws-server/static/app.js index 7613962..f606432 100644 --- a/services/ws-server/static/app.js +++ b/services/ws-server/static/app.js @@ -142,15 +142,18 @@ const configureOnnxRuntimeWasm = () => { } const distBaseUrl = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ortVersion}/dist`; - window.ort.env.wasm.proxy = false; - window.ort.env.wasm.numThreads = 1; + const supportsWasmThreads = + window.crossOriginIsolated === true && + typeof SharedArrayBuffer !== "undefined"; + + window.ort.env.wasm.numThreads = supportsWasmThreads ? 0 : 1; window.ort.env.wasm.wasmPaths = { mjs: `${distBaseUrl}/ort-wasm-simd-threaded.mjs`, wasm: `${distBaseUrl}/ort-wasm-simd-threaded.wasm`, }; append( - `onnxruntime-web configured: version=${ortVersion} wasm=${window.ort.env.wasm.wasmPaths.wasm} threads=1` + `onnxruntime-web configured: version=${ortVersion} wasm=${window.ort.env.wasm.wasmPaths.wasm} threads=${window.ort.env.wasm.numThreads === 1 ? "disabled" : "auto"}` ); }; From ba489becbd486dce6dd93daa2ca6c0e9dd38097c Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Wed, 8 Apr 2026 12:38:20 +0800 Subject: [PATCH 4/4] fmt --- .mise.toml | 4 ++-- services/ws-server/static/app.js | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.mise.toml b/.mise.toml index 5086f36..a3b91c7 100644 --- a/.mise.toml +++ b/.mise.toml @@ -6,6 +6,7 @@ cmake = "latest" dprint = "latest" editorconfig-checker = "latest" "github:block/goose" = "latest" +"github:wasm-bindgen/wasm-bindgen" = "0.2.114" ollama = "latest" osv-scanner = "latest" pipx = "latest" @@ -13,7 +14,6 @@ pipx = "latest" protoc = "latest" rust = "latest" typos = "latest" -"github:wasm-bindgen/wasm-bindgen" = "0.2.114" [tasks] dprint-check = "dprint check" @@ -72,8 +72,8 @@ dir = "services/ws-wasm-agent" run = "wasm-pack build . --target web -- -Z build-std=std,panic_abort" [tasks.build-ws-wasm-agent.env] -RUSTUP_TOOLCHAIN = "nightly" RUSTFLAGS = "-C target-cpu=mvp -C target-feature=+mutable-globals,+sign-ext,+nontrapping-fptoint" +RUSTUP_TOOLCHAIN = "nightly" [tasks.test-ws-wasm-agent-firefox] description = "Run headless Firefox tests for the WebSocket WASM client" diff --git a/services/ws-server/static/app.js b/services/ws-server/static/app.js index f606432..3caa152 100644 --- a/services/ws-server/static/app.js +++ b/services/ws-server/static/app.js @@ -142,9 +142,8 @@ const configureOnnxRuntimeWasm = () => { } const distBaseUrl = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${ortVersion}/dist`; - const supportsWasmThreads = - window.crossOriginIsolated === true && - typeof SharedArrayBuffer !== "undefined"; + const supportsWasmThreads = window.crossOriginIsolated === true + && typeof SharedArrayBuffer !== "undefined"; window.ort.env.wasm.numThreads = supportsWasmThreads ? 0 : 1; window.ort.env.wasm.wasmPaths = { @@ -153,7 +152,9 @@ const configureOnnxRuntimeWasm = () => { }; append( - `onnxruntime-web configured: version=${ortVersion} wasm=${window.ort.env.wasm.wasmPaths.wasm} threads=${window.ort.env.wasm.numThreads === 1 ? "disabled" : "auto"}` + `onnxruntime-web configured: version=${ortVersion} wasm=${window.ort.env.wasm.wasmPaths.wasm} threads=${ + window.ort.env.wasm.numThreads === 1 ? "disabled" : "auto" + }`, ); };