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

geolocation option for newContext on the Browser class doesn't seem to override the real geolocation #435

Open
ankur22 opened this issue Jul 5, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@ankur22
Copy link
Collaborator

ankur22 commented Jul 5, 2022

Tested against: dbede12

I've created a simple go app which returns an html page which allows geolocation:

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
	navigator.geolocation.getCurrentPosition(function(position) {
		let lat = position.coords.latitude;
		let long = position.coords.longitude;

		document.getElementById("demo").innerHTML = "Lat: " + lat.toFixed(2) + " Long: " + long.toFixed(2) + "";
		latText.innerText = lat.toFixed(2);
		longText.innerText = long.toFixed(2);
	});
}
</script>
</head>
<body>
<h2>Demo JavaScript in Head</h2>

<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>

</body>
</html>

When the button is clicked to "Try it", i'm expecting the result to look like this when i use the geolocation option:

Screenshot 2022-07-05 at 17 26 30

But what actually happens is that it timeouts waiting for the location to be calculated. When running against google maps, it should use the override values, but it instead uses the real location values.

Here's the test script:

NOTE: In the code below it works against localhost:8080, which is a test server. It can be found in the following link along with Instructions on how to run it locally: https://github.com/grafana/xk6-browser/tree/temp/testserver/testserver.

import { sleep } from 'k6';
import launcher from 'k6/x/browser';

export default function () {
  const browser = launcher.launch('chromium', {
      headless: false,
  });
  browser.newContext({
    geolocation: {
        latitude: 18.452626,
        longitude: 33.930396,
        accuracy: 0,
      },
  });
  const cc = browser.contexts();
  const page = cc[0].newPage();
  const res = page.goto('http://localhost:8080');

  sleep(30);
  browser.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant