Wgpu / wasm32 hide/lock cursor

I'm on Rust compiled to Chrome/wasm32. I have a canvas that is rendering via wgpu.

I would like to hide + "lock" the cursor (as one would expect a FPS style game to).

I am trying:

        // window: winit:;window::Window
        web_sys::console::log_1(&"hiding cursor".into());

            .or_else(|_e| window.set_cursor_grab(CursorGrabMode::Locked))


It is doing nothing. The "hiding cursor" line appears in Google chrome dev console, but the cursor is neither hidden nor locked in the web browser.

Question: am I (1) calling the wrong functions or (2) calling the right functions but in the wrong place or (3) need some other magical incantation to hide + lock more cursor ?


Figured out the issue:

The code is correct, but it can not be called during initialization. It must be called during some "user event handler".

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.