Magnetometer: Magnetometer() 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 insecure contexts (HTTPS), in some or allsupporting browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
TheMagnetometer() constructorcreates a newMagnetometer object which returns information about themagnetic field as detected by a device's primary magnetometer sensor.
In this article
Syntax
new Magnetometer()new Magnetometer(options)Parameters
optionsOptionalOptions are as follows:
frequencyOptionalThe desired number of times per second a sample shouldbe taken, meaning the number of times per second that the
readingevent will be called. A whole number or decimal may beused, the latter for frequencies less than a second. The actual reading frequencydepends on device hardware and consequently may be less than requested.referenceFrameOptionalEither
'device'or'screen'. The default is'device'.
Exceptions
SecurityErrorDOMExceptionUse of this feature was blocked by aPermissions Policy.
Specifications
| Specification |
|---|
| Magnetometer> # dom-magnetometer-magnetometer> |
Browser compatibility
See also
readingevent