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

Emulation: Support geolocation override #343

Open
jimevans opened this issue Dec 8, 2022 · 7 comments
Open

Emulation: Support geolocation override #343

jimevans opened this issue Dec 8, 2022 · 7 comments
Labels
emulation Emulation module needs-discussion Issues to be discussed by the working group

Comments

@jimevans
Copy link
Collaborator

jimevans commented Dec 8, 2022

One request often heard from users is that they want to simulate a browser at a specific geolocation for their sites. WebDriver should provide a mechanism to facilitate this testing.

@whimboo whimboo added the emulation Emulation module label Dec 8, 2022
@whimboo
Copy link
Contributor

whimboo commented Dec 8, 2022

Thank you @jimevans for filing!

I want to add that clients should be able to set this location override per tab.

@whimboo whimboo changed the title Support for simulating geolocation Emulation: Support location override Dec 8, 2022
@whimboo whimboo changed the title Emulation: Support location override Emulation: Support geolocation override Dec 8, 2022
@whimboo whimboo added the needs-discussion Issues to be discussed by the working group label Apr 10, 2024
@css-meeting-bot
Copy link
Member

The Browser Testing and Tools Working Group just discussed Geolocation emulation.

The full IRC log of that discussion <jgraham> Topic: Geolocation emulation
<jgraham> github: https://github.com//issues/343
<orkon> q+
<jgraham> jgraham: We know there are requests for this and Puppeteer has it, so this should be the next priority for emulation and overrides
<jgraham> ack next
<jgraham> orkon: We support this in puppeteer. The blocker for using this in BiDi is that we need to be able to provide permissions. It might be possible to use a preload script to override things, but I'm not sure.
<jgraham> q?
<jgraham> jgraham: I assumed we'd just provide mock data, does that require implementing permissions?
<jgraham> orkon: To request geolocation data you first have to give permissions. We could say that providing the data atuo-grants the permissions, but it might make sense to do permissions first, if that's needed cross-browser.
<orkon> q+
<JimEvans> q+
<jgraham> jgraham: Makes sense. We can do the work in parallel though; browsers might have some out of band way to disable the permissions prompt so you could still test that the right geolocation data is returned without supporting the permissions API.
<jgraham> ack next
<jgraham> orkon: Perhaps there is also a relation to the user prompt handing changes; permissions are like user prompts and we could have similar auto-accept functionality.
<jgraham> ack next
<jgraham> JimEvans: Does the permissions spec have a BiDi implementation?
<jgraham> orkon: We have it in Chrome, but I don't know about other implementations. It only covers overrides.
<jgraham> jgraham: We have the permissions spec implemented in classic, but not yet for BiDi (need to check which parts are actually shipping already)
<jgraham> RRSAgent: make minutes
<RRSAgent> I have made the request to generate https://www.w3.org/2024/04/10-webdriver-minutes.html jgraham
<jgraham> zakim, bye
<Zakim> leaving. As of this point the attendees have been AutomatedTester_, orkon, jdescottes, whimboo, jgraham, sasha, MaksimSadym, JimEvans, lightning00blade
<sasha> orkon: `browsingContext.setViewport` command already has a step to check if a specified context is a top-level context, and throw an error if it's not, so we don't need to do anything for iframes
<jgraham> RRSAgent: bye
<RRSAgent> I see no action items

@OrKoN
Copy link
Contributor

OrKoN commented Apr 10, 2024

Should we propose it as part of the https://w3c.github.io/geolocation-api/ spec?

@OrKoN
Copy link
Contributor

OrKoN commented Apr 10, 2024

Chrome currently supports latitude, longitude, accuracy overrides which works for the top-level context and iframes. It does not affect the permission and it does not allow to use geolocation on insecure contexts.

@christian-bromann
Copy link
Member

WebdriverIO currently already supports this by overwriting the navigator.geolocation interface in the browser via the preload script:

const patchedFn = options instanceof Error
    ? `cbError(new Error(${JSON.stringify(options.message)}))`
    : `cbSuccess({
        coords: ${JSON.stringify(options)},
        timestamp: Date.now()
    })`
await this.scriptAddPreloadScript({
    functionDeclaration: /*js*/`() => {
        Object.defineProperty(navigator.geolocation, 'getCurrentPosition', {
            value: (cbSuccess, cbError) => ${patchedFn}
        })
    }`
})

@OrKoN
Copy link
Contributor

OrKoN commented Apr 11, 2024

@christian-bromann Thanks for sharing! Do you support changing it after the page is loaded/during the test? Also, what about Geolocation.watchPosition()?

I think the override on the browser side would be more robust but preload scripts offer the ability to implement something already.

@christian-bromann
Copy link
Member

I agree. The current emulation features we have can't be changed after the page has loaded. It would be helpful, especially for component tests to modify these capabilities without having to do a page load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emulation Emulation module needs-discussion Issues to be discussed by the working group
Projects
None yet
Development

No branches or pull requests

5 participants