How to Set Up Adblock Plus with EasyList in Selenium Firefox Webdriver Using Python
When automating web browsers with Selenium, ads can be a major annoyance. They slow down page loads, clutter the UI, and may even break test workflows by triggering unexpected pop-ups or dynamic content. To mitigate this, integrating an ad blocker like Adblock Plus with EasyList (the most popular ad-filtering list) into your Selenium Firefox setup is a game-changer.
This guide will walk you through every step to configure Adblock Plus with EasyList in Selenium’s Firefox WebDriver using Python. By the end, you’ll have a browser instance that automatically blocks ads, ensuring faster, cleaner, and more reliable automation.
Before starting, ensure you have the following installed/configured:
Python: Version 3.6 or higher. Download from python.org.
Selenium: The Python package for browser automation. Install via pip:
pip install selenium
Mozilla Firefox: The browser itself. Download from firefox.com.
Geckodriver: Firefox’s WebDriver executable. Download the latest version from GitHub and add it to your system’s PATH (or specify its path in your script).
A Code Editor: (Optional but recommended) VS Code, PyCharm, or any editor to write/run Python scripts.
Adblock Plus: A popular browser extension that blocks ads, pop-ups, and trackers. It works by applying filter lists to identify and block ad content.
EasyList: The default and most widely used filter list for Adblock Plus. It contains rules to block ads on thousands of websites, including banners, video ads, and sponsored content. Adblock Plus ships with EasyList pre-enabled, so no extra setup is needed for the list itself—just ensure the extension is installed!
Click Add to Firefox → A pop-up will ask for confirmation. Instead of installing directly, right-click the Add button and select Copy Link Address (or similar, depending on your browser).
The copied link will point to the latest Adblock Plus XPI file (e.g., https://addons.mozilla.org/firefox/downloads/file/XXXX/adblock_plus-XXX.xpi).
Download the XPI file using wget (terminal) or a browser:
Save it to a directory accessible by your Python script (e.g., ./extensions/adblock_plus.xpi).
Step 2: Set Up a Firefox Profile with Adblock Plus#
Firefox uses profiles to store settings, extensions, and user data. To load Adblock Plus in Selenium, we’ll create a custom profile and add the extension to it.
Open Firefox normally and type about:profiles in the address bar.
Click Create a New Profile and follow the prompts to name it (e.g., selenium_adblock_profile). Note the Root Directory path (you’ll need this later).
Alternatively: Let Selenium Create a Temporary Profile#
For automation, Selenium can generate a temporary profile on the fly. This avoids cluttering your system with permanent profiles. We’ll use this approach in the script below.
Step 3: Verify Adblock Plus and EasyList Installation#
Before writing the full script, let’s confirm Adblock Plus loads correctly and uses EasyList.
from selenium import webdriver from selenium.webdriver.firefox.service import Service from selenium.webdriver.firefox.options import Options import time # ---------------------- # Configuration # ---------------------- ADBLOCK_XPI_PATH = "./extensions/adblock_plus.xpi" # Path to your downloaded XPI GECKODRIVER_PATH = "/path/to/geckodriver" # Update this to your geckodriver path TEST_URL = "https://www.cnn.com" # URL to test ad blocking # ---------------------- # Set Up Firefox Profile # ---------------------- # Create a temporary Firefox profile (no need for manual setup) firefox_profile = webdriver.FirefoxProfile() # Add Adblock Plus extension to the profile try: firefox_profile.add_extension(extension=ADBLOCK_XPI_PATH) print("Adblock Plus extension added successfully!") except Exception as e: print(f"Failed to add Adblock Plus: {e}") exit(1) # Optional: Disable Firefox notifications/pop-ups (reduces distractions) firefox_profile.set_preference("dom.webnotifications.enabled", False) firefox_profile.set_preference("dom.push.enabled", False) # ---------------------- # Initialize Firefox Driver # ---------------------- # Configure geckodriver service service = Service(executable_path=GECKODRIVER_PATH) # Start Firefox with the custom profile driver = webdriver.Firefox( service=service, firefox_profile=firefox_profile ) # ---------------------- # Test Ad Blocking # ---------------------- driver.get(TEST_URL) print(f"Loaded: {driver.title}") # Wait for page to load (adjust based on the site) time.sleep(5) # Optional: Take a screenshot to verify (saves to current directory) driver.save_screenshot("adblock_test_screenshot.png") print("Screenshot saved as 'adblock_test_screenshot.png'") # ---------------------- # Cleanup # ---------------------- # Keep the browser open for manual verification (remove in production) input("Press Enter to close the browser...") driver.quit()
Open adblock_test_screenshot.png and check for missing ads (e.g., banner ads, video ads).
Manually navigate to about:addons in the Selenium-controlled Firefox window. Select Adblock Plus → Options → Confirm "EasyList" is listed under "Filter Lists" and enabled.
By following this guide, you’ve integrated Adblock Plus with EasyList into your Selenium Firefox setup. This ensures faster page loads, cleaner automation workflows, and fewer interruptions from ads.
Whether you’re running UI tests, web scraping, or browser automation, an ad-free environment will make your scripts more reliable and efficient.