[deviceorientation] Guidance needed: how to acquire compass headings in a future-compatible manner? (#137)

juj has just created a new issue for https://github.com/w3c/deviceorientation:

== Guidance needed: how to acquire compass headings in a future-compatible manner? ==
Today there exists an event [deviceorientationabsolute](https://developer.mozilla.org/en-US/docs/Web/API/Window/deviceorientationabsolute_event) that can be used to register to device orientation events that are relative to the magnetic north pole (for 1D compass heading calculations)

This event is available on other browsers except Safari.

On Safari `window.addEventListener('deviceorientationabsolute', ...)` does not work, but instead one must first call `DeviceOrientationEvent.requestPermission()` and after that Promise resolves to a success, register to the `window.addEventListener('deviceorientation', ...)` event, and use `DeviceOrientationEvent.webkitCompassHeading` to acquire the 1D compass heading direction.

In other browsers today, I understand that one does not need to call `DeviceOrientationEvent.requestPermission()` before registering a `deviceorientationabsolute` event handler, though I presume that since the function is in the spec, that in the future this may also be required.

But this gives a problem: what kind of code should one write in order to precisely register to get 1D compass heading directions in a manner that will be forward-compatible to future Firefox, Chrome and Safari browsers?

We can feature test whether `DeviceOrientationEvent.requestPermission()` exists and call it before registering a handler, but how does one know precisely whether to register `'deviceorientation'` or `'deviceorientationabsolute'` events?


Please view or discuss this issue at https://github.com/w3c/deviceorientation/issues/137 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 31 January 2024 17:34:02 UTC