How to replicate CursorLockMode.Confined in browser WebGL?

Hi. I want to replicate the behaviour of setting the cursor lock state to Confined (mouse is visible, but can’t leave the play window/screen) but in WebGL.

Cursor.lockState = CursorLockMode.Confined;

The docs say that this functionality only works in Windows and Linux. Does anyone have any ideas on how this could be replicated for a web browser using WebGL?

That’s simply not possible. A website running in a browser does not get any access to the hardware cursor. Browsers provide the Pointer Lock API which Unity is using in order to lock the cursor. However it does not allow to specify how the cursor is locked. For security reasons when the user presses ESC the lock has to be released and can not be acquired again until the user clicks onto the canvas again. This is to prevent a website trapping the mouse.

So there is no way to set the position of the hardware / system mouse cursor from inside a website.

What you can do is simply show a software mouse cursor and move it around based on the mouse delta. Though it highly depends on what you want to do.