I run PixVibe, a set of image tools. Background removal runs an ONNX model directly in the user's browser: WebGPU when it works, WASM when it doesn't. Run that way, the photo is never uploaded. We never see it. (There's also a server-side option that does upload the photo. Users pick it themselves.)

That also means when it breaks, it breaks on a machine I can't see.

I found this out watching Microsoft Clarity recordings. I saw people upload a photo, wait, and leave. Some got an error. Some just watched the page reload itself. Our error logs had almost nothing. I didn't know if it was the model, the GPU, the phone, or our code.

So we built crash telemetry for the model runs. It records what was going on when a run failed, but it never uploads the image. The only bytes of the file it sends are the first 16, to detect the real format. Below is how it works, with simplified code, and what it found in the first month. The biggest bug it found was ours.

Why window.onerror wasn't enough

A normal error tracker catches exceptions and sends a stack trace. With a model running in the browser, most of what went wrong for us never showed up there:

  • The page gets killed. A phone runs out of memory while loading a 90 MB model, and the OS reloads the tab. Nothing throws. Your code never runs again.
  • The GPU fails quietly. WebGPU times out, the code falls back to the CPU, the job finishes several times slower. Nothing broke, so nothing got reported.
  • The error you show isn't the error that happened. We catch InvalidStateError: The source image could not be decoded and show "We couldn't read this image". If you report the friendly text, the real cause is gone. With four UI languages it's worse: one bug becomes four.
  • The error alone tells you almost nothing. The same failed to allocate on a 2 GB Android phone and on a 32 GB desktop are two different problems. You need to know what the device looked like at that moment.

What goes into one incident

We call one failure an incident. Our rule: collect more than you think you need. Every time I sat down to dig into a problem, I wanted some detail we hadn't captured, and you can't go back for it later. The limit is privacy, which I cover at the end.

Each incident has:

Group Fields
What failed incident kind, the original error name and message, first 10 lines of the stack
Where stage (decode, model download, model init, inference, encode), backend (webgpu or wasm), model
The file size, MIME type, extension, dimensions; for failed jobs and killed pages also the first 16 bytes and the real format detected from them. Never the file name, and nothing of the file beyond those 16 bytes
The moment JS heap used, tab visible or hidden, online or not, time since page load
The device browser and OS, cores, memory, GPU, WebGPU status, screen, network, cross-origin isolation
The history the last 50 breadcrumbs

We keep a separate device profile table too, but every incident carries its own copy of the device snapshot. One row has the whole picture, no joins.

An incident is also broader than an error. If the GPU fails and the CPU fallback succeeds, the user sees nothing wrong, and we still record it. That fallback is where the speed goes.

The reporter, simplified:

const API = '/api/incident' const MAX_BODY = 60 * 1024 const MAX_PER_PAGE = 40 const MAX_PER_KIND = 10 const sent = { total: 0, byKind: new Map<string, number>() } export function reportIncident(input: IncidentInput): void { try { // A real failure doesn't produce 40 reports. A loop does. if (sent.total >= MAX_PER_PAGE) return const n = (sent.byKind.get(input.kind) ?? 0) + 1 if (n > MAX_PER_KIND) return sent.byKind.set(input.kind, n) sent.total++ const err = describeError(input.error) const run = currentRun() // Capture the moment synchronously. After the first await // the state has already moved on. const body = { kind: input.kind, stage: input.stage ?? run?.stage ?? 'unknown', backend: input.backend ?? run?.backend ?? '', errorName: err.name, errorMessage: err.message, errorStack: err.stack, memUsedMB: usedHeapMB(), visible: document.visibilityState === 'visible', online: navigator.onLine, uptimeMs: Math.round(performance.now()), breadcrumbs: recentCrumbs(50), env: deviceSnapshot(), extra: { ...err.fields, ...input.extra }, fileBytes: input.file?.size ?? 0, fileType: input.file?.type ?? '', fileMagic: '', } if (input.file && input.sniff) { // failed jobs and killed pages only sniffHeader(input.file) // reads only the first 16 bytes .then((magic) => { body.fileMagic = magic }) .finally(() => send(body)) } else { send(body) } } catch { // Telemetry must never break the page. } } async function send(body: Record<string, unknown>) { try { let json = JSON.stringify(body) // Too big? Drop the least useful parts first. if (json.length > MAX_BODY) { body.errorStack = ''; json = JSON.stringify(body) } if (json.length > MAX_BODY) { body.breadcrumbs = (body.breadcrumbs as unknown[]).slice(-20); json = JSON.stringify(body) } if (json.length > MAX_BODY) { body.extra = {}; json = JSON.stringify(body) } await fetch(API, { method: 'POST', keepalive: true, // finishes even if the tab is closing headers: { 'Content-Type': 'application/json' }, body: json, }) } catch { /* silent */ } } 

keepalive matters more than it looks. Without it, the report you send right before the tab closes is the one you lose, and that's often the interesting one. The function returns nothing and never throws, so you can drop it into any catch without thinking.

Breadcrumbs

The error tells you what failed. Breadcrumbs tell you what the user was doing. Each one is tiny: upload, option changed, start, stage changed, fell back to CPU, done, failed, tab hidden, tab visible. A ring buffer keeps the last 50:

export type Crumb = { t: number; k: string; d?: Record<string, string | number | boolean> } const MAX = 50 const buf: Crumb[] = [] export function crumb(k: string, d?: Record<string, unknown>): void { const c: Crumb = { t: Math.round(performance.now()), k } if (d) c.d = shortData(d) // short scalars only: max 8 keys, strings cut at 64 chars buf.push(c) if (buf.length > MAX) buf.splice(0, buf.length - MAX) } export function recentCrumbs(n = MAX): Crumb[] { return buf.slice(-n).map((c) => ({ ...c, d: c.d && { ...c.d } })) } document.addEventListener('visibilitychange', () => crumb('visibility', { state: document.visibilityState })) window.addEventListener('pagehide', () => crumb('nav', { v: 'pagehide' })) 

The visibility crumb turned out to be the most useful line in the whole system. On phones, the last thing before a dead page is very often "tab hidden". The user switched to another app while the model was loading, and the OS took the memory back.

Stages

"Background removal failed" is useless. "Failed during model init on the WASM backend" tells you where to look.

The engine reports which stage it's in. It doesn't know or care which tool it's running for. The tool shell registers that once when a job starts:

export type RunStage = 'upload' | 'decode' | 'model_download' | 'model_init' | 'infer' | 'encode' | 'unknown' type RunState = { tool: string; seq: number; stage: RunStage; backend?: string; model?: string; mem?: number; crumbs: Crumb[] } let current: RunState | null = null const listeners = new Set<(s: RunState | null) => void>() export function runStart(tool: string, seq: number) { current = { tool, seq, stage: 'unknown', crumbs: [] } crumb('start', { tool, seq }) emit() } export function stage(s: RunStage, extra?: { backend?: string; model?: string }) { crumb('stage', { s, ...extra }) if (!current) return current.stage = s if (extra?.backend) current.backend = extra.backend if (extra?.model) current.model = extra.model current.mem = usedHeapMB() current.crumbs = recentCrumbs(15) emit() } export function runEnd() { current = null; emit() } export const currentRun = () => current export const onRunChange = (cb: (s: RunState | null) => void) => { listeners.add(cb); return () => listeners.delete(cb) } function emit() { for (const cb of listeners) { try { cb(current) } catch {} } } 

In the engine it's one line per step:

stage('model_download', { model: 'isnet' }) const session = await loadModel() stage('infer', { backend: session.backend }) const mask = await session.run(input) stage('encode') 

A flight recorder for pages the browser killed

No error tracker sees this one. The page doesn't throw. It's just gone, and a fresh copy loads.

What we do:

  1. When a job starts, write a small record to localStorage (tool, file name and dimensions, run number, options) and put the original image in IndexedDB, in the user's own browser. Nothing here is sent anywhere.
  2. On every stage change, rewrite the record: stage, backend, memory, last 15 breadcrumbs. A few hundred bytes.
  3. When the job ends, or the page leaves normally (pagehide), delete the record.
  4. When the tool page opens, look for records left by other tabs. If one is there and its tab doesn't answer, that tab died mid-job.
const PREFIX = 'run:' const TAB = crypto.randomUUID() const keyOf = (tool: string, tab = TAB) => `${PREFIX}${tool}:${tab}` const channel = new BroadcastChannel('run-guard') const active = new Set<string>() channel.onmessage = (e) => { if (e.data?.type === 'ping' && active.has(e.data.tool)) { channel.postMessage({ type: 'pong', tool: e.data.tool, tab: TAB }) } } // Leaving normally is not a crash. window.addEventListener('pagehide', () => { for (const tool of active) localStorage.removeItem(keyOf(tool)) }) onRunChange((s) => { if (!s || !active.has(s.tool)) return const prev = JSON.parse(localStorage.getItem(keyOf(s.tool)) || '{}') localStorage.setItem(keyOf(s.tool), JSON.stringify({ ...prev, ...s })) }) export function beginRun(tool: string, info: { seq: number }, file: File) { active.add(tool) localStorage.setItem(keyOf(tool), JSON.stringify({ ...info, ts: Date.now() })) saveImage(`crash:${tool}`, file) // IndexedDB; if this fails, fine runStart(tool, info.seq) } export function endRun(tool: string) { active.delete(tool) runEnd() localStorage.removeItem(keyOf(tool)) deleteImage(`crash:${tool}`) // don't leave the user's image on disk } export async function takeCrashedRun(tool: string) { const foreign = Object.keys(localStorage) .filter((k) => k.startsWith(`${PREFIX}${tool}:`) && k !== keyOf(tool)) if (!foreign.length) return null // Ask the other tabs if they're still working. const alive = new Set<string>() const onPong = (e: MessageEvent) => { if (e.data?.type === 'pong' && e.data.tool === tool) alive.add(keyOf(tool, e.data.tab)) } channel.addEventListener('message', onPong) channel.postMessage({ type: 'ping', tool }) await new Promise((r) => setTimeout(r, 400)) channel.removeEventListener('message', onPong) let hit = null for (const k of foreign) { if (alive.has(k)) continue const v = JSON.parse(localStorage.getItem(k) || 'null') if (v && (!hit || v.ts > hit.ts)) hit = v localStorage.removeItem(k) // read once, then delete } if (!hit) return null const file = await takeImage(`crash:${tool}`) // also deletes it return { ...hit, file } } 

On page load the tool calls takeCrashedRun(). If it gets something back, we send a page_killed incident with the stage, backend, model, memory and breadcrumbs from the record, and we put the user's image back in the workspace with a short explanation.

We don't rerun the job. On a phone that just ran out of memory, a rerun will most likely crash again, and now the user is stuck in a reload loop. Instead, the device gets a mark for seven days: the next upload doesn't start the local model automatically, it asks first (try again here, or use the server-side option). One successful local run clears the mark.

Two things bit us here. Without the BroadcastChannel ping, a second open tab looks exactly like a crashed one; 400 ms is plenty for a live tab to answer. And older browsers don't have BroadcastChannel at all, so there we only treat records older than two minutes as crashes. I'd rather miss a crash than invent one.

Signatu...