Skip to content

Instantly share code, notes, and snippets.

@Nerahikada
Created June 20, 2023 12:21
Show Gist options
  • Save Nerahikada/3fd3dfcefbb20718ba48eeb8c39c564f to your computer and use it in GitHub Desktop.
Save Nerahikada/3fd3dfcefbb20718ba48eeb8c39c564f to your computer and use it in GitHub Desktop.
Geolocation API Spoofer
a=navigator.geolocation,b=()=>Math.random()*2147483647,c=null,a&&(a.getCurrentPosition=(d,e)=>{confirm(`Do you want to allow ${location.hostname} to access your location?`)?d({coords:{latitude:b(),longitude:b(),altitude:c,accuracy:b(),altitudeAccuracy:c,heading:c,speed:c},timestamp:Date.now()}):e({code:1,message:"User denied geolocation prompt"})})
if (navigator.geolocation) {
navigator.geolocation.__proto__.getCurrentPosition = (success: Function, error: Function) => {
if (confirm(`Do you want to allow ${location.hostname} to access your location?`)) {
success(new class{
/**
* GeolocationPosition class
* @link https://developer.mozilla.org/docs/Web/API/GeolocationPosition
*/
public readonly coords = new class{
/**
* GeolocationCoordinates class
* @link https://developer.mozilla.org/ja/docs/Web/API/GeolocationCoordinates
*/
public readonly latitude: number = Math.random() * 2147483647;
public readonly longitude: number = Math.random() * 2147483647;
public readonly altitude: number|null = null;
public readonly accuracy: number = Math.random() * 2147483647;
public readonly altitudeAccuracy: number|null = null;
public readonly heading: number|null = null;
public readonly speed: number|null = null;
};
public readonly timestamp: number = Date.now();
});
}else{
error(new class extends Error{
/**
* GeolocationPositionError class
* @link https://developer.mozilla.org/docs/Web/API/GeolocationPositionError
*/
public readonly code: 1|2|3 = 1;
public readonly message: string = "User denied geolocation prompt";
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment