The Ambient Light API allows web applications to access the light intensity level measured by the device's light sensor, normally built-in with the device's camera.
The first approach to supporting light intensity sensor on the web - as a standalone API - was implemented in Firefox back in 2013. Since then the specification was rewritten to make use of the new Generic Sensors API. This flavor, as of summer 2017, is implemented in Microsoft Edge and - behind the "Experimental Web Platform Features" flag - in Google Chrome.
The old, standalone API
- 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.
- An event fired when the light intensity has changed, with
event.reading.illuminanceproperty containing the light intensity expressed in lux.
- Starts listening for the sensor readings.