I managed to enable the download via headless chrome with the following code:
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}
command_result = driver.execute("send_command", params)
But I was unable to download pdf files, even though I used this as preferences when running chrome:
options = Options()
profile = {"plugins.plugins_list": [{"enabled": False, "name": "Chrome PDF Viewer"}], # Disable Chrome's PDF Viewer
"profile.default_content_settings.popups": 0, # Disable download file dialog
"download.default_directory": download_dir,
"download.prompt_for_download": False, # To auto download the file
"download.extensions_to_open": "applications/pdf",
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True, # It will not show PDF directly in chrome
"safebrowsing.enabled": False,
"safebrowsing.disable_download_protection": True
}
options.add_experimental_option('prefs', profile)
So my problem now is to download pdf files :(