Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Selenium Chrome driver - Disable image loading

I am trying to run chrome driver without loading any images for obvious reasons.

i found a piece of code online but i think it's outdated

HashMap<String, Object> images = new HashMap<String, Object>(); 
images.put("images", 2); 

HashMap<String, Object> prefs = new HashMap<String, Object>(); 
prefs.put("profile.default_content_settings", images); 

ChromeOptions options =new ChromeOptions(); 
options.setExperimentalOption("prefs", prefs); 

DesiredCapabilities chromeCaps = DesiredCapabilities.chrome(); 
chromeCaps.setCapability(ChromeOptions.CAPABILITY, options); 

driver = new ChromeDriver(chromeCaps);

does not work at all..

any help would be greatly appriciated

like image 930
zvikachu Avatar asked Dec 07 '25 08:12

zvikachu


1 Answers

If you're running the headless mode, you can try

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--blink-settings=imagesEnabled=false");
WebDriver driver = new ChromeDriver(options);

Alternatively, you can create a new chrome profile. Disable images by accessing chrome://settings/content on the new profile. Then add the new profile to your chromeDriver options. More info here.

like image 50
Ercross Avatar answered Dec 08 '25 20:12

Ercross