PointerLockElement returns null when called immediately after requestPointerLock() function
domElement.onclick = () => { // requestPointerLock() needs to be called by user input
domElement.requestPointerLock = domElement.requestPointerLock || domElement.mozRequestPointerLock;
domElement.requestPointerLock();
console.log(document.pointerLockElement || document.mozPointerLockElement); // return null
}
Check out the docs:
Asynchronous means, that you cannot call those lines after another:
In the moment the second line is executed, the first statement might not be finished yet.
The docs also mention:
Use an implementation as shown in the pointerlockchange docs: