如何使用Selenium设置chrome.privacy.network.WebRTChipHandlingPolicy的值

2024-10-03 00:30:20 发布

您现在位置:Python中文网/ 问答频道 /正文

有人知道如何使用硒铬驱动程序将chrome.privacy.network.webRTCIPHandlingPolicy的值设置为disable_non_proxied_udp

我不确定这是通过set_experimental_options还是set_desired_capabilities完成的


Tags: 驱动程序networkchromeprivacyoptionsudpdisablenon
2条回答

根据讨论disable_non_proxied_udp allows non-proxied TURN启用“防止WebRTC泄漏本地IP地址”chrome.privacy.network.webRTCIPHandlingPolicy设置为disable_non_proxied_udp

参数 force-webrtc-ip-handling-policy覆盖WebRTC IP处理策略,以模拟在首选项中指定WebRTC IP处理策略时的行为

因此,作为首选项,您需要将enforce-webrtc-ip-permission-check设置为True

因此,有效代码块:

  • Python:

    from selenium import webdriver
    
    options = webdriver.ChromeOptions() 
    options.add_experimental_option("prefs", { \
      "enforce-webrtc-ip-permission-check": True 
      })
    options.add_argument("force-webrtc-ip-handling-policy")
    driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://www.google.com/")
    
  • Java

    HashMap<String, Object> prefs = new HashMap<>();
    prefs.put("enforce-webrtc-ip-permission-check", true);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", prefs);
    options.addArguments("force-webrtc-ip-handling-policy"); 
    WebDriver driver =  new ChromeDriver(options); 
    driver.get("https://www.google.com/");
    
    preferences = {"webrtc.ip_handling_policy": "disable_non_proxied_udp", "webrtc.multiple_routes_enabled": False,
                   "webrtc.nonproxied_udp_enabled": False, "profile.managed_default_content_settings.images": 2}

    option.add_experimental_option("prefs", preferences)

相关问题 更多 >