Check if wasm thread is main thread or webworker? part(2)


    let t: String = js_sys::global().to_string().into();
    if t == "[object Window]" {

is there something better than the above ? I'm running into the problem where Window appears to not be defined in webworker threads, and thus I can't even do a dyn_into() without getting a JS runtime error.

Related Post:

Revisiting Check if wasm thread if main thread of web worker? (but for a different reason).

Different motivation this time.

I'm writing Rust/wasm code that uses the Fetch/Sleep calls. Unfortunately, depending on if we are on the main thread (use window()) or webworker (use dedicatedWolrkerGlobalScope) we have to make different calls.

I am wondering if there is a more elegant / less hacky way (than the above) for detecting if we are on main thread or in a webworker.