Ambient Light

The Ambient Light API allows web applications to access the light intensity level measured by the device's light sensor.

The first approach to supporting light intensity sensor on the web - as a standalone API - was implemented in Firefox. Since then the specification was rewritten to make use of the new Generic Sensors API, but no vendor implemented that spec as of September 2016.

API glimpse

The old, standalone API

window.addEventListener('devicelight', listener)
An event fired when the device's light sensor measured value has changed, containing the light intensity expressed in lux.

The new, generic API

sensor = new AmbientLightSensor()
Creates an object serving as an accessor to the light intensity sensor readings.
sensor.addEventListener('change', listener)
An event fired when the light intensity has changed, with event.reading.illuminance property containing the light intensity expressed in lux.
sensor.start()
Starts listening for the sensor readings.

Resources