Description
Description
The web backend uses web_sys::window
to obtain a handle to the global Navigator
object. This does not work when called from a worker scope since there is no window
global variable nor a Window
interface.
Repro steps
Create a Worker
that executes a Rust program compiled to WebAssembly calling wgpu::Instance::new
. Unfortunately I don't have a minimal repro available at the moment.
Expected vs observed behavior
Observed behavior: the web backend tries to obtain a handle to the window
object and performs an instanceof
check against the Window
interface, which does not exist in the worker scope. This results in an error:
Uncaught (in promise) ReferenceError: Window is not defined
Expected behavior:
In a worker scope, a web_sys::WorkerGlobalScope
could be used instead to obtain the Navigator
handle, but this might be tricky in practice (rustwasm/wasm-bindgen#1046). Since the program will crash and not return None
when window
is not available, it is not enough to use Option::or
to fall back to, say, web_sys::global()
. Based on rustwasm/wasm-bindgen#1982 (comment), this is a problem with other web_sys
consumers too and might require some glue code like this.
Platform
wgpu
version: master