AmbientLightSensor: AmbientLightSensor() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

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

The AmbientLightSensor() constructor creates a new AmbientLightSensor object, which returns the current light level or illuminance of the ambient light around the hosting device.

Syntax

js
new AmbientLightSensor()
new AmbientLightSensor(options)

Parameters

options Optional

Currently only one option is supported:

frequency Optional

The desired number of times per second a sample should be taken, meaning the number of times per second that reading event will be called. A whole number or decimal may be used, the latter for frequencies less than a second. The actual reading frequency depends on the device hardware and consequently may be less than requested.

Exceptions

SecurityError DOMException

Use of this feature was blocked by a Permissions Policy.

Specifications

Specification
Ambient Light Sensor
# dom-ambientlightsensor-ambientlightsensor

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
AmbientLightSensor() constructor
Experimental
Chrome – No support
Chrome 56 (Release date: 2017-01-25)
disabled
disabled From version 56 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Chrome, visit chrome://flags.
Chrome – No support
Chrome 67 (Release date: 2018-05-29)
disabled
disabled From version 67 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Chrome, visit chrome://flags.
Edge – No support
Edge 79 (Release date: 2020-01-15)
disabled
disabled From version 79 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Edge, visit about:flags.
Edge – No support
Edge 79 (Release date: 2020-01-15)
disabled
disabled From version 79 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Edge, visit about:flags.
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera 43 (Release date: 2017-02-07)
disabled
disabled From version 43 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Opera, visit opera://flags.
Opera – No support
Opera 54 (Release date: 2018-06-28)
disabled
disabled From version 54 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Opera, visit opera://flags.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android 56 (Release date: 2017-02-01)
disabled
disabled From version 56 users must explicitly set the #enable-experimental-web-platform-features preference to Enabled. To change preferences in Chrome Android, visit chrome://flags.
Chrome Android – No support
Chrome Android 67 (Release date: 2018-05-31)
disabled
disabled From version 67 users must explicitly set the #enable-generic-sensor-extra-classes preference to Enabled. To change preferences in Chrome Android, visit chrome://flags.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

No support
No support
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
Has more compatibility info.

See also