v150 · Device Orientation
Orientation permission & tilt
Tap the button to call the real DeviceOrientationEvent.requestPermission() from a user gesture. On "granted", the page subscribes to deviceorientation and tilts the card + spirit level with your device's live alpha/beta/gamma. No sensor (e.g. a desktop)? The manual preview below lets you drive the same visual by hand — clearly labelled, never dressed up as sensor data.
requestPermission() isn't exposed in this browser.Launch Chrome 150+ with
--enable-blink-features=DeviceOrientationRequestPermission, or enable
chrome://flags/#enable-experimental-web-platform-features. On browsers without it (older Chrome/desktop),
orientation events may still be attached directly — this page falls back to that automatically.
tilt card (β·γ)
spirit level
Manual preview SIMULATION — not sensor data
Check each sample's event.absolute: a relative sample uses an arbitrary initial reference, so its alpha is not a compass heading; an absolute sample uses the Earth's reference frame via a magnetometer. To explicitly request magnetometer permission, pass true for the optional absolute parameter and listen for deviceorientationabsolute. The spec currently marks its permission integration and the absolute event as at risk.
document.querySelector("button").addEventListener("click", async () => {
// requestPermission MUST be called from a user gesture —
// without transient activation the promise rejects with NotAllowedError
if (typeof DeviceOrientationEvent.requestPermission === "function") {
const state = await DeviceOrientationEvent.requestPermission(); // "granted" | "denied"
if (state !== "granted") return;
}
window.addEventListener("deviceorientation", (e) => {
// e.alpha (0–360), e.beta (−180–180), e.gamma (−90–90)
tilt(e.beta, e.gamma);
});
});
see also
- Motion permission & shake —
DeviceMotionEvent.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 ↗