Skip to Content
Platform.Ontology

Magnetometer

Reads the magnetic field around the device, like a compass.

Asks you firstLocation and motionGeneric Sensor APIWeb browsersWhile you use it

In one line

Can sense the magnetic field around your device, like a compass

Reads the magnetic field around the device, like a compass.

Gives compass heading and can reveal nearby metal and electronics. Indoor magnetic fields form a rough fingerprint of a building or room.

What it can and can't do

What the user does: Nothing in most browsers. Chrome allows it by default unless you changed Motion sensors in site settings

It can

  • Find which way your device points, like a compass
  • Spot nearby metal and electronics
  • Guess which room or building you are in from its magnetic pattern, roughly

It cannot

  • Run in Firefox or Safari, which do not support it
  • Show a prompt in Chrome; there is none by default
  • Measure the field while the page is closed

How it differs between platforms: Chrome, Edge and Samsung Internet support it. Safari and Firefox do not.

Browser support

BrowserStatusFirst versionReleasedNote
ChromeSupported672018-05-29None
EdgeSupported792020-01-15None
FirefoxNot supportedNot availableNot listedNone
SafariNot supportedNot availableNot listedNone
Safari on iPhoneNot supportedNot availableNot listedNone
Chrome on AndroidSupported672018-05-31None
Samsung InternetSupported9.02018-09-15BCD lists no support; agent research says otherwise

How a site asks for it

APInew Magnetometer({frequency})
Permission namemagnetometer
Permissions policymagnetometer
Browser compat keysapi.Magnetometer
How access is grantedprompt
What the user seesChromium 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 gestureNo
How long it lastsSite setting Allow or Block per origin
How to take it backchrome://settings/content/sensors; Permissions API 'change' event
Inside an iframeCross-origin iframes blocked unless allow="magnetometer"; page must be focused and visible

Typical flow

  1. Check isSecureContext and Permissions Policy
  2. Construct the sensor with {frequency: 60}
  3. sensor.start()
  4. '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)

FieldTypeUnitRangePrecision
x, y, zfloatmicroteslaabout -4900 to 4900 hardware; Earth field 25 to 65about 0.1
frequencyfloatHz1 to 10 effective1 Hz

Technical limits

  • Chrome limits sampling for privacy
  • Not in Firefox or Safari

The story

What it is

The page reads the magnetic field around your device, like a compass.

For you

A compass or a map turns to match where you face. You may not see a prompt. Nearby metal and electronics change what the sensor reads.

For makers

Makers use it for compass features and AR. Indoor magnetic patterns can help place a person in a building, and they are also a rough fingerprint of where a device has been.

Where you see it

TypeExampleApps
mapsA web map or hiking page turns to the direction you face.Google Maps, AllTrails
ar-vrA web AR scene lines up virtual objects with north.8th Wall
gamesA treasure hunt or location web game points you toward the next clue.Geocaching.com
travelA museum or airport web app uses magnetic maps to guide people indoors.None named
securityA fraud tool may check whether a phone reads believable magnetic data, since an emulator does not.None named
analyticsA tracker uses the readings to build a rough fingerprint of the device and its surroundings.None named

Risks

  • Hints at surroundings
  • Fingerprint clue

What the platform says

Good uses and abuse

Legitimate uses

  • Compass in web maps
  • AR heading

Known abuse

  • Indoor localisation by magnetic fingerprint

Scores

ScoreValueMeaning
Sensitivity3 of 5How revealing the data is
Utility3 of 5How useful it is to honest apps
Friction1 of 5How much the user has to do
Fingerprint bits3Rough identifying entropy, when known

History

  • 2018-05, Chrome 67: Magnetometer ships with the Generic Sensor API

Sources

How well checked: Based on official documentation.

On this page