5

I am trying to get headless Chrome to work while setting a user data dir using the following:

from selenium import webdriver

options = webdriver.ChromeOptions();
options.add_argument('--user-data-dir=./User_Data') 
options.add_argument('--headless')

browser = webdriver.Chrome(options=options)

This returns this error message:

selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

none of the following prevents this message from showing up (as suggested here: WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser)

options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
options.add_experimental_option("useAutomationExtension", False)

The only thing I could find that prevents this error from showing up is adding this argument:

options.add_argument('--remote-debugging-port=45447')

This at least starts up a headless Chrome, but still does not pick up the user dir specified, when running without the headless argument everything seems to be working as expected.

How do I get a headless chrome to use the user data dir?

  • Does this answer your question? [WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser](https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t) – bmcculley Jan 11 '20 at 18:05
  • 2
    none of the suggestions given help me out in this case unfortunately. Headless chrome runs fine without a the --user-data-dir argument, it is only when the argument is added that the error occurs – Jorrit Schulte Jan 11 '20 at 18:37
  • I have the same problem, it seems that this problem is a bug inside chrome driver. – Ali Akhtari Aug 28 '20 at 18:28
  • So it is not possible to run headless chrome with --user-data-dir argument, or with a specific profile? – user6133 Jan 26 '21 at 07:41

0 Answers0