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.
requestPermission() isn't exposed in this browser.Launch Chrome 150+ with
--enable-blink-features=DeviceOrientationRequestPermission, or enable
chrome://flags/#enable-experimental-web-platform-features. Where the gate is absent, this page
attaches the devicemotion listener directly.
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
Manual magnitude SIMULATION — not sensor data
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
- Orientation permission & tilt —
DeviceOrientationEvent.requestPermission() - Feature-detect the gate — the cross-browser pattern
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗