Icons representing Sensor API

Designing A Generic Sensor API For The Web Platform


Creating a set of web APIs for interacting with the physical world.

Based on our experience designing hardware programming APIs for Johnny-Five, we proposed an alternative device sensory programming model for the Web Platform, that establishes a generic sensor class for all sensors to inherit from. That proposal was adopted and became the foundation for the Generic Sensor API. Working with Tobie Langel and Anssi Kostiainen at the W3C, we were able to drive interest and development, resulting in the suite of modern sensory APIs coming to the Web Platform.


Physical device sensor APIs for the web were originally introduced to the web platform as DeviceMotionEvent, DeviceOrientationEvent along with their respective window.* event handlers: ondevicemotion, ondeviceorientation and oncompassneedscalibration. These early APIs were essentially just ports from the Core Motion APIs to WebKit JS APIs. Despite opening up exciting new possibilities for human interaction with web applications, this API design was identified as an anti-pattern that prohibited the platform from supporting multiple sensors of a given kind and abetted the proliferation of new sensor APIs that were unintuitive and nonsensical for the web platform. In 2012, other platform implementers announced work (Fri, 7 Dec 2012, Tue, 18 Dec 2012) on implementations and proposals for standardization of more new sensor APIs that attempted to force the same strange design pattern (DeviceLightEvent, DeviceProximityEvent). To be fair, we must mention that these designs were well-intentioned, with the assumption that API design consistency was a desirable trait.


We used our experience designing JavaScript APIs for physical world and device sensors to inform a more generalizable and scalable programming interface for the web platform. This resulted in the creation of the Generic Sensor specification and the rebooting of sensor API suite, which now includes:


By providing a clear and consistent way to describe programming interfaces for device sensors, the Generic Sensor API has opened the door for a wave of new web platform capabilities that are powerful and intuitive. Additionally, its strength as a thoughtfully designed base class has inspired a rebooting of several extant sensor APIs, for example navigator.geolocation.* and DeviceOrientationEvent have been superseded by the Geolocation Sensor and Orientation Sensor.

To track the progress of these new capabilities in the web platform, take a look at the latest test results for each new API: Accelerometer, Ambient Light, Generic Sensor, Geolocation Sensor, Gyroscope, Magnetometer, Orientation Sensor, and Proximity.

To see demonstration examples of these sensors, check out Intel's Generic Sensors Demo.

Contact Us

We'd love to hear from you. Get in touch!


P.O. Box 961436
Boston, MA 02196