Can not disable image loading with preference profile.managed_default_content_settings.images set to

608 views
Skip to first unread message

dahua zeng

unread,
Jun 7, 2019, 4:24:53 PM6/7/19
to Selenium Users

I am trying to disable image loading with chrome preferences. here is my code:

from selenium.webdriver import Remote
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--allow-running-insecure-content')
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs",prefs)
# Note: '127.0.0.1:8888 is my Charles proxy.
chrome_options.add_argument('--proxy-server=http://127.0.0.1:8888')

driver = Remote(
    command_executor='http://127.0.0.1:4444/wd/hub',
    desired_capabilities=chrome_options.to_capabilities())
driver.get('https://www.google.com')

I am expecting the driver load no image on the site. But it does (from what I can see in Charles).

In the container, I can find the Preferences file with the path /tmp/.org.chromium.Chromium.xxxxxx/Default/Preferences:

{"alternate_error_pages":{"enabled":false},"autofill":{"enabled":false},"browser":{"check_default_browser":false},"distribution":{"import_bookmarks":false,"import_history":false,"import_search_engine":false,"make_chrome_default_for_user":false,"skip_first_run_ui":true},"dns_prefetching":{"enabled":false},"profile":{"content_settings":{"pattern_pairs":{"https://*,*":{"media-stream":{"audio":"Default","video":"Default"}}}},"default_content_setting_values":{"geolocation":1},"default_content_settings":{"geolocation":1,"mouselock":1,"notifications":1,"popups":1,"ppapi-broker":1},"managed_default_content_settings":{"images":2},"password_manager_enabled":false},"safebrowsing":{"enabled":false},"search":{"suggest_enabled":false},"translate":{"enabled":false}}

It looks like to me that the experimental_option does not work because the browser does not read the Preferences file correctly

Any Ideas?

I am using the latest docker image selenium/standalone-chrome, and run the image as suggested in the documents


John Doe

unread,
Jun 10, 2019, 6:43:35 AM6/10/19
to Selenium Users
Your setup should be fine, at least I fail to see any images in headless or normal modes. 

Alternatively you can try installing Block Image Chrome Extension

chrome_options.add_extension("Block-image_v1.1.crx")


Reply all
Reply to author
Forward
0 new messages