Loading Browser Extensions
Install browser extensions in Selenium: Firefox installAddon, Chrome packed and unpacked extensions, the BiDi webExtension module, and the 4.50 removals.
There are two reasons to load an extension in a Selenium session. The first is that you are testing the extension: a password manager, an ad blocker, a developer tool, or a browser companion to your web app. The second is that an extension helps you test something else: an accessibility checker, a header modifier, or a corporate SSO helper the app depends on.
Either way, the mechanics have shifted over the last few Selenium releases. Profile-based Firefox extension loading is gone, Chrome has tightened its command-line switches, and WebDriver BiDi now provides a standard webExtension module that works the same way across browsers. This lesson covers all three routes and when to use each.
Extension Formats in Brief
| Format | Browser | What it is |
|---|---|---|
.crx | Chrome, Edge | Packed, signed Chromium extension |
| Unpacked directory | Chrome, Edge, Firefox (temporary) | Folder containing manifest.json and sources |
.xpi | Firefox | Zip archive of a WebExtension, signed for release Firefox |
.zip | All (via BiDi “archive path”) | Zipped extension directory |
For development and CI, an unpacked directory built by your extension’s build step is usually the most convenient input: no signing, no packaging step, and the same artefact can be loaded into Chromium and Firefox if the manifest is compatible.
Route 1: Firefox installAddon
Firefox drivers have a dedicated command to install an add-on into a running session. It accepts an .xpi file or (as a temporary add-on) an unpacked directory, and returns the add-on ID, which you need to uninstall it. The command is installAddon in JavaScript and Python (install_addon), installExtension in Java (via the HasExtensions interface), and InstallAddOnFromFile/InstallAddOnFromDirectory in C#. In Python (4.52) and JavaScript (4.51+), install_addon/installAddon are now deprecated in favour of the cross-browser install_web_extension/installWebExtension driver methods covered in Route 3; the old names still work but log a deprecation warning.
FirefoxDriver driver = new FirefoxDriver();
// Signed .xpi: permanent install for this session's profileString id = driver.installExtension(Path.of("extensions/my-extension.xpi"));
// Unsigned or unpacked: install as a temporary add-onString devId = driver.installExtension(Path.of("extensions/my-extension-dev"), true);
driver.uninstallExtension(devId);driver = webdriver.Firefox()
# Signed .xpi: permanent install for this session's profileaddon_id = driver.install_addon("extensions/my-extension.xpi")
# Unsigned or unpacked: install as a temporary add-ondev_id = driver.install_addon("extensions/my-extension-dev", temporary=True)
driver.uninstall_addon(dev_id)const driver = await new Builder().forBrowser('firefox').build();
// Signed .xpi: permanent install for this session's profileconst id = await driver.installAddon('extensions/my-extension.xpi');
// Unsigned or unpacked: install as a temporary add-onconst devId = await driver.installAddon('extensions/my-extension-dev', true);
await driver.uninstallAddon(devId);var driver = new FirefoxDriver();
// Signed .xpi: permanent install for this session's profilevar id = driver.InstallAddOnFromFile("extensions/my-extension.xpi");
// Unpacked directory: install as a temporary add-onvar devId = driver.InstallAddOnFromDirectory("extensions/my-extension-dev", true);
driver.UninstallAddOn(devId);Release builds of Firefox only accept signed extensions for permanent installation. Unsigned extensions must be installed with temporary set to true; temporary add-ons are removed when the browser closes, which is exactly what you want in a test. Firefox Developer Edition and Nightly can be configured to accept unsigned permanent installs, but you rarely need that for testing.
On Selenium Grid or with RemoteWebDriver, the Firefox-specific install method is not on the generic driver type. In Java you can wrap the remote driver with new Augmenter().augment(driver) and cast to HasExtensions; in other bindings, prefer the BiDi route below.
Note: Selenium 4.50 removed the deprecated Firefox profile methods for adding extensions (and certificates) from all bindings. Code like
profile.addExtension(...)orprofile.add_extension(...)that used to bake the add-on into aFirefoxProfilebefore startup no longer compiles or runs. Install extensions after startup with the methods above or with BiDiwebExtension.install.
Route 2: Chrome and Edge Options
Chromium browsers load extensions at startup, configured through Options.
Packed .crx files
addExtensions (Java/JavaScript), add_extension (Python) and AddExtension (C#) embed the .crx in the session capabilities. This works locally and on Grid, because the file content travels with the new-session request.
ChromeOptions options = new ChromeOptions();options.addExtensions(new File("extensions/my-extension.crx"));WebDriver driver = new ChromeDriver(options);options = webdriver.ChromeOptions()options.add_extension("extensions/my-extension.crx")driver = webdriver.Chrome(options=options)const chrome = require('selenium-webdriver/chrome');
const options = new chrome.Options().addExtensions('extensions/my-extension.crx');const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build();var options = new ChromeOptions();options.AddExtension("extensions/my-extension.crx");var driver = new ChromeDriver(options);Unpacked directories with —load-extension
The traditional way to load an unpacked extension is the --load-extension=/path/to/dir argument. Be aware of two limits:
- Branded Chrome no longer honours
--load-extensionin recent stable releases (the switch was disabled in Chrome 137 for security reasons). It still works in Chrome for Testing and Chromium builds. Selenium Manager can download Chrome for Testing for you, so this is usually a configuration change rather than an infrastructure one. - The path must exist on the machine running the browser. On Grid, a local path is useless unless it is mounted into the node.
ChromeOptions options = new ChromeOptions();options.setBrowserVersion("stable"); // Selenium Manager resolves Chrome for Testing if neededoptions.addArguments("--load-extension=" + Path.of("extensions/my-extension-dev").toAbsolutePath());WebDriver driver = new ChromeDriver(options);options = webdriver.ChromeOptions()options.browser_version = "stable"options.add_argument(f"--load-extension={os.path.abspath('extensions/my-extension-dev')}")driver = webdriver.Chrome(options=options)const options = new chrome.Options().setBrowserVersion('stable').addArguments('--load-extension=' + path.resolve('extensions/my-extension-dev'));const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build();var options = new ChromeOptions { BrowserVersion = "stable" };options.AddArgument("--load-extension=" + Path.GetFullPath("extensions/my-extension-dev"));var driver = new ChromeDriver(options);Whether Selenium Manager picks Chrome for Testing over an installed branded Chrome depends on what is installed locally and the version you request; see Selenium Manager. If you need a guarantee, point binary at a Chrome for Testing executable explicitly.
Headless and extensions
Old headless Chrome did not support extensions at all. The current headless mode (--headless, formerly --headless=new) runs the full browser and does load extensions, so CI runs are possible. Extension UI such as the toolbar popup is not rendered as browser chrome in headless mode, so test popup pages by opening their URL directly (see below).
Route 3: WebDriver BiDi webExtension
WebDriver BiDi defines a webExtension module with install and uninstall commands. It accepts an unpacked directory path, a zip archive path, or a base64-encoded archive, and it works in a running session, in Chromium and Firefox, through the same API. This is the direction the ecosystem is moving.
Binding support has been arriving release by release:
| Binding | BiDi webExtension install/uninstall |
|---|---|
| Java | Available (BiDi WebExtension module) |
| Python | driver.install_web_extension() since 4.52 (earlier: driver.webextension.install) |
| JavaScript | driver.installWebExtension() since 4.51 |
| Ruby | Since 4.50 |
| .NET | Via the .NET BiDi implementation; check the current API docs |
// Requires BiDi: options.enableBiDi()FirefoxOptions options = new FirefoxOptions();options.enableBiDi();WebDriver driver = new FirefoxDriver(options);
WebExtension webExtension = new WebExtension(driver);Map<String, Object> result = webExtension.install( new InstallExtensionParameters( new ExtensionPath(Path.of("extensions/my-extension-dev").toAbsolutePath().toString())));String extensionId = (String) result.get("extension");
// ... test ...
// UninstallExtensionParameters takes the result map returned by install()webExtension.uninstall(new UninstallExtensionParameters(result));options = webdriver.FirefoxOptions()options.enable_bidi = Truedriver = webdriver.Firefox(options=options)
# Selenium 4.52+: driver-level methods (older releases: driver.webextension.install(path=...))extension = driver.install_web_extension(os.path.abspath("extensions/my-extension-dev"))print(extension.id)
# ... test ...
driver.uninstall_web_extension(extension)// Selenium 4.51+: driver-level methods; Chromium also needs BiDi enabledconst options = new firefox.Options().enableBidi();const driver = await new Builder().forBrowser('firefox').setFirefoxOptions(options).build();
const extension = await driver.installWebExtension(path.resolve('extensions/my-extension-dev'));
// ... test ...
await driver.uninstallWebExtension(extension);The Java WebExtension classes live in org.openqa.selenium.bidi.webextension and are marked @Beta. Python’s install_web_extension (4.52) and JavaScript’s installWebExtension (4.51) accept an unpacked directory, a packed .xpi/.crx/.zip, or base64 bytes, upload directories to Grid automatically, and on Firefox fall back to the classic add-on endpoint when BiDi is off. Ruby (4.50+) and .NET expose equivalent install and uninstall commands with their own naming. Because these APIs are young, confirm the exact method names against the selenium.dev BiDi documentation for the version you pin rather than copying across bindings.
Chromium requirements for BiDi install
Chromium only allows webExtension.install when the browser was started with unsafe extension debugging enabled. In practice that means adding:
--enable-unsafe-extension-debuggingto the Chrome or Edge arguments (and, depending on the Chrome version, using a pipe-based remote debugging transport, which Selenium configures for you in recent releases). Without it, the install command returns an error. This flag only affects the automated browser instance; it is not something users have enabled.
Testing the Extension Itself
Once an extension is installed, you need to reach its pages: the popup, options page, or side panel. These live at extension URLs:
| Browser | URL pattern |
|---|---|
| Chrome / Edge | chrome-extension://<extension-id>/popup.html |
| Firefox | moz-extension://<internal-uuid>/popup.html |
In Chromium, the extension ID is derived from the extension’s key. If you set a fixed key in your development manifest.json, the ID is stable across runs, so tests can navigate directly to chrome-extension://<id>/options.html. In Firefox, the moz-extension:// UUID is randomised per profile; the add-on ID returned by installAddon is not the UUID. Read it from about:debugging#/runtime/this-firefox, or have the extension expose its own URL (for example, a test-only content script that writes browser.runtime.getURL('') into the page).
String extensionId = "abcdefghijklmnopabcdefghijklmnop"; // stable because manifest has a fixed "key"driver.get("chrome-extension://" + extensionId + "/options.html");
driver.findElement(By.id("api-endpoint")).sendKeys("https://staging.example.com");driver.findElement(By.id("save")).click();new WebDriverWait(driver, Duration.ofSeconds(5)) .until(ExpectedConditions.textToBe(By.id("status"), "Saved"));extension_id = "abcdefghijklmnopabcdefghijklmnop" # stable because manifest has a fixed "key"driver.get(f"chrome-extension://{extension_id}/options.html")
driver.find_element(By.ID, "api-endpoint").send_keys("https://staging.example.com")driver.find_element(By.ID, "save").click()WebDriverWait(driver, 5).until(EC.text_to_be_present_in_element((By.ID, "status"), "Saved"))const extensionId = 'abcdefghijklmnopabcdefghijklmnop'; // stable because manifest has a fixed "key"await driver.get('chrome-extension://' + extensionId + '/options.html');
await driver.findElement(By.id('api-endpoint')).sendKeys('https://staging.example.com');await driver.findElement(By.id('save')).click();await driver.wait(until.elementTextIs(driver.findElement(By.id('status')), 'Saved'), 5000);var extensionId = "abcdefghijklmnopabcdefghijklmnop"; // stable because manifest has a fixed "key"driver.Navigate().GoToUrl($"chrome-extension://{extensionId}/options.html");
driver.FindElement(By.Id("api-endpoint")).SendKeys("https://staging.example.com");driver.FindElement(By.Id("save")).Click();new WebDriverWait(driver, TimeSpan.FromSeconds(5)) .Until(d => d.FindElement(By.Id("status")).Text == "Saved");Some things WebDriver cannot do with extensions:
- Click the toolbar icon. Browser UI is outside the page, so WebDriver cannot reach it. Open the popup URL in a tab instead. The popup then runs as a normal page, which is fine for testing its logic, though some popup-specific behaviour (auto-closing on blur) will not reproduce.
- Interact with native permission prompts shown during install. Grant permissions in the manifest for test builds, or use
optional_permissionsflows that you trigger from extension pages. - Debug the service worker directly. Background service workers are not windows; use logging, or BiDi realms and script evaluation where supported.
Content scripts, on the other hand, are easy: they run inside normal web pages, so you test them by visiting a page and asserting on the DOM changes the extension makes.
Choosing a Route
| Situation | Use |
|---|---|
| Firefox, local or with a typed Firefox driver | installAddon (temporary for unsigned builds) |
Chrome/Edge, packed .crx, local or Grid | addExtensions in Options |
| Chrome/Edge, unpacked build output, local | --load-extension with Chrome for Testing |
| Same extension across Chrome and Firefox; installing mid-session | BiDi webExtension.install |
| Grid with unpacked extension | Package as .crx/zip and send it, or BiDi with a base64 archive |
Common Pitfalls
| Symptom | Cause | Fix |
|---|---|---|
| Extension silently not loaded in Chrome | --load-extension ignored by branded Chrome | Use Chrome for Testing, a .crx, or BiDi install |
| Firefox rejects the add-on | Unsigned extension, permanent install | Install with temporary set to true |
profile.addExtension no longer exists | Removed in 4.50 | Use installAddon or BiDi |
| BiDi install errors in Chrome | Missing --enable-unsafe-extension-debugging | Add the argument |
| Extension ID changes every run | No fixed key in the manifest (Chromium) | Add a development key |
| Path not found on Grid | Local path sent to remote node | Send file content (.crx, base64 archive) instead |
| SessionNotCreatedException at startup | Corrupt or mismatched .crx | Rebuild the package; check Chrome version compatibility |
Summary
- Firefox:
installAddonafter startup; unsigned extensions install as temporary add-ons. - Chrome/Edge:
.crxthrough Options works everywhere;--load-extensionneeds Chrome for Testing in recent versions. - BiDi
webExtension.installis the cross-browser, mid-session route, now available in Java, Python, JavaScript (4.51) and Ruby (4.50). - Selenium 4.50 removed the deprecated Firefox profile extension methods; migrate any code that used them.
- Test extension pages by navigating to their extension URL; the toolbar UI is out of WebDriver’s reach.
Finished this lesson?
Mark it complete to track your progress through the course. Saved in this browser only.