The Element.requestPointerLock() method allows to asynchronously ask for the pointer to be locked on the given element.
The Element.requestPointerLock() method allows to asynchronously ask for the pointer to be locked on the given element.
To track the success or failure of the request, it is necessary to listen for the pointerlockchange and pointerlockerror events at the Document level.
MDN