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?

4
  • Does this answer your question? WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser Commented Jan 11, 2020 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 Commented Jan 11, 2020 at 18:37
  • I have the same problem, it seems that this problem is a bug inside chrome driver. Commented Aug 28, 2020 at 18:28
  • So it is not possible to run headless chrome with --user-data-dir argument, or with a specific profile? Commented Jan 26, 2021 at 7:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.