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
Comments
Thank you @jimevans for filing! I want to add that clients should be able to set this location override per tab. |
The Browser Testing and Tools Working Group just discussed 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 |
Should we propose it as part of the https://w3c.github.io/geolocation-api/ spec? |
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. |
WebdriverIO currently already supports this by overwriting the 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}
})
}`
}) |
@christian-bromann Thanks for sharing! Do you support changing it after the page is loaded/during the test? Also, what about I think the override on the browser side would be more robust but preload scripts offer the ability to implement something already. |
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. |
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.
The text was updated successfully, but these errors were encountered: