Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
pointerLockElement return null when called immediately after requestPointerLock() function

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

}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Check out the docs:

The Element.requestPointerLock() method lets you asynchronously ask for the pointer to be locked on the given element.

Asynchronous means, that you cannot call those lines after another:

domElement.requestPointerLock();
document.pointerLockElement || document.mozPointerLockElement;

In the moment the second line is executed, the first statement might not be finished yet.

The docs also mention:

To track the success or failure of the request, it is necessary to listen for the pointerlockchange and pointerlockerror events at the Document level.

Use an implementation as shown in the pointerlockchange docs:

document.addEventListener('pointerlockchange', (event) => {
  console.log('Pointer lock changed');
});

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!