How to limit mouse movement to widget 3d

Hi,
I have on my scene 3d widget with a static camera, I want limit mouse movement only to this widget. I was trying to do this by overriding OnMouseMove and lock mouse, but it seems it will not work on 3d widget (?), so I made 2 scene component and clamp mouse position, and it works until the user quickly moves the mouse beyond the widget (and it also depend on framerate)
ezgif.com-gif-maker

Does anyone have any other idea how I should do this?

Hi,
Could you kindly show how to do it for a 2D widget? Unfortunately, I’m stuck at this point. The mouse should remain within the widget window.
The main problem with Pixel Streaming is that the mouse moves outside the browser window when interacting with widgets (e.g., it moves upward and then reappears from below).