From b34562333b7bb1108903e8e653bc817e1034604f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Sat, 17 Oct 2026 02:05:39 -0400 Subject: [PATCH] Show the crash overlay when the Go loader fails to load Co-Authored-By: Claude Opus 5.5 (1M context) --- web/main.js | 11 ++++++----- web/tests/smoke.spec.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/web/main.js b/web/main.js index 9572fb7..bfd8468 100644 --- a/web/main.js +++ b/web/main.js @@ -1,10 +1,5 @@ // Streams the wasm, runs Go, shows crashes. const stderr = [] -const write = globalThis.fs.writeSync.bind(globalThis.fs) -globalThis.fs.writeSync = (fd, buf) => { - if (fd === 2) stderr.push(new TextDecoder().decode(buf)) - return write(fd, buf) -} function crash (msg) { const why = [msg, stderr.join('').slice(-4000)].filter(Boolean).join('\n\n') @@ -15,6 +10,12 @@ function crash (msg) { document.getElementById('reload').onclick = () => location.reload() async function load () { + if (!globalThis.Go || !globalThis.fs) throw new Error('wasm_exec.js did not load.') + const write = globalThis.fs.writeSync.bind(globalThis.fs) + globalThis.fs.writeSync = (fd, buf) => { + if (fd === 2) stderr.push(new TextDecoder().decode(buf)) + return write(fd, buf) + } const t0 = performance.now() const res = await fetch('__WASM__') if (!res.ok) throw new Error(`${res.url}: HTTP ${res.status}`) diff --git a/web/tests/smoke.spec.js b/web/tests/smoke.spec.js index 5b87dc5..8428596 100644 --- a/web/tests/smoke.spec.js +++ b/web/tests/smoke.spec.js @@ -11,10 +11,20 @@ test.beforeEach(async ({ page }) => { page.on('pageerror', e => seen.push(e.message)) }) +// Every page ends free of errors, unless it expects them. test.afterEach(async ({ page }) => { + if (test.info().annotations.some(a => a.type === 'expects errors')) return expect(pageErrors.get(page)).toEqual([]) }) +test('a missing loader shows the crash overlay', async ({ page }) => { + test.info().annotations.push({ type: 'expects errors' }) + await page.route('**/a/wasm_exec.*.js', route => route.abort()) + await page.goto('/') + await expect(page.locator('#over')).toBeVisible() + await expect(page.locator('#why')).toContainText('wasm_exec.js did not load.') +}) + async function open (page, hash = '') { await page.goto('/' + hash) await page.waitForFunction(() => window.__crychicBoot)