I want to Change our Browser location to usa Please help me changing firefox location i.e geolocation location for testing.
The two preferences mentioned by nmaler are spot-on. Additionally, you don't need a (local) server, a data:-URI works fine too.
For example, if you set the preference geo.wifi.uri
(at about:config
) with value:
data:,{"location":{"lat":1.2,"lng":3.4},"accuracy":4000}
and then test by running the following from the JS console:
navigator.geolocation.getCurrentPosition(pos => console.log(pos.coords));
then you will see that the spoof succeeded:
Coordinates { latitude: 1.3, longitude: 11, altitude: 0, accuracy: 4000, ... }
If you need to generate a valid data:-URL with JavaScript (e.g. in add-on code), use the following. Note that I use encodeURIComponent
just in case the pos
object somehow contains special characters such as %
or #
(this is unlikely, but better safe than sorry):
var pos = {
location: {
lat: 1.2,
lng: 3.4,
},
accuracy: 4000,
};
var geoWifiUrl = `data:,${encodeURIComponent(JSON.stringify(pos))}`;
// TODO: Set geo.wifi.url's pref to geoWifiUrl.
The easiest way would be to setup your own geolocation mock server and change some preferences:
geo.provider.testing
, setting it to true
. This will force the network provider on (instead of an OS level geo location provider, if any).geo.wifi.uri
to the URI of your mock server, e.g. http://localhost:8888/
You can change preferences in about:config
or by editing the prefs.js
file of your browser profile directly. Easiest way to open the profile directory is using the corresponding button in about:support
.
Sample mock server in python2 (returning always the coordinates for the White House):
import json
import BaseHTTPServer
import SocketServer
PORT = 8888
LAT, LNG = 38.894967, -77.034917
class GeoHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json.dumps({
"location": {
"lat": LAT,
"lng": LNG
},
"accuracy": 4000
}))
def do_POST(self):
return self.do_GET()
httpd = SocketServer.TCPServer(("", PORT), GeoHandler)
print "serving at port
If you want to spoof your location for the HTML5 Geolocation API you can follow these steps:
about:config
.geo.wifi.uri
.Change the value to something like this:
data:application/json,{"location": {"lat": 40.7590, "lng": -73.9845}, "accuracy": 27000.0}
(The lat
and lng
values determine the latitude and longitude of your location.)
Note that if you want to prevent websites from deriving the location from your IP address you can't do that on the application layer - the only way will be a proxy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With