Add support for approximate geolocation#195
Conversation
|
For readability as you iterate on this proposal it's okay for this PR to directly change the specification text however to land this change the changes need to be enclosed in the correct candidate additions/corrections/deletions syntax. |
|
@reillyeon if it's ok, let's move this to CR first (i.e., let's not waste time with the ins/dels). We are close to publishing as CR again. |
99d9b03 to
3fa8869
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for approximate location positioning to the Geolocation API specification. It introduces a privacy-preserving alternative to precise location sharing, allowing applications to request coarse-grained location data when high accuracy is not needed.
Key changes:
- Introduces
accuracyModeoption with "precise" (default) and "approximate" values - Adds new "geolocation-approximate" permission alongside existing "geolocation" permission
- Implements separate caching for precise and approximate positions
- Updates permission request flows to allow users to choose between precise and approximate location sharing
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3fa8869 to
8658f5a
Compare
2354ca8 to
d3a4d47
Compare
antosart
left a comment
There was a problem hiding this comment.
A few comments wrt the permission handling.
d3a4d47 to
b0d0589
Compare
|
Ok, added to Privacy WG agenda: Will ping Mozilla folks directly. |
|
Oops, thanks @alvinjiooo for pinging @nondebug! Added him to the Moz position too. |
|
Fyi @tomvangoethem pointed out that the paragraph regarding State 5. was confusing, so I tried to make it a bit more clear, see the diff here. |
|
Thanks for the ping! (I'm Tom from the Chrome Privacy team). My understanding of the proposed changes to make
So the prompt/granted case for querying "geolocation"/"geolocation-approximate" would only indicate whether a user granted or denied an approximate-only permission prompt where the site selected Given that there is no net-new information added with |
|
Hi @tomvangoethem! Welcome! 🤗 so yeah, that’s my argument: developers don’t get any additional value/info from querying “geolocation-approximate” given that what matters is |
I wanted to chime in again since I think this is actually where we disagree. I believe that having all the following three properties:
is what makes everything simple and usable for web developers. In particular, it is what allows them to easily switch to using approximate-only (if that fits their use case) without regressions in functionality and without precluding the possibility of using precise position in the future, which is what we want to encourage also from a privacy point of view. I don't think it's possible to have 1. 2. and 3. without a separate queryable permission for approximate location only. |
|
Mmm, will reverify tomorrow if it’s a possibility with code. I concluded above the it was absolutely possible, but maybe 🤔 I made a mistake. I’ll try to prove it again purely with JS. |
cc @jyasskin |
|
I just wanted to elaborate a bit more on the privacy perspective: ideally, we want to encourage sites to request approximate-only when that's all the information they need (see also the W3C privacy principles on data minimization). Being able to upgrade the geolocation permission to precise (if this would be required for another use case on the site) and having full support to do so (i.e. having a representative While it's possible to mimic the behavior in JS with a number of caveats, it's far from ideal. I would imagine that code would look something like this: navigator.geolocation.getCurrentPosition((pos) => {
localStorage.setItem('canAskForPrecise', true);
processPosition(pos);
}, (err) => {
localStorage.setItem('canAskForPrecise', false);
}, {accuracyMode: 'approximate'});
// ... later, if precise is required:
// NOTE: this only works if the user did not make any changes to the granted permissions
if (localStorage.getItem('canAskForPrecise')) {
navigator.geolocation.getCurrentPosition(handlePrecisePos, {accuracyMode: 'precise'});
}By having the separate navigator.geolocation.getCurrentPosition(processPosition, {accuracyMode: 'approximate'});
// ... later, if precise is required:
// NOTE: if this returns "prompt", we are sure we can ask the user for precise location
if ((await navigator.permissions.query({name: 'geolocation'})).state == 'prompt') {
navigator.geolocation.getCurrentPosition(handlePrecisePos, {accuracyMode: 'precise'});
}The latter looks way more intuitive to me, provides clarity to sites, and better supports the (from a privacy perspective) preferred approach of asking for approximate location when that is all the information that is (initially) needed. |
|
@antosart, I built a test harness to verify whether a single-permission model can satisfy your three properties. The results are more nuanced than I expected. Demo: https://marcoscaceres.github.io/geolocation-permissions-demo/ (source) What it testsThe demo implements both models (Chromium's two-permission proposal and WebKit's single-permission proposal) as mock APIs, then tests developer patterns across all four permission states to see whether The findingThe results depend on an assumption that neither of us has articulated: what does We assume the UA returns approximate data rather than re-prompting, since the user already consented to sharing location. Under that assumption, both models behave differently when the
The
|
|
Thanks for trying this out concretely. One observation though:
Actually, in our proposal this is covered in the explainer and is also explicitly specified in the current version of the spec PR (although it's arguably not that easy to decode). In particular, there are two cases in which only
So this is actually incorrect. Chromium's model respects the invariant "permissions.query() returns prompt iff getCurrentPosition() shows a prompt". |
|
Inspired by your idea @marcoscaceres I created an emulator of how the permission model we are proposing would work. Playing with that is much easier than reading through the explainer. PTAL! |
Clarifies that exposing the "geolocation-approximate" permission is not strictly enforced, and implementations may choose to only make "geolocation" queryable.
|
@marcoscaceres / @antosart / @tomvangoethem , |
| <a>"geolocation-approximate"</a> changes: | ||
| </p> | ||
| <ol class="algorithm"> | ||
| <li>If the [=permission state=] of <a>"geolocation"</a> is changed to |
There was a problem hiding this comment.
I think we should also add:
If the permission state of "geolocation" is granted and the permission state of "geolocation-approximate" is changed to prompt, set the permission state of "geolocation" to prompt.
If the permission state of "geolocation-approximate" is denied and the permission state of "geolocation" is changed to prompt, set the permission state of "geolocation-approximate" to prompt.
There was a problem hiding this comment.
I think current algorithm give the basic coherence between two permissions seems good to me. I am not sure whether should we add more coherence here given that it might bring more questions and different agents might want to implement this differently. Maybe let's add it later from a new issue so we can discuss further on finer permission control for this feature?
There was a problem hiding this comment.
Exactly... what @alvinjiooo said.
Maybe we can add a note or issues here saying we are still trying to figure this out. And we can link to the issue via <aside class="issue" data-number="??">
There was a problem hiding this comment.
This should be handled by the Permissions spec, as these changes are bound to the event loop.
If anything, changes state needs to "queue at task on the ??? task source to ..." so the permission state can change at the appropriate time at the turn of the event loop (so the PermissionState can do what it needs to do).
There was a problem hiding this comment.
The point is that the PR as currently written assumes that the combined permission states are in one of the 6 allowed states. The algorithms break otherwise. Given that, I do believe that we should explicitly listing the 6 allowed states (see comment above) and also write that implementations must make sure that everything stays consistent at all times. If we list things that implementors must do, I say either we list all of them or we skip all.
There was a problem hiding this comment.
I’ll have another look. If they as look up tables for state, the yes: make sense to keep them. I didn’t get that sense tho, as the permission state is maintained independently by the permission store (as permissions might change at any time for any reason… they expire, users changes them, os level changes etc. and the change might not always be observable by script).
There was a problem hiding this comment.
@marcoscaceres ,
I discussed with @antosart and decided to remove the new/old permission coherence description from this PR and added a aside tag with issue #231 to track the follow up discussion. Currently we still keep the table for the permission state combos which we believe you also think that is reasonable to have it in this PR. Please take a look at the latest version of the PR and let us know if this looks good to you.
Thanks!
This update correctly links to the Permissions API using ReSpec citing conventions and resolves a missing definition error by using the correct 'query a permission' algorithm term.
Hi @marcoscaceres , |
marcoscaceres
left a comment
There was a problem hiding this comment.
Mostly just nits now... but question around the permissions table.
Otherwise looking pretty good.
- Use <dl>, <dt>, and <dd> for precise and approximate position definitions. - Convert informative note on permission masking to a normative statement. - Tidy index.html.
There was a problem hiding this comment.
I updated for most comments but leave the permission states combination table since @antosart and @marcoscaceres still having discussion. For other comments I have them updated and resolved.
Closes #182
This commit introduces the ability for users and developers to request a less precise, privacy-preserving "approximate" location.
Key changes include:
The following tasks have been completed:
Implementation commitment (and no objections):
Documentation (new feature):
For documentation, either create an issue or pull request in MDN's Content repo - providing as much information as you can. PR is prefered.
Approximate Geolocation explainer
Preview | Diff