我正在尝试通过CDP(铬调试协议)使用无头铬设置模拟地理位置,并为特定或所有站点范围授予“地理位置”权限。目前,我遇到了一些问题,即使在授予主机地理位置许可后,测试网站仍然说它正在提示用户进行访问,例如通过允许访问位置/通知等弹出窗口。
有人能告诉我它们是否是用于通过cdp设置模拟地理定位的命令顺序中的问题,或者它们是否还有其他阻止/启用此功能的无用问题chromedriver / chrome参数?
以下是我目前正在尝试的示例代码片段:({https://str8up.media/test.txt)
print "devtools setting up geoapi auths"
command = {
"id": 5,"method": "Browser.grantPermissions","params": {
"origin": 'https://browserleaks.com',"permissions": ["geolocation"]
}
}
ws.send(json.dumps(command))
result = ws.recv()
print "Received geoapi auths result'%s'" % result
print "devtools changing geoapi"
command = {
"id": 6,"method": "Page.setGeolocationOverride","params": {
"latitude": 27.1752868,"longitude": 78.040009,"accuracy": 100
}
}
ws.send(json.dumps(command))
result = ws.recv()
print "Received geolocation change result'%s'" % result
print "[!] devtools changing page..."
command = {
"id": 14,"method": "Page.navigate","params": {
"url": "https://browserleaks.com/geo","referrer": "http://finallyexamplereferer.com",}
}
ws.send(json.dumps(command))
result = ws.recv()
print "pagechange response: %s" % result
运行:
Linux 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64 GNU/Linux
ChromeDriver 80.0.3957.0 (60b069c753ac47f4d444b8ac1f08a22c32a131e1-refs/heads/master@{#711741})
Chromium 80.0.3957.0
在我努力使它起作用的过程中,任何帮助将不胜感激。
谢谢