AmbientLightSensor
Reads the light level (lux) around the device; not shipped by default anywhere.
In one line
Can't use your device's light sensor in most browsers today
Reads the light level (lux) around the device; not shipped by default anywhere.
Shows whether the person is indoors, outdoors or in a dark room. Research showed it can leak visited links and cross-origin pixels, so Chrome keeps it behind a flag and Firefox removed it.
What it can and can't do
What the user does: Nothing. Chrome keeps it off by default behind a setting, and Firefox removed it
It can
- Measure the light level (lux) if you turn the browser flag on
- Hint whether you are outside, indoors or in a dark room
- Dim or brighten a page when it works
It cannot
- Run by default in Chrome, Edge or Samsung Internet; it sits behind a flag
- Run in Firefox, which removed it, or in Safari, which never had it
- Avoid privacy risks; research found it can leak visited links and screen pixels
How it differs between platforms: Chrome-based browsers have it only behind a flag. Firefox removed it and Safari never added it.
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Behind a flag | 67 | Not listed | Needs chrome://flags generic-sensor-extra-classes |
| Edge | Behind a flag | 79 | Not listed | None |
| Firefox | Removed | 62 | 2018-09-05 | devicelight events removed from release builds |
| Safari | Not supported | Not available | Not listed | None |
| Safari on iPhone | Not supported | Not available | Not listed | None |
| Chrome on Android | Behind a flag | 67 | Not listed | None |
| Samsung Internet | Behind a flag | 9.0 | Not listed | None |
How a site asks for it
| API | new AmbientLightSensor({frequency}); sensor.illuminance; legacy 'devicelight' event |
| Permission name | ambient-light-sensor |
| Permissions policy | ambient-light-sensor |
| Browser compat keys | api.AmbientLightSensor |
| How access is granted | prompt |
| What the user sees | Chromium shows no bubble: access follows the Motion sensors site setting (default Allow) plus the Permissions API name. Safari and Firefox do not ship the API. |
| Needs a secure context (HTTPS) | Yes |
| Needs a user gesture | No |
| How long it lasts | Site setting Allow or Block per origin |
| How to take it back | chrome://settings/content/sensors; Permissions API 'change' event |
| Inside an iframe | Cross-origin iframes blocked unless allow="ambient-light-sensor"; page must be focused and visible |
Typical flow
- Check isSecureContext and Permissions Policy
- Construct the sensor with {frequency: 60}
- sensor.start()
- 'reading' events fire; 'error' event on NotAllowedError or NotReadableError
Data you get
What comes back: Sensor readings at the requested frequency
Shape: event
How often: up to 60 Hz (Chrome caps frequency)
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
illuminance | float | lux | 0 to about 100000 | coarse rounding in flag builds |
frequency | float | Hz | 1 to 10 | 1 Hz |
Technical limits
- Unusable on stable by default in major browsers
- Secure context and policy still apply when flagged on
The story
What it is
Reads how bright it is around your device. Not available by default in browsers.
For you
Almost no one will see this. If it were on, a page could dim itself in a dark room. It is not turned on in browsers by default, because it was found to leak information.
For makers
Makers wanted it for auto dark mode and for reading light for photos. It was held back after research showed it could leak links you visited and pixels from another site.
Where you see it
| Type | Example | Apps |
|---|---|---|
| media | A reading or video page could switch to dark mode when your room goes dark. | None named |
| accessibility | A web app could raise contrast in bright sunlight to help low vision readers. | None named |
| ar-vr | A web AR scene could match virtual lighting to the room. | None named |
| games | A browser game could change its look at night to match your room light. | None named |
| analytics | Trackers would see if you are indoors or outside, and a screen reflection could leak details. | None named |
| security | Researchers showed it could guess visited links and cross site pixels, so browsers held it back. | None named |
Risks
- Leaks what is on screen
- Hardly shipped
Good uses and abuse
Legitimate uses
- Auto dark mode
- Reading apps
Known abuse
- Cross-origin link and pixel leaks via light reflection
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 2 of 5 | How revealing the data is |
| Utility | 2 of 5 | How useful it is to honest apps |
| Friction | 3 of 5 | How much the user has to do |
| Fingerprint bits | 2 | Rough identifying entropy, when known |
History
- 2017, paper n/a: Olejnik analysis of light sensor leaks (links, pixels)
- 2018-05, Chrome 67: Implemented but disabled by default
- 2018-09, Firefox 62: devicelight and lightlevel events disabled after privacy findings
Related capabilities
Related
- DeviceOrientation and DeviceMotion events. Can sense how your phone is tilted and shaken, sometimes only after you allow it
Sources
How well checked: Based on official documentation.