AmbientLightSensor

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The AmbientLightSensor interface of the the Ambient Light Sensor API returns an interface for accessing AmbientLightSensorReading.

Constructor

AmbientLightSensor.AmbientLightSensor()
Creates a new AmbientLightSensor object.

Properties

AmbientLightSensor.illuminance
Returns a Number indicating the current light level.

Examples

if ( 'AmbientLightSensor' in window ) {
  const sensor = new AmbientLightSensor();
  sensor.onreading = () => {
    console.log('Current light level:', sensor.illuminance);
  };
  sensor.onerror = (event) => {
    console.log(event.error.name, event.error.message);
  };
  sensor.start();
}

Specifications

Specification Status Comment
Ambient Light Sensor
The definition of 'AmbientLightSensor' in that specification.
Working Draft Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support54 ? ? ? ? ?
AmbientLightSensor() constructor54 ? ? ? ? ?
illuminance54 ? ? ? ? ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5454 ? ? ? ? ?
AmbientLightSensor() constructor5454 ? ? ? ? ?
illuminance5454 ? ? ? ? ?

Document Tags and Contributors

Contributors to this page: connorshea, fscholz, RockoDev, david_ross, Joel-Kornbluh, jpmedley
Last updated by: connorshea,