From 1f5756fd7c6a99aaae23f7b0a22b869d41b5844e Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 21 Aug 2026 06:39:11 +0000 Subject: [PATCH 1/2] Make a failed WebGPU start-up visible on the page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a phone a demo that cannot reach a GPU showed nothing at all. Six of the eight examples called init() with no catch, so a missing navigator.gpu or a null adapter threw out of the module script into a console the reader does not have — a loaded page, a blank canvas, and no way to tell that from the JavaScript never having run. - diag.js: a classic, non-module script loaded first by every demo page. It traps window 'error' and 'unhandledrejection' and puts the failure on the screen with an environment report (user agent, secure context, adapter, limits). Being classic and loaded ahead of the modules, it also catches a module that fails to load or parse. - libselect.js: gpuAdvice() names what a failure means on the device in front of the reader, reportFailure() raises the banner, and boot() is the one call the examples now make — picker, build import, init(), failure reported. - Examples 1-5 and 8 moved to boot(); 6 and 7 keep their own error strip but fill it from the shared reporter. The tutorial reports an adapter failure once at page level rather than only inside whichever box asked first. - docs/webgpu-check.html: a library-free page that walks navigator.gpu → adapter → device → one compiled and drawn triangle and says where the chain broke, with a copyable report. Linked from the banner, the index and the tutorial's unsupported notice. - README: the Android specifics — Chrome 121+ on Android 12+, and no WebGPU at all in Samsung Internet, Firefox for Android or in-app browsers. No change to src/ or dist/. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01UEu5U9tL6svBahBmuxjrC5 --- README.md | 18 ++- diag.js | 180 +++++++++++++++++++++++ docs/tutorial.html | 16 ++- docs/webgpu-check.html | 240 +++++++++++++++++++++++++++++++ examples/1_hello.html | 12 +- examples/2_compute_readback.html | 11 +- examples/3_life.html | 10 +- examples/4_indirect.html | 11 +- examples/5_texture.html | 11 +- examples/6_evolution.html | 13 +- examples/7_particles.html | 13 +- examples/8_heightmap.html | 10 +- index.html | 10 +- libselect.js | 48 +++++++ 14 files changed, 566 insertions(+), 37 deletions(-) create mode 100644 diag.js create mode 100644 docs/webgpu-check.html diff --git a/README.md b/README.md index 98519f2..6612018 100644 --- a/README.md +++ b/README.md @@ -460,11 +460,12 @@ no TypeScript build needed, and plain-JS users get it too through their editor. src/ tinywebgpu.js — the library — and tinywebgpu.d.ts dist/ the built artifacts, committed so the demo pages can load them tools/ build-min.mjs, its two configs, and find-repeats.mjs -docs/ the tutorial, API.md, CHANGELOG.md +docs/ the tutorial, webgpu-check.html, API.md, CHANGELOG.md examples/ the eight demo pages test/ the test suite index.html the demo index — the site's landing page libselect.js the ?lib=full|min|tiny picker the pages share +diag.js puts an uncaught page error on the screen — see "Browser support" below ``` To vendor the library, take `src/tinywebgpu.js` (or a file from `dist/`) and drop it next to your @@ -476,6 +477,21 @@ Pages, which is why `index.html` and `.nojekyll` live there. WebGPU requires a current browser (Chrome/Edge 113+, Firefox 141+ on Windows, Safari 26+) and a secure context (https or localhost). No WebGL fallback — this is a WebGPU tool. +On **Android**, WebGPU means Chrome 121+ on Android 12 or newer. Samsung Internet, Firefox for +Android, and the in-app browsers that chat and mail apps open links in have no WebGPU at all, so +a demo opened from a message will not run — open it in Chrome. Where Chrome has WebGPU but the +driver is blocklisted, `requestAdapter()` returns null; `chrome://flags/#enable-unsafe-webgpu` +usually gets past that. + +Because a phone has no console, the demo pages do not rely on one. Every page loads `diag.js` +first — a plain, non-module script that turns an uncaught error into a banner on the page: +a missing `navigator.gpu`, a null adapter, a module that failed to load or parse. The banner +carries an environment report (user agent, secure context, adapter, limits) and links to +**[docs/webgpu-check.html](https://lampmaker.github.io/tinywebgpu/docs/webgpu-check.html)**, +a library-free page that compiles and draws one triangle and reports exactly where the chain +broke. That page is the right thing to open — and the right report to paste — when a demo shows +nothing on a device. + ## License MIT. diff --git a/diag.js b/diag.js new file mode 100644 index 0000000..c1f4b59 --- /dev/null +++ b/diag.js @@ -0,0 +1,180 @@ +// Failure reporting for the demo pages. A classic script, deliberately ES5, deliberately not a +// module: it is loaded from before anything else, so it is already listening when the +// module scripts are parsed and run. +// +// Why it exists: a WebGPU demo that cannot start has nowhere to say so. An uncaught throw in a +// ` + + + +
+

WebGPU check

+ +
Checking…
+ + +

A shader should paint this box. If it stays empty, nothing below ran.

+ +

Environment

+
+ + + + + +
+ + + + + + diff --git a/examples/1_hello.html b/examples/1_hello.html index 9c6c933..fc588d0 100644 --- a/examples/1_hello.html +++ b/examples/1_hello.html @@ -7,6 +7,10 @@ TinyWebGPU — hello shader + +