The portable motion API is the deviceorientation event (angles alpha, beta, gamma) with its sibling devicemotion (acceleration in m/s²), Widely available since March 2026. iOS delivers them only after DeviceOrientationEvent.requestPermission() runs from a click, and Chrome 152 1 added that method too. The Generic Sensor API (Accelerometer, Gyroscope, AbsoluteOrientationSensor and relatives) adds a sampling frequency but ships only in Chromium 4,389 .
tiltButton.onclick = async () => {
if (await DeviceOrientationEvent.requestPermission?.() === 'denied') return;
addEventListener('deviceorientation', (e) => { // beta: front-back, gamma: left-right
ball.style.translate = `${e.gamma * 2}px ${e.beta * 2}px`;
});
};
const acl = new Accelerometer({ frequency: 30 });
acl.onreading = () => console.log(acl.x, acl.y, acl.z); // includes gravity
acl.onerror = (e) => console.log(e.error.name); // NotAllowedError, NotReadableError
acl.start();Headless Chrome has no sensors and logs NotAllowedError; test on a phone or fake values in the DevTools Sensors panel.