Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change firefox Location setting

I want to Change our Browser location to usa Please help me changing firefox location i.e geolocation location for testing.

like image 335
Charnjeet Singh Avatar asked Jul 24 '14 11:07

Charnjeet Singh


3 Answers

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.
like image 173
Rob W Avatar answered Sep 25 '22 13:09

Rob W


The easiest way would be to setup your own geolocation mock server and change some preferences:

  1. Create (or change) the boolean geo.provider.testing, setting it to true. This will force the network provider on (instead of an OS level geo location provider, if any).
  2. Change the geo.wifi.uri to the URI of your mock server, e.g. http://localhost:8888/
  3. Start your mock server and restart Firefox.
  4. Test that stuff works, e.g.

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
like image 20
nmaier Avatar answered Sep 23 '22 13:09

nmaier


If you want to spoof your location for the HTML5 Geolocation API you can follow these steps:

  • Go to about:config.
  • Type in 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.)

  • Congratulations, you're now on Times Square! (You can test the result here.)

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.

like image 37
greuze Avatar answered Sep 24 '22 13:09

greuze