Reported mouse movement is massively slower on Wasm than on native when cursor is locked
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.15.3 and 0.16.0-rc.5
## Relevant system information
native:
```ignore
2025-04-15T20:34:25.405810Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 41 Fedora Linux", kernel: "6.13.9-200.fc41.x86_64", cpu: "AMD Ryzen 9 7950X 16-Core Processor", core_count: "16", memory: "30.4 GiB" }
2025-04-15T20:34:25.466728Z INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon RX 7900 XTX (RADV NAVI31)", vendor: 4098, device: 29772, device_type: DiscreteGpu, driver: "radv", driver_info: "Mesa 25.0.2", backend: Vulkan }
```
firefox:
```ignore
INFO /home/hhh/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_render-0.15.3/src/renderer/mod.rs:199 AdapterInfo { name: "Radeon R9 200 Series, or similar", vendor: 4098, device: 0, device_type: Other, driver: "", driver_info: "WebGL 2.0", backend: Gl }
```
chromium:
```ignore
INFO /home/hhh/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_render-0.16.0-rc.5/src/renderer/mod.rs:200 AdapterInfo { name: "ANGLE (AMD, AMD Radeon RX 7900 XTX (radeonsi navi31 LLVM 19.1.7), OpenGL 4.6)", vendor: 4098, device: 0, device_type: Other, driver: "", driver_info: "WebGL 2.0 (OpenGL ES 3.0 Chromium)", backend: Gl }
```
Firefox: `137.0 (64-bit)`
Chromium: `Version 135.0.7049.84 (Official Build) (64-bit)`
## What you did
Either execute this [Bevy playground snippet](https://learnbevy.com/playground?share=7c1e2e0aab10579f10465e304b9a90d62784a0650187609815b7e3d4fd8a2640) directly or write this code:
main.rs
```rust
use std::time::Duration;
use bevy::{
input::{common_conditions::input_just_pressed, mouse::AccumulatedMouseMotion},
prelude::*,
window::CursorGrabMode,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(
Update,
(
count_motion,
capture_cursor.run_if(input_just_pressed(MouseButton::Left)),
),
)
.run();
}
fn count_motion(
time: Res
fn median(values: &[f32]) -> f32 {
let mut sorted = values.to_vec();
sorted.sort_by(|a, b| a.partial_cmp(b).unwrap());
sorted[sorted.len() / 2]
}
fn capture_cursor(mut window: Single<&mut Window>) {
window.cursor_options.visible = false;
window.cursor_options.grab_mode = CursorGrabMode::Locked;
}
```
Now run it once using `bevy run` and once using `bevy run web`. On web, open the console to see the output.
## What went wrong
On Firefox:
Move the mouse around the window in web *before* you click into the window. Notice the output.
Now, click into the center of the window to lock the cursor. Continue moving the mouse at the same pace. Notice that the output drastically went down.
On native, you will not be able to recreate this behavior.
For me, the bug was not present on Chromium, but other users report getting the issue *only* on Chrome.
## Additional information
Using an extra scaling factor on Wasm is not enough, as slow mouse movements get reported as absolute zero.
This might also very well be a winit bug, I didn't investigate it independently of Bevy.
This is the output for slow mouse movement:

The cutoff to the locked state should be obvious, as the numbers go down drastically.
Note that the message saying that the mouse moved a distance of zero is collapsed as it is repeated 6(!) times.
This is the output for fast mouse movement:

Note that the amount of zeros does not go up, but the maximal distance and average distance per second are drastically lower.
Contributor guide
Assessment
This issue has not been assessed yet.