Skip to content

Instantly share code, notes, and snippets.

@mohit-s96
Last active May 10, 2026 15:11
Show Gist options
  • Select an option

  • Save mohit-s96/e5c85283e2c9f04ac992adc8a30178af to your computer and use it in GitHub Desktop.

Select an option

Save mohit-s96/e5c85283e2c9f04ac992adc8a30178af to your computer and use it in GitHub Desktop.
spoof location/GPS with the geolocation API
/*
* Run this in your console with the desired latitude and longitude values just before the page requests location / after the page loads..
*
* getCurrentPosition takes a callback function which is normally called when the user gives persmission to access location.
* Here we shim the function with our own implementation which resolves after sometime with the fake coordinate data.
*
* we're no-op'ing the watchPosition function because websites can use this to track changes in the location which can be used
* to detect the last position.
*/
navigator.geolocation.getCurrentPosition = (fn) => {
setTimeout(() => {
fn({
coords: {
accuracy: 40,
altitude: null,
altitudeAccuracy: null,
heading: null,
latitude: 12.9716,
longitude: 77.5946,
speed: null,
},
timestamp: Date.now(),
})
navigator.geolocation.watchPosition = () => {}
}, 2912)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment