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
Fundamentals
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.
Concept
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).
Handler — document.onpointerlockerror or document.addEventListener("pointerlockerror", ...).
Limited availability on MDN (not Baseline)—test carefully.
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property on document:
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
Hands-On
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).
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();
});
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.
LimitedNot Baseline
Google ChromeSupported (check BCD / platform)
Supported
Mozilla FirefoxSupported in modern versions
Supported
Apple SafariSupported with platform quirks
Supported
Microsoft EdgeSupported · Chromium
Supported
OperaSupported · Modern versions
Supported
Internet ExplorerNo modern Pointer Lock API
No
pointerlockerrorLimited
Bottom line: Listen on document for pointerlockerror, lock from a user gesture, and always provide an unlocked fallback for games.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Document pointerlockerror
Failure signal on Document — always plan an unlocked fallback.
5
Core concepts
📄01
Lock failed
could not lock
Event
🚫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().