如何更改firefox位置设置

问题描述 投票:5回答:3

我想将我们的浏览器位置更改为美国请帮助我更改firefox位置,即地理定​​位位置以进行测试。

firefox firefox-addon browser
3个回答
8
投票

nmaler提到的两个首选项是定点。此外,您不需要(本地)服务器,数据:-URI也可以正常工作。

例如,如果您使用值设置首选项geo.wifi.uri(在about:config):

data:,{"location":{"lat":1.2,"lng":3.4},"accuracy":4000}

然后通过从JS控制台运行以下代码进行测试:

navigator.geolocation.getCurrentPosition(pos => console.log(pos.coords));

然后你会看到恶搞成功了:

Coordinates { latitude: 1.3, longitude: 11, altitude: 0, accuracy: 4000, ... }

如果您需要生成有效数据:-URL with JavaScript(例如,在附加代码中),请使用以下内容。请注意,我使用encodeURIComponent以防pos对象以某种方式包含特殊字符,如%#(这不太可能,但比抱歉更安全):

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.

7
投票

最简单的方法是设置自己的地理定位模拟服务器并更改一些首选项:

  1. 创建(或更改)布尔值geo.provider.testing,将其设置为true。这将强制网络提供商(而不是OS级别的地理位置提供商,如果有的话)。
  2. geo.wifi.uri更改为模拟服务器的URI,例如http://localhost:8888/
  3. 启动模拟服务器并重新启动Firefox。
  4. 测试那些东西是有效的,e.g.

您可以在about:config中更改首选项,也可以直接编辑浏览器配置文件的prefs.js文件。打开配置文件目录的最简单方法是使用about:support中的相应按钮。

python2中的示例模拟服务器(总是返回白宫的坐标):

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

2
投票

如果您想欺骗HTML5 Geolocation API的位置,您可以按照以下步骤操作:

  • about:config
  • 输入geo.wifi.uri
  • 将值更改为以下内容: data:application / json,{“location”:{“lat”:40.7590,“lng”: - 73.9845},“准确度”:27000.0} (latlng值决定了您所在位置的纬度和经度。)
  • 恭喜你,你现在在时代广场! (你可以测试结果here。)

请注意,如果您想阻止网站从您的IP地址获取位置,则无法在应用层上执行此操作 - 唯一的方法是代理。

© www.soinside.com 2019 - 2024. All rights reserved.