How to integrate browser addons with headless testing frameworks

I’m trying to figure out if it’s possible to use browser addons while running automated tests with headless browsers like Selenium or PhantomJS. My main goal is to test how my website behaves when users have ad blocking extensions installed, such as uBlock Origin or AdBlock Pro.

I want to make sure that these popular extensions don’t interfere with my site’s functionality or cause any unexpected issues. The problem is that most headless testing environments seem to run without any extensions by default.

I know that PhantomJS dropped support for certain plugins a while back, but I’m wondering if there are alternative approaches or workarounds to achieve this kind of testing. Has anyone successfully managed to load browser extensions in their headless testing setup?

Selenium WebDriver handles extension loading pretty well for both Chrome and Firefox. With Chrome, just create a ChromeOptions object and use add_extension() to load your .crx files. I’ve done this in my CI pipeline for testing with uBlock Origin. The tricky part is getting the extension files - you’ll need to download them from the Chrome Web Store or build from source. Firefox works similarly with FirefoxProfile, but I’ve found Chrome more reliable. One heads up: some extensions need user interaction during install, so you might have to handle those dialogs programmatically or use pre-configured profiles.

yeah, phantomjs is pretty much abandoned. headless chrome with puppeteer is def the way to go. you can use --load-extension to add your extensions. i’ve been runnin tests with adblockers on it - works great with no hiccups!

I made this exact switch from PhantomJS to headless Firefox about two years ago. Here’s what worked for me: don’t try installing extensions during test runs - it’s a nightmare. Instead, create a regular Firefox profile first, install your extensions (like uBlock Origin) manually, set them up how you want, then copy that whole profile folder to your test environment. Point your WebDriver to this profile using the FirefoxProfile class. This saved me tons of debugging headaches. Firefox vs Chrome performance? Barely noticeable. But reliability went way up. Just keep your extension versions synced with what real users actually have.