Implementation:SeleniumHQ Selenium HasExtensions
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Firefox_Browser |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
HasExtensions is a Beta interface that enables runtime installation and uninstallation of Firefox browser extensions during an active WebDriver session.
Description
The HasExtensions interface, annotated with @Beta, declares three methods for managing Firefox extensions at runtime without restarting the browser. The installExtension(Path) method installs an extension from an absolute file path and returns its unique identifier. An overloaded variant installExtension(Path, Boolean) allows installing an extension as temporary (it will be removed when Firefox closes). The uninstallExtension(String) method removes a previously installed extension using its unique identifier (typically ending with @mozilla.org, as found in the extension's manifest). This is a Firefox-specific capability that operates through the geckodriver/Marionette protocol and is not part of the standard W3C WebDriver specification.
Usage
Use HasExtensions when you need to dynamically install or remove Firefox extensions during a running test session, such as adding an ad blocker for specific test scenarios, installing a debugging extension on the fly, or testing extension behavior. Cast your FirefoxDriver instance to HasExtensions to access these methods.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/firefox/HasExtensions.java
Signature
@Beta
public interface HasExtensions {
String installExtension(Path path);
String installExtension(Path path, Boolean temporary);
void uninstallExtension(String extensionId);
}
Import
import org.openqa.selenium.firefox.HasExtensions;
I/O Contract
Methods
| Method | Input | Output | Description |
|---|---|---|---|
installExtension(Path) |
Path path - absolute path to the extension file (XPI or directory) |
String - the unique identifier of the installed extension |
Installs the extension permanently into the current Firefox session. |
installExtension(Path, Boolean) |
Path path - absolute path to the extension; Boolean temporary - whether the extension is temporary |
String - the unique identifier of the installed extension |
Installs the extension, optionally as temporary (removed when Firefox closes). |
uninstallExtension(String) |
String extensionId - the unique extension identifier (typically ending with @mozilla.org) |
void |
Uninstalls the specified extension from the running Firefox session. |
Parameters
| Parameter | Type | Description |
|---|---|---|
path |
java.nio.file.Path |
Absolute path to the extension file (.xpi) or unpacked extension directory to install. |
temporary |
Boolean |
If true, the extension is installed temporarily and removed when Firefox closes.
|
extensionId |
String |
The unique identifier of the extension to uninstall, as returned by installExtension().
|
Usage Examples
// Install an extension at runtime
FirefoxDriver driver = new FirefoxDriver();
HasExtensions extensionsDriver = (HasExtensions) driver;
// Install extension and get its ID
String extensionId = extensionsDriver.installExtension(
Path.of("/path/to/extension.xpi"));
System.out.println("Installed extension: " + extensionId);
// Later, uninstall the extension
extensionsDriver.uninstallExtension(extensionId);
// Install a temporary extension (removed when browser closes)
HasExtensions extensionsDriver = (HasExtensions) driver;
String extensionId = extensionsDriver.installExtension(
Path.of("/path/to/extension.xpi"), true);
// Install an unpacked extension directory
HasExtensions extensionsDriver = (HasExtensions) driver;
String extensionId = extensionsDriver.installExtension(
Path.of("/path/to/unpacked-extension-dir"));
Related Pages
- FirefoxDriver - Implements
HasExtensionsfor runtime extension management - ClasspathExtension - Installs extensions from the classpath at profile creation time
- FirefoxProfile - Pre-session extension management via profile configuration
- HasContext - Another Firefox-specific capability interface
- HasFullPageScreenshot - Another Firefox-specific capability interface