Search code examples
javascriptandroidiosmobiledevice-orientation

How sensitive is DeviceOrientation when browsing the web on Mobile in a handheld context


I'd like to determine the chances or prospects of reading a mobile device's orientation using the DeviceOrientation Javascript API (not orientationchange) when loading a web page.

Unless I am mistaken, the W3C specs indicate the DeviceOrientation properties can only be read during an event trigger. i.e. The initial states are not exposed if the device is not moving at all.

If so, is DeviceOrientation sensitive enough to read a value in most common cases where the device is held by hand(s), while the user wait for a page load, assuming very subtle hand/motion tilts.


Solution

  • After testing on actual devices, I am noticing that the device orientation is quite sensitive. For my initial use case anyway. It's sensitive enough that it almost always fire, reporting alpha, beta and gamma value that are not all 0 when using any mobile browser (phone or tablet) that support the DeviceOrientation API, not matter how you use it (even if it sits on a table).

    The drawback is that the ondeviceorientation event only fires after window.load on Webkit/Blink. Or about 25ms to 100ms after the window load event, varying upon browsers and devices. While Firefox fires the event early at the interactive state of the document before DOMContentLoaded.

    So it seems impossible to start rendering a web page in the context of the initial device's rotation for lack of early detection capabilities. That's a significant flaw of the current DeviceOrientation API.