Using Light Sensor in Google Chrome
Light Sensor needs to be enabled in Chrome: go to: chrome://flags/#enable-generic-sensor-extra-classes and enable it.
Then you will be able to get sensor readings
const sensor = new AmbientLightSensor();
sensor.start();
sensor.addEventListener('reading', () => {
console.log(sensor.illuminance);
});
There are also activate
and error
events on the sensor object that can be listened to.
Full article: https://blog.arnellebalane.com/using-the-ambient-light-sensor-api-to-add-brightness-sensitive-dark-mode-to-my-website-82223e754630
Tweet