Last active
May 10, 2026 15:11
-
-
Save mohit-s96/e5c85283e2c9f04ac992adc8a30178af to your computer and use it in GitHub Desktop.
spoof location/GPS with the geolocation API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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