Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guidance needed: how to acquire compass headings in a future-compatible manner? #137

Open
juj opened this issue Jan 31, 2024 · 2 comments
Open
Labels

Comments

@juj
Copy link

juj commented Jan 31, 2024

Today there exists an event deviceorientationabsolute 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?

@anssiko
Copy link
Member

anssiko commented Feb 25, 2024

@marcoscaceres
Copy link
Member

marcoscaceres commented May 22, 2024

Just noting that registering a listener shouldn't have any side effects (i.e., it doesn't automatically enable the machinery to start firing the events).

One would still need to request permission.

In WebKit specifically, we don't implement "deviceorientationabsolute" it seems.

It seems Gecko does... but I haven't confirmed how it works there.

@rakuco, I saw you took an action to look into what Gecko does... could you still do that? I'd like to get a complete picture of what each browser is doing and then we can look at aligning everything in the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants