Implementing Download Restrictions on Selenium Chromedriver
DownloadRestrictions

Allow download restrictions
Supported on:
- Google Chrome (Linux, Mac, Windows) since version 61
- Google Chrome OS (Google Chrome OS) since version 61
Description:
Setting the policy means users can’t bypass download security decisions.
Setting the policy to:
* Block dangerous downloads means all downloads are allowed, except for those that carry safety warnings.
* Block potentially dangerous downloads means all downloads allowed, except for those that carry safety warnings of potentially dangerous downloads.
* Block all downloads means all downloads are blocked.
* Block malicious downloads means all downloads are allowed, except for those assessed to be malware with high confidence. Unlike with dangerous downloads, this does not take into account file type, but does take into account the host.
* No special restrictions means the downloads go through the usual security restrictions based on safety analysis results.
- 0 = No special restrictions
- 1 = Block dangerous downloads
- 2 = Block potentially dangerous downloads
- 3 = Block all downloads
- 4 = Block malicious downloads
How to implement it on Selenium:
Code:
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
prefs.put("download_restrictions", 3);
options.setExperimentalOption("prefs", prefs); WebDriver driver = new ChromeDriver(options);
Note: These restrictions apply to downloads triggered from webpage content, as well as the Download link… menu option. They don’t apply to the download of the currently displayed page or to saving as PDF from the printing options. Read more about Safe Browsing ( https://developers.google.com/safe-browsing ).