-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
performance.now in worker #1752
Comments
It looks like our webidl, which is derived from Firefox/Gecko, only has it on the |
It looks like performance on worker global scope is part of the High Resolution Time Level 2 recommendation, and it is defined as an attribute on the The link from that spec to caniuse.com seems to indicate most browsers have full support for it: https://caniuse.com/#feat=high-resolution-time I spent a few hours looking into this today, as I was trying to use the |
This issue causes the |
As a workaround, I added this and it let me call performance.now() inside of webworker: #[wasm_bindgen]
extern "C" {
#[no_mangle]
#[used]
static performance:web_sys::Performance;
} |
From which context is perfomance called from on Firefox/Geeko? I suppose it's still WorkerGlobalScope right? so it's should be an easy fix! |
There is no way to access the `performance` object from `web_sys` inside web workers because `web_sys` only exposes the `Window` object, not available in a worker context. Instead, as workaround, we use `wasm_bindgen` with `extern "C"` to access the `performance` object directly. rustwasm/wasm-bindgen#1752 https://rustwasm.github.io/wasm-bindgen/reference/attributes/on-js-imports/js_name.html
Another workaround until this is fixed could be: let performance = js_sys::Reflect::get(&js_sys::global(), &"performance".into())
.expect("failed to get performance from global object")
.unchecked_into::<web_sys::Performance>();
let time = performance.time_origin() + performance.now(); |
Fixed by #3506. |
MDN says that WorkerGlobalScope has
performance
in Chrome and Firefox: https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/performanceweb-sys
doesn't seem to export this: https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.WorkerGlobalScope.htmlIs this expected? If so, what is the right way to get
performance.now
from inside a worker?The text was updated successfully, but these errors were encountered: