Skip to content

feat: add accuracyMode to emulation.setGeolocationOverride#1105

Open
alvinjiooo wants to merge 1 commit into
w3c:mainfrom
alvinjiooo:geolocation-api
Open

feat: add accuracyMode to emulation.setGeolocationOverride#1105
alvinjiooo wants to merge 1 commit into
w3c:mainfrom
alvinjiooo:geolocation-api

Conversation

@alvinjiooo
Copy link
Copy Markdown

@alvinjiooo alvinjiooo commented Mar 21, 2026

This pull request adds an optional accuracyMode parameter to the emulation.setGeolocationOverride command.

This aligns WebDriver BiDi with the upcoming changes to the W3C Geolocation API, which introduces support for approximate geolocation via the accuracyMode attribute on the GeolocationPosition interface.


Preview | Diff

@alvinjiooo
Copy link
Copy Markdown
Author

Hi @OrKoN,
May I have your help to review this PR?
Thanks!
Alvin

@whimboo whimboo added enhancement New feature or request module-emulation Emulation module labels Mar 23, 2026
Comment thread index.bs Outdated
(coordinates: emulation.GeolocationCoordinates / null) //
(error: emulation.GeolocationPositionError)
),
? accuracyMode: "precise" / "approximate",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that also apply to errors? If not we should add this field to GeolocationCoordinates.

Suggested change
? accuracyMode: "precise" / "approximate",
? accuracyMode: "approximate", "precise",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the placement of accuracyMode: While we could move it into GeolocationCoordinates, it is intended to describe the operating mode of the browser's geolocation service (based on the website's request and the user's permission state) rather than a property of the coordinates themselves. In the underlying Geolocation spec PR #195, accuracyMode is defined on the GeolocationPosition interface at the same level as coords (GeolocationCoordinates).

And yes, accuracyMode should be paired only with coordinates, I wonder would it work if I move it to the group with coordinates like:

emulation.SetGeolocationOverrideParameters = {
  (
    (
      coordinates: emulation.GeolocationCoordinates / null,
      ? accuracyMode: "precise" / "approximate"
    ) //
    (error: emulation.GeolocationPositionError)
  ),
  ? contexts: [+browsingContext.BrowsingContext],
  ? userContexts: [+browser.UserContext],
}

Will this break existing tooling and tests which already using setGeolocationOverride?

Copy link
Copy Markdown
Author

@alvinjiooo alvinjiooo Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually update the PR further for emulated position data to either emulation.GeolocationCoordinates or GeolocationPositionError. I think it probably will be better to pass emulated position data as a map with {coordinates:..., accuracyMode?: ... } or {error: {code: ...}}, so the Geolocation side can decide what to created at their side. I also have Geolocation PR#195 (at step 5.5 of Acquire a position algorithm) updated to hook this up.
PTAL at latest version and thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this break existing tooling and tests which already using setGeolocationOverride?

This should work fine given that this is a new optional parameter. Older versions of browsers will just ignore it as long as the handling of the parameter is not supported.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't see the proposed changes from your second last comment yet. accuracyMode should be part of emulation.GeolocationCoordinates given that if coordinates is null we won't need this parameter's value.

Copy link
Copy Markdown
Author

@alvinjiooo alvinjiooo Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @whimboo,
Sorry for the confusion, my original plan was to add accuracyMode outside of GeolocationCoordinates, but after discussing with w3c/geolocation#195 reviewer we think it seems also feasible to add new accuracyMode into GeolocationCoordinates. So I updated the CDDL and remote end steps for the new proposal (add new accuracyMode into GeolocationCoordinates). Thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @whimboo,
Do you get a chance to review the latest PR?
Thanks!

Comment thread index.bs Outdated
@alvinjiooo alvinjiooo requested a review from whimboo March 25, 2026 22:00
@alvinjiooo alvinjiooo marked this pull request as draft March 25, 2026 22:51
@alvinjiooo alvinjiooo marked this pull request as ready for review March 26, 2026 03:39
@alvinjiooo alvinjiooo marked this pull request as draft March 26, 2026 17:58
@alvinjiooo alvinjiooo marked this pull request as ready for review March 27, 2026 03:51
@alvinjiooo alvinjiooo force-pushed the geolocation-api branch 2 times, most recently from a0cc095 to f0340e4 Compare April 6, 2026 20:57
Copy link
Copy Markdown
Contributor

@whimboo whimboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it looks like that I missed the emails from a week ago given that there was a public holiday and I was out as well for some days.

I think that one of our latest changes (#1086) caused merge conflicts for you.

Comment thread index.bs Outdated
Comment thread index.bs
Comment on lines -6310 to +6311
A <dfn>geolocation override</dfn> is a [=struct=] with:
* [=struct/item=] named <dfn attribute for="geolocation override">latitude</dfn> which is a float;
* [=struct/item=] named <dfn attribute for="geolocation override">longitude</dfn> which is a float;
* [=struct/item=] named <dfn attribute for="geolocation override">accuracy</dfn> which is a float;
* [=struct/item=] named <dfn attribute for="geolocation override">altitude</dfn> which is a float or null;
* [=struct/item=] named <dfn attribute for="geolocation override">altitudeAccuracy</dfn> which is a float or null;
* [=struct/item=] named <dfn attribute for="geolocation override">heading</dfn> which is a float or null;
* [=struct/item=] named <dfn attribute for="geolocation override">speed</dfn> which is a float or null.
A <dfn>geolocation override</dfn> is a [=/map=].
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change all these lines? It's for the internal data structure. You need to get the accuracy mode added. Maybe this was caused by a merge conflict? The same applies to the changes below.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @whimboo,
Thanks for the review! The reason for changing the geolocation override from a struct to a map was intend to fix an existing type inconsistency in the spec regarding how we handle the error parameter.
In the original code, geolocation override was defined as a strict struct containing only coordinate floats (latitude, longitude, etc.). However, in the algorithm steps for setGeolocationOverride, when an "error" is provided, the spec does this:

Let emulated position data be a map matching GeolocationPositionError production...

This created an inconsistency where the geolocation override configuration (which is typed as a geolocation override) was being forced to store a map representing a GeolocationPositionError, instead of the expected struct of coordinates. I believe changing internal definition of geolocation override to be a map, containing either GeolocationCoordinates or GeolocationPositionError, should resolve this conflict. So Geolocation side can check what does geolocation override contain and decide what to create. Please let me know what do you think about this.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request module-emulation Emulation module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants