Skip to content

Block Image Loading in Selenium

Disabling images before a Selenium session starts can reduce unnecessary downloads and help text-focused scraping finish with less browser work.

OUTPUT FORMATSHTMLJSONMarkdown

The approach differs by browser: Chrome receives a content-setting preference through ChromeOptions, while Firefox receives an image permission through FirefoxOptions.

Chrome: set the preference before creating the driver

For Chrome, build a ChromeOptions object, add a preferences dictionary that sets the managed default content setting for images to block, and pass those options when creating the Chrome driver. The driver path is supplied separately in the accompanying Chrome module, code0001. The important sequence is options first, driver second, navigation last.

Firefox: use its own image permission

Firefox uses a different options object and preference name. Create FirefoxOptions, set the default image permission to block, and pass the options when creating the Firefox driver. The accompanying Firefox module is code0002. Do not copy the Chrome preference key into Firefox, because the two browsers expose the control under different names.

Quick setup check

Use this checklist when deciding whether the setup is correct: the options object exists before the driver is created; the image preference is added to that object; the driver constructor receives the options; and navigation happens only after the driver starts. If images still appear, check that the browser-specific module was used rather than mixing Chrome and Firefox settings.

When this helps

Blocking images is most useful when the data you need comes from text, links, forms, or structured page content rather than image files. It will not remove image elements from the page structure, and it is not a substitute for waiting for dynamic content when the information you need loads after the initial page render.

Frequently asked questions

Where does the image-blocking setting belong?

Create the browser-specific options object before starting the driver, add the image-blocking preference to it, and pass that object when the driver is constructed. The Chrome example is protected module code0001 and the Firefox example is protected module code0002.

Do I apply the setting after opening a page?

No. The setting is applied through browser options before navigation, so it is part of driver setup rather than a page interaction after the page has loaded.