| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/API/Sensor | [Back] [Original] |
Get to know MDN better
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.
The Sensor interface of the Sensor APIs is the base class for all the other sensor interfaces. This interface cannot be used directly. Instead it provides properties, event handlers, and methods accessed by interfaces that inherit from it.
This feature may be blocked by a Permissions Policy set on your server.
EventTarget SensorWhen initially created, the Sensor object is idle, meaning it does not take measures. Once the start() method is called, it prepares itself to read data and, once ready, the activate event is sent and the sensor becomes activated. It then sends a reading event each time new data is available.
In case of an error, the error event is sent, reading stops, and the Sensor object becomes idle again. The start() method needs to be called again before it can read further data.
Sensor
SensorBelow is a list of interfaces based on the Sensor interface.
AccelerometerAmbientLightSensorGravitySensorGyroscopeLinearAccelerationSensorMagnetometerOrientationSensorSensor.activated Read onlyReturns a boolean value indicating whether the sensor is active.
Sensor.hasReading Read onlyReturns a boolean value indicating whether the sensor has a reading.
Sensor.timestamp Read onlyReturns the timestamp of the latest sensor reading.
Sensor.start()Activates one of the sensors based on Sensor.
Sensor.stop()Deactivates one of the sensors based on Sensor.
activateFired when a sensor becomes activated.
errorFired when an exception occurs on a sensor.
readingFired when a new reading is available on a sensor.
| Specification |
|---|
| Generic Sensor API # the-sensor-interface |
This page was last modified on Mar 13, 2025 by MDN contributors.
SensorYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |