aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit f97e81083641b505095b06bfcb943b884f1c3c28
parent e15b3eb5874aaab313a6bfe0f7fd9fade0dd096f
Author: anon <anon@example.com>
Date:   Tue, 20 Oct 2026 16:51:14 +0000

Check worker graphics support before loading the browser client

Diffstat:
Msrc/browser/index.html | 20++++++++++++++++++++
Msrc/tests/browser_loading.mjs | 29++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/src/browser/index.html b/src/browser/index.html @@ -288,6 +288,26 @@ show(); async function startGame() { if (!crossOriginIsolated) { status.textContent = 'Shared memory is unavailable'; return; } if (!canvas.transferControlToOffscreen) { status.textContent = 'This game requires OffscreenCanvas, which this browser does not support'; return; } + + // Some browsers expose OffscreenCanvas without supporting WebGL in workers. + const probeURL = URL.createObjectURL(new Blob([ + "postMessage(!!new OffscreenCanvas(1, 1).getContext('webgl2', {alpha: false, antialias: false}));" + ], {type: 'text/javascript'})); + const probe = new Worker(probeURL); + let graphicsReady; + try { + graphicsReady = await new Promise((resolve, reject) => { + probe.onmessage = event => resolve(event.data); + probe.onerror = event => reject(new Error(event.message)); + }); + } finally { + probe.terminate(); + URL.revokeObjectURL(probeURL); + } + if (!graphicsReady) { + status.textContent = 'This browser could not initialize WebGL 2 in a worker. Check graphics settings or try another browser.'; + return; + } Module.audioContext = new AudioContext(); // Load immediately; browsers unlock audio on the first game interaction. for (const type of ['pointerdown', 'keydown']) { diff --git a/src/tests/browser_loading.mjs b/src/tests/browser_loading.mjs @@ -64,7 +64,34 @@ async function reportsMissingOffscreenCanvas() { assert.deepEqual(test.progress, ['This game requires OffscreenCanvas, which this browser does not support']); } +async function reportsUnavailableWorkerWebGLBeforeDownloading() { + const test = fixture(); + test.context.document.querySelector('#canvas').transferControlToOffscreen = () => {}; + let terminated = false, revoked = null; + test.context.Blob = Blob; + test.context.URL = { + createObjectURL() { return 'blob:graphics-probe'; }, + revokeObjectURL(url) { revoked = url; } + }; + test.context.Worker = class { + constructor(url) { + assert.equal(url, 'blob:graphics-probe'); + queueMicrotask(() => this.onmessage({data: false})); + } + terminate() { terminated = true; } + }; + + await test.context.startGame(); + + assert.deepEqual(test.progress, [ + 'This browser could not initialize WebGL 2 in a worker. Check graphics settings or try another browser.' + ]); + assert.equal(terminated, true); + assert.equal(revoked, 'blob:graphics-probe'); +} + await streamsDecodedClientAndTracksProgress(); await rejectsFailedClientDownload(); await reportsMissingOffscreenCanvas(); -console.log('PASS: loading progress, streaming compilation, first frame, download failure and missing browser features'); +await reportsUnavailableWorkerWebGLBeforeDownloading(); +console.log('PASS: loading progress, streaming compilation, first frame, download failure and missing browser graphics');