v150 · Device Orientation

Motion permission & shake

Call the real DeviceMotionEvent.requestPermission() from a tap, then read devicemotion: linear acceleration, acceleration including gravity, and rotation rate. The meter tracks total acceleration magnitude; cross the threshold and the shake detector fires. On a device with no accelerometer, the readout stays empty and the threshold slider still lets you explore the logic — honestly labelled.

permission: unknown
Tap "Enable motion access" to request permission.
shake detector idle
total acceleration magnitude0.0 m/s²
acceleration x·y·z (gravity removed)
including gravity x·y·z
rotation rate α·β·γ
interval / events— / 0
18 m/s²

Manual magnitude SIMULATION — not sensor data

0 m/s²
button.addEventListener("click", async () => {
  // requestPermission MUST be called from a user gesture —
  // without transient activation the promise rejects with NotAllowedError
  if (typeof DeviceMotionEvent.requestPermission === "function") {
    if (await DeviceMotionEvent.requestPermission() !== "granted") return;
  }
  window.addEventListener("devicemotion", (e) => {
    const a = e.acceleration;              // gravity removed (may be null)
    const g = e.accelerationIncludingGravity;
    const mag = Math.hypot(a.x || 0, a.y || 0, a.z || 0);
    if (mag > THRESHOLD) onShake();
  });
});

see also

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗