headless=new breaks DevTools Chrome/Driver 1.22

98 views
Skip to first unread message

Philip Smith

unread,
Mar 8, 2024, 6:53:55 AM3/8/24
to Selenium Users
I'm using the following config with Chrome/ChromeDriver 1.22.

I'm using docker containers. All works however if I'm using '--headless=new' then DevTools no longer works, but file downloads do.

If I use '--headless', file downloads fail but DevTools works - no other changes are being made.

My function that works is below, showing the '--headless=new' setting which means that I get the files downloaded to '/var/tmp/'.

    def start_driver(self):
        logging.info('Configuring Driver')
        # Set up the options for the browser
        chrome_options = webdriver.ChromeOptions()
        prefs = {
            "profile.default_content_setting_values.notifications": 2,
            "download.default_directory": "/var/tmp/",
            "download.prompt_for_download": False,
            "download.directory_upgrade": True,
        }
        service = webdriver.ChromeService(
            # log_output=subprocess.STDOUT,
            log_output='/var/tmp/webservice.log',
            service_args=['--log-level=INFO']
        )
        cloud_options = {}
        cloud_options['goog:loggingPrefs'] = {'browser': 'ALL'}
        chrome_options.add_experimental_option("prefs", prefs)
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument('--headless=new')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument("--remote-debugging-address=0.0.0.0")
        chrome_options.add_argument("--remote-debugging-port=9222")
        chrome_options.add_argument('--disable-notifications')
        chrome_options.add_argument('--use-fake-ui-for-media-stream')
        chrome_options.add_argument('--use-fake-device-for-media-stream')
        # chrome_options.add_argument('--log-path=/var/tmp/chrome.log')
        chrome_options.add_argument('--user-data-dir=/var/tmp/chrome')
        chrome_options.add_argument('--log-format=json')
        chrome_options.add_argument('--log-level=0')
        chrome_options.add_argument('--enable-logging')
        chrome_options.add_argument('--v=1')
        chrome_options.set_capability('cloud:options', cloud_options)
        # chrome_options.binary_location = '/usr/bin/google-chrome'
        try:
            self.driver = webdriver.Chrome(
                options=chrome_options, service=service)
            # options=chrome_options)
            logging.info('Driver configured.')
        except Exception as e:
            logging.error('Driver Configuration Failed.')
            logging.error(e)


Reply all
Reply to author
Forward
0 new messages