JavaScript Document pointerlockerror Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Document event
Limited availability

What You’ll Learn

The Document pointerlockerror event fires when locking the pointer fails (technical reasons or permission denied). Learn how to use document.onpointerlockerror, why it does not bubble, how it pairs with requestPointerLock() and pointerlockchange, and five try-it labs.

01

Kind

Document event

02

Type

Event

03

Cancelable

No

04

Bubbles

No — listen on document

05

Also check

Promise .catch()

06

Status

Limited availability

Introduction

Pointer lock is powerful for games and 3D viewers—and often restricted. If requestPointerLock() is denied, the pointer stays unlocked. Instead you get a pointerlockerror event on document (and, in browsers that return a Promise, a rejection).

MDN documents this as a Document event that is not cancelable and does not bubble. Listening on document is the right place for app-wide error UI alongside pointerlockchange.

💡
Beginner tip

The most common beginner mistake is calling requestPointerLock() outside a click/key handler. Many browsers deny that and fire pointerlockerror. MDN marks this API Limited availability (not Baseline)—feature-detect and test.

Understanding pointerlockerror

A Document event that answers: “Did pointer lock fail?”

  • Fires when locking the pointer failed (technical reasons or permission denied).
  • Does not bubble — listen on document (unlike fullscreenerror’s Element-then-Document path).
  • Not cancelable — you cannot force a lock with preventDefault().
  • Event type — a plain Event (no rich error code on the event itself).
  • Handlerdocument.onpointerlockerror or document.addEventListener("pointerlockerror", ...).
  • Limited availability on MDN (not Baseline)—test carefully.

📝 Syntax

Use the event name with addEventListener, or set the handler property on document:

JavaScript
addEventListener("pointerlockerror", (event) => { });

onpointerlockerror = (event) => { };

Event type

A generic Event. Not cancelable and does not bubble.

MDN Document example

JavaScript
const para = document.querySelector("p");

document.addEventListener("pointerlockerror", (event) => {
  console.log("Error locking pointer");
});

// or
document.onpointerlockerror = (event) => {
  console.log("Error locking pointer");
};

Success vs failure path

OutcomeWhat you get
SuccessPromise resolves + pointerlockchange
Failurepointerlockerror on document (+ Promise reject in some browsers)

⚠️ Why Pointer Lock Requests Fail

  • No user gesture — call from a click/key handler, not a bare timer.
  • Permission denied — the browser or user may refuse pointer lock.
  • Unsupported context — older browsers, some embedders, or restricted environments.
  • Technical issues — MDN notes failures for technical reasons as well as denial.
  • Exit failures — the Pointer Lock overview also mentions errors from exitPointerLock().

See MDN’s Pointer Lock API guide and the pointerlockerror page for details.

⚖️ pointerlockerror vs pointerlockchange

Topicpointerlockchangepointerlockerror
MeaningPointer locked or unlockedLock (or exit) failed
Typical next stepUpdate UI from pointerLockElementShow error / keep unlocked UI
PromiseMay resolve on successMay reject on failure
Bubbles?No — DocumentNo — Document
Cancelable?NoNo

⚡ Quick Reference

GoalCode / note
Listen (Document)document.addEventListener("pointerlockerror", fn)
Handler propertydocument.onpointerlockerror = fn
Catch Promise tooel.requestPointerLock().catch(handler)
Cancelable / bubbles?No / No
Sibling success eventpointerlockchange
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts to remember about Document pointerlockerror.

Event type
Event

Plain Event

Means
Lock fail

Could not lock

Also
.catch()

Promise rejects

Baseline
no

Limited availability

Examples Gallery

Examples follow MDN Document: pointerlockerror event and listen on document. Some labs intentionally trigger failures (for example calling without a user gesture).

📚 Getting Started

MDN-style Document listener and the handler property.

Example 1 — Document addEventListener (MDN)

Log when locking the pointer fails; listen on document (MDN pattern).

JavaScript
const para = document.querySelector("p");

document.addEventListener("pointerlockerror", (event) => {
  console.log("Error locking pointer");
});
Try It Yourself

How It Works

MDN listens on document. Pair this with a user-gesture call to requestPointerLock(). Calling lock without a gesture is a common way to see pointerlockerror in demos.

Example 2 — document.onpointerlockerror

Update a status line when the Document handler property receives the event.

JavaScript
const el = document.getElementById("game");
const out = document.getElementById("out");

document.onpointerlockerror = () => {
  out.textContent = "pointerlockerror: could not lock pointer";
};

document.getElementById("bad").addEventListener("click", () => {
  // May still fail in unsupported / restricted environments
  el.requestPointerLock();
});
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners. Keep the property form for tiny demos.

📈 Promise, Gesture & Fallback

Pair the event with Promise rejection, show a common denial, and offer UI fallback.

Example 3 — Event + Promise .catch()

Handle both Document pointerlockerror and requestPointerLock().catch().

JavaScript
const el = document.getElementById("game");
const out = document.getElementById("out");

document.addEventListener("pointerlockerror", () => {
  out.textContent = "Event: pointerlockerror (on document)";
});

document.getElementById("go").addEventListener("click", () => {
  el.requestPointerLock().catch((err) => {
    out.textContent =
      "Promise rejected: " + (err && err.message ? err.message : String(err));
  });
});
Try It Yourself

How It Works

The event is a generic signal; the Promise rejection often carries a more useful message. Handle both for robust UX.

Example 4 — Delayed Call (No User Gesture)

Arm a timer from a click, then call requestPointerLock later to show a common denial.

JavaScript
const el = document.getElementById("game");
const out = document.getElementById("out");

document.addEventListener("pointerlockerror", () => {
  out.textContent = "pointerlockerror (likely no user gesture / denied)";
});

document.getElementById("arm").addEventListener("click", () => {
  out.textContent = "Calling requestPointerLock in 500ms without a gesture...";
  setTimeout(() => {
    el.requestPointerLock().catch(() => {
      out.textContent += "\nPromise also rejected.";
    });
  }, 500);
});
Try It Yourself

How It Works

The original click gesture is gone by the time the timer runs. Call requestPointerLock() synchronously inside the click handler instead.

Example 5 — Friendly UI Fallback

On Document pointerlockerror, show a message and apply a CSS unlocked fallback mode.

JavaScript
const el = document.getElementById("game");
const msg = document.getElementById("msg");

document.addEventListener("pointerlockerror", () => {
  msg.textContent =
    "Pointer lock blocked here. Using mouse-move aiming without lock.";
  el.classList.add("is-fallback");
});

document.addEventListener("pointerlockchange", () => {
  if (document.pointerLockElement) {
    msg.textContent = "Pointer lock OK";
    el.classList.remove("is-fallback");
  }
});

document.getElementById("go").addEventListener("click", () => {
  el.requestPointerLock();
});
Try It Yourself

How It Works

Never leave the player stuck. Pair error handling with a usable fallback so games still aim with regular mouse moves when lock is denied.

🚀 Common Use Cases

  • Toast / banner when a “Lock pointer” button is denied.
  • Falling back to regular mouse-move aiming for games.
  • Logging analytics for pointer-lock permission failures.
  • Teaching why user gestures matter for privileged APIs.
  • One Document listener covering lock errors for every game surface.

🔧 How It Works

1

Request pointer lock

Code calls element.requestPointerLock() (or exit fails).

Request
2

Browser denies

No gesture, permission denial, or technical limits block the lock.

Deny
3

pointerlockerror

Document fires the event; optional Promise rejects.

Notify
4

Show fallback UI

Message the user and keep unlocked mouse aiming working.

📝 Notes

Limited Availability Support

Document pointerlockerror is marked Limited availability on MDN (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. Feature-detect requestPointerLock / exitPointerLock, and remember some environments deny pointer lock.

Limited availability

Document pointerlockerror

Failure signal when locking the pointer fails (or sometimes when exit fails). Confirm support and user-gesture rules in your target browsers.

Limited Not Baseline
Google Chrome Supported (check BCD / platform)
Supported
Mozilla Firefox Supported in modern versions
Supported
Apple Safari Supported with platform quirks
Supported
Microsoft Edge Supported · Chromium
Supported
Opera Supported · Modern versions
Supported
Internet Explorer No modern Pointer Lock API
No
pointerlockerror Limited

Bottom line: Listen on document for pointerlockerror, lock from a user gesture, and always provide an unlocked fallback for games.

Conclusion

Document pointerlockerror is your safety net when pointer lock is denied. Listen on document for app-wide errors, catch the Promise when available, and keep unlocked mouse aiming ready.

Continue with prerenderingchange, pointerLockElement, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Listen on document for global pointer-lock error UI
  • Also handle requestPointerLock().catch() when a Promise is returned
  • Call requestPointerLock() from a real user gesture
  • Offer unlocked mouse-move aiming as a fallback
  • Feature-detect and handle pointerlockchange for success

❌ Don’t

  • Assume every browser allows pointer lock
  • Call lock from a bare timer
  • Expect preventDefault() to force a lock
  • Ignore failures and leave the game UI looking broken
  • Assume Baseline Widely available status

Key Takeaways

Knowledge Unlocked

Five things to remember about Document pointerlockerror

Failure signal on Document — always plan an unlocked fallback.

5
Core concepts
🚫 02

No bubble

listen on document

DOM
📦 03

Promise

may also reject

API
👋 04

User gesture

required often

Cause
⚠️ 05

Limited avail.

not Baseline

Compat

❓ Frequently Asked Questions

It fires when locking the pointer failed — for technical reasons or because permission was denied. Per the Pointer Lock API overview, errors from requestPointerLock() or exitPointerLock() dispatch pointerlockerror to the document.
No. MDN does not mark Document pointerlockerror as Deprecated, Experimental, or Non-standard. It has Limited availability (not Baseline), so always test the browsers and embedding contexts you care about.
Common reasons: no user gesture, unsupported browser or context, permission denial, or other technical restrictions. Listen for pointerlockerror and optionally handle a Promise rejection when requestPointerLock returns a Promise.
No. MDN states this event is not cancelable and does not bubble. Listen on document.
No. Unlike fullscreenerror (Element then Document), MDN documents pointerlockerror as a Document event that does not bubble. Listen on document.
Success path: pointerlockchange fires and pointerLockElement is non-null. Failure path: pointerlockerror fires instead and the pointer stays unlocked.
Did you know?

The Pointer Lock overview describes pointerlockerror as a simple event with no extra data. That is why you often pair it with UI messages and, when available, the Promise rejection message from requestPointerLock().

Next: Document prerenderingchange

Learn the Document event that fires when a Speculation Rules prerender is activated.

prerenderingchange →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful