Return helpful error when WebGPU is disabled (#9319)

This commit is contained in:
Emil Ernerfeldt authored and GitHub committed 2026-04-07 18:18:35 +02:00
1 parent 74827c4181
commit fe725d6df0
1 file changed
+13 -5
+13 -5
View File
@@ -1120,11 +1120,19 @@ impl ContextWebGpu {
}
};
// Not returning this error because it is a type error that shouldn't happen unless
// the browser, JS builtin objects, or wasm bindings are misbehaving somehow.
let context: webgpu_sys::GpuCanvasContext = context
.dyn_into()
.expect("canvas context is not a GPUCanvasContext");
// An error here indicated that WebGPU is disabled in the browser.
let context: webgpu_sys::GpuCanvasContext =
context
.dyn_into()
.map_err(|actual| crate::CreateSurfaceError {
inner: crate::CreateSurfaceErrorKind::Web(format!(
"`canvas.getContext()` returned a value that did not coerce to \
`GPUCanvasContext`. \
This is likely because WebGPU is disabled in this browser. \
Expected: `GPUCanvasContext`, Actual: `{}`",
actual.to_string()
)),
})?;
Ok(WebSurface {
gpu: self.gpu.clone(),