Disabling PDF Viewer plugin in chromedriver
Solution 1
Ari's answer was almost working properly. I only needed to encapsulate the plugin's name into a list:
chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : ["Chrome PDF Viewer"]} # Here should be a list
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)
The downloading now works just fine!
Solution 2
Chrome 57 change the setting... use this to disable Chrome PDF viewer:
//To disable PDF viewer plugins with Chrome 57
chromePrefs.put("plugins.always_open_pdf_externally", true);
Solution 3
Can you set the plugin to be disable as a preference?
chromeOptions = webdriver.ChromeOptions()
prefs = {"plugins.plugins_disabled" : "Chrome PDF Viewer"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "path/to/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)
See "setting Chrome preferences w/ Selenium Webdriver in Python" and "How to disable Chrome Plugins in Selenium WebDriver using Java".
Willem van Opstal
Updated on June 05, 2022Comments
-
Willem van Opstal almost 2 years
I'm trying to batch-download a lot of files within the BlackBoard environment (used a lot on universities/schools around the world). I am able to retrieve the links where the files are but one mayor issue:
When the file is a .pdf-file, it is shown in a new browser-tab in stead of being downloaded. For e.g. .xlsx-files downloading with a click() works just fine..
Can I change the driversettings to change this behaviour? And how?
Edit
I updated the question in reaction to Ari's answer. It's now including more info on the actual plugin. Maybe that's usable to identify the plugin which has to be disabled..Chrome PDF Viewer (2 files) Name: Chrome PDF Viewer Version: Location: chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/ Type: BROWSER PLUGIN Disable MIME types: MIME type Description File extensions application/pdf .pdf Name: Chrome PDF Viewer Description: Portable Document Format Version: Location: internal-pdf-viewer Type: PPAPI (out-of-process) Disable MIME types: MIME type Description File extensions application/x-google-chrome-pdf Portable Document Format .pdf
-
Willem van Opstal over 7 yearsThanks, but not working for me.. It doesn't disable the plugin when I check it. I updated the question, it's now including more info on the actual plugin. Maybe thats usable to identify the plugin which has to be disabled..
-
Ari Cooper-Davis over 7 yearsWeird, glad you got it working, and you've taught me something about chromedriver! :)
-
GuiTeK about 7 yearsIndeed,
'plugins.plugins_disabled': ["Chrome PDF Viewer"],
doesn't work anymore (since Chrome 57)! Thank you, you have the right solution! How did you find that? -
Ross Smith II about 7 yearsIn Python, use:
chrome_options = webdriver.ChromeOptions(); chrome_options.add_experimental_option("prefs", {"download.prompt_for_download": False, "plugins.always_open_pdf_externally": True})
-
Martin Thoma almost 7 yearsThis seems not to work anymore. See gist.github.com/MartinThoma/8b55b296375f83cbe4b70179930e70bd as an example.
-
Martin Thoma almost 7 years
-
prrao about 6 yearsMost recently solved with this command:
prefs = {"plugins.always_open_pdf_externally": True}
-
Sariq Shaikh almost 6 yearsIn Robotframework, use:
${prefs} Create Dictionary download.default_directory ${CURDIR} plugins.always_open_pdf_externally ${TRUE}
Note the usage ofCreate Dictionary
and${TRUE}