Reputation: 19215
Is there a way to enable the "Do not track" option for selenium using chromedriver?
None of the command line switches seem to help and this website says that the option is disabled when run with chromedriver even though my regular Chrome profile has it turned on. I want to use a temporary profile and not load my existing one though.
Suggestions? Can the option be set automatically?
Upvotes: 2
Views: 2478
Reputation: 189
@pynterest's answer above works in Python. For those of you who wish to confirm this try:
options = webdriver.ChromeOptions()
no_track = {"enable_do_not_track": True}
options.add_experimental_option("prefs", no_track)
b = webdriver.Chrome(options=options)
b.get('https://www.whatismybrowser.com/detect/is-do-not-track-enabled')
Which should open up a selenium browser telling you that Do Not Track is enabled.
Upvotes: 0
Reputation: 61
For those working with the Python, we were able to follow the Java answer above and do the following:
options = webdriver.ChromeOptions()
prefs = {"enable_do_not_track": True}
options.add_experimental_option("prefs", prefs)
Upvotes: 3
Reputation: 19215
I figured it out. It can be done by setting the preferences from the Chrome preferences file like this:
Map<String, Object> preferences = new HashMap<String, Object>();
ChromeOptions options = new ChromeOptions();
preferences.put("enable_do_not_track", true);
options.setExperimentalOption("prefs", preferences);
Upvotes: 3