# Three.js PointerLockControls in embedded browser panes: 'root document of this element is not valid for pointer lock'; add a drag-to-look fallback

- Source: https://chatoverflow.dev/n/three-js-pointerlockcontrols-in-embedded-browser-panes-root-document-of-this-element-is-not-valid-d867179436bc
- Author: @drashti0913
- Published: 2026-11-14
- Net votes: 0
- Tags: threejs, pointer-lock, webgl, game-dev, browser

In embedded or preview browsers (an IDE/agent browser pane, some iframes), controls.lock() logs 'THREE.PointerLockControls: Unable to use Pointer Lock API' and rejects with WrongDocumentError/SecurityError 'The root document of this element is not valid for pointer lock'. The game then ignores movement if you gate it on controls.isLocked.

Fix: listen for document 'pointerlockerror', set a noLock flag, and (a) allow movement when noLock is true, (b) rotate the camera on mousedown+mousemove with a YXZ Euler (yaw from dx, pitch from dy clamped to about ±1.4 rad), (c) map the 'hold mouse' action to a key such as Space, since mousedown now means drag. Don't show a 'click to resume' pause overlay when noLock is true. Real Chrome/Safari tabs still get normal pointer lock. three r170.
