Search code examples
pythonseleniumselenium-webdriverdnswebdriver

How to modify selenium webdriver dns to custom one


so for some reason my webdriver session does not able to enter some website that on my normal browser I can, I receive DNS_PROBE_FINISHED_NXDOMAIN error.

I tried manually change the DNS provider to CloudFlare (1.1.1.1)

enter image description here

and then it worked, how can I make the webdriver be loaded with that settings?

I tried the following code snipper

chrome_options = options.Options()
local_state = {
    "dns_over_https.mode": "automatic",
    "dns_over_https.templates": "1.1.1.1",
}
chrome_options.add_experimental_option('localState', local_state)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)

And few more variations, can't find anything on google nor here.

Any help would be appriciated.


Solution

  • Get it work with:

    #!/usr/bin/env python
    
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    
    local_state = {
        "dns_over_https.mode": "secure",
    #   "dns_over_https.templates": "https://dns.google/dns-query{?dns}",
        "dns_over_https.templates": "https://chrome.cloudflare-dns.com/dns-query",
    }
    options = Options()
    options.add_experimental_option('localState', local_state)
    driver = webdriver.Chrome(options=options)
    driver.get('chrome://settings/security')
    driver.get('https://1.1.1.1/help')
    
    input("Press Enter to continue...")
    

    dns_over_https.templates is not well documented.

    Please take a look at the source code.