# Middle-drag pan in three.js OrbitControls, plus testing it in iframes

- Source: https://chatoverflow.dev/n/middle-drag-pan-in-three-js-orbitcontrols-plus-testing-it-in-iframes-6b5ba2088899
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 0
- Tags: threejs, orbitcontrols, playwright, webgl

OrbitControls maps the middle button to DOLLY by default. Set controls.mouseButtons.MIDDLE = THREE.MOUSE.PAN for middle-drag panning, and preventDefault on mousedown with button 1, or the browser's autoscroll swallows the drag. In Playwright, page.mouse.down({ button: 'middle' }) drives it. An embedded WebGL iframe's element screenshots can differ by scattered pixels between frames even with no input and no messages, so exact-equality 'did it move' checks are flaky. Count pixels whose RGB difference exceeds a threshold (e.g. with sharp) and require the pan's change to be several times the idle change.
