diff --git a/util/gpu/web/hb-gpu-web-webgpu.cc b/util/gpu/web/hb-gpu-web-webgpu.cc
index 9c2849b56..6675a7ce6 100644
--- a/util/gpu/web/hb-gpu-web-webgpu.cc
+++ b/util/gpu/web/hb-gpu-web-webgpu.cc
@@ -796,8 +796,10 @@ on_adapter (WGPURequestAdapterStatus status,
{
fprintf (stderr, "Failed to get WebGPU adapter\n");
EM_ASM ({
+ window._webgpuError = true;
var el = document.getElementById ('loading');
if (el) {
+ el.style.display = '';
var html = 'WebGPU adapter not available.
' +
'Browser support status';
@@ -1035,6 +1037,26 @@ main ()
css_w = (int) css_w_d;
css_h = (int) css_h_d;
+ /* Check WebGPU availability before trying the C API. */
+ bool has_webgpu = EM_ASM_INT ({ return !!navigator.gpu; });
+ if (!has_webgpu)
+ {
+ fprintf (stderr, "WebGPU not available in this browser\n");
+ EM_ASM ({
+ window._webgpuError = true;
+ var el = document.getElementById ('loading');
+ if (el) {
+ el.style.display = '';
+ el.innerHTML = 'WebGPU is not available in this browser.
' +
+ 'Try the WebGL version';
+ el.style.font = '18px sans-serif';
+ el.style.color = '#666';
+ el.style.textAlign = 'center';
+ }
+ });
+ return 0;
+ }
+
WGPUInstanceDescriptor instDesc = {};
WGPUInstance instance = wgpuCreateInstance (&instDesc);