0
# Profile Management
1
2
Firefox user profile creation, customization, and management including preferences, extensions, and certificate handling. The FirefoxProfile class provides comprehensive control over Firefox user data and behavior.
3
4
## Capabilities
5
6
### FirefoxProfile Class
7
8
Represents a Firefox user profile for customization and persistence of browser settings.
9
10
```java { .api }
11
/**
12
* Represents a Firefox user profile for customization.
13
* Manages preferences, extensions, certificates, and user data.
14
*/
15
public class FirefoxProfile {
16
17
/**
18
* Creates a new Firefox profile with default settings.
19
*/
20
public FirefoxProfile();
21
22
/**
23
* Creates a Firefox profile from an existing profile directory.
24
* @param profileDir Existing Firefox profile directory
25
*/
26
public FirefoxProfile(File profileDir);
27
}
28
```
29
30
**Usage Examples:**
31
32
```java
33
import org.openqa.selenium.firefox.FirefoxProfile;
34
import java.io.File;
35
36
// Create new profile
37
FirefoxProfile profile = new FirefoxProfile();
38
39
// Load existing profile
40
File existingProfile = new File("/path/to/firefox/profile");
41
FirefoxProfile profile = new FirefoxProfile(existingProfile);
42
```
43
44
### JSON Profile Creation
45
46
Creates profile instances from JSON representation for serialization scenarios.
47
48
```java { .api }
49
/**
50
* Creates a FirefoxProfile from JSON string representation.
51
* @param json JSON string containing profile configuration
52
* @return FirefoxProfile instance created from JSON
53
*/
54
public static FirefoxProfile fromJson(String json);
55
```
56
57
### Preference Management
58
59
Gets and sets Firefox preferences with type-safe accessors.
60
61
```java { .api }
62
/**
63
* Gets a string preference value.
64
* @param key Preference name
65
* @param defaultValue Default value if preference not set
66
* @return String preference value or default
67
*/
68
public String getStringPreference(String key, String defaultValue);
69
70
/**
71
* Gets an integer preference value.
72
* @param key Preference name
73
* @param defaultValue Default value if preference not set
74
* @return Integer preference value or default
75
*/
76
public int getIntegerPreference(String key, int defaultValue);
77
78
/**
79
* Gets a boolean preference value.
80
* @param key Preference name
81
* @param defaultValue Default value if preference not set
82
* @return Boolean preference value or default
83
*/
84
public boolean getBooleanPreference(String key, boolean defaultValue);
85
86
/**
87
* Sets a Firefox preference value.
88
* @param key Preference name (about:config key)
89
* @param value Preference value (String, Integer, Boolean)
90
*/
91
public void setPreference(String key, Object value);
92
```
93
94
**Usage Examples:**
95
96
```java
97
FirefoxProfile profile = new FirefoxProfile();
98
99
// Set various preference types
100
profile.setPreference("browser.startup.page", 1); // Integer
101
profile.setPreference("browser.startup.homepage", "https://example.com"); // String
102
profile.setPreference("dom.webnotifications.enabled", false); // Boolean
103
104
// Get preferences with defaults
105
String homepage = profile.getStringPreference("browser.startup.homepage", "about:blank");
106
int startupPage = profile.getIntegerPreference("browser.startup.page", 0);
107
boolean notifications = profile.getBooleanPreference("dom.webnotifications.enabled", true);
108
```
109
110
### Extension Management
111
112
Manages Firefox extensions including installation from various sources.
113
114
```java { .api }
115
/**
116
* Checks if the profile contains the WebDriver extension.
117
* @return true if WebDriver extension is present
118
*/
119
public boolean containsWebDriverExtension();
120
121
/**
122
* Adds an extension from the classpath.
123
* @param loadResourcesUsing Class to use for resource loading
124
* @param loadFrom Classpath location of extension
125
*/
126
public void addExtension(Class<?> loadResourcesUsing, String loadFrom);
127
128
/**
129
* Adds an extension from a file.
130
* @param extensionToInstall Extension file (.xpi or directory)
131
*/
132
public void addExtension(File extensionToInstall);
133
134
/**
135
* Adds an extension with a specific key.
136
* @param key Extension identifier key
137
* @param extension Extension implementation
138
*/
139
public void addExtension(String key, Extension extension);
140
```
141
142
**Usage Examples:**
143
144
```java
145
FirefoxProfile profile = new FirefoxProfile();
146
147
// Add extension from file
148
File extensionFile = new File("/path/to/extension.xpi");
149
profile.addExtension(extensionFile);
150
151
// Add extension from classpath
152
profile.addExtension(MyClass.class, "/extensions/my-extension");
153
154
// Check for WebDriver extension
155
if (profile.containsWebDriverExtension()) {
156
System.out.println("WebDriver extension is installed");
157
}
158
```
159
160
### User Preferences File Management
161
162
Updates Firefox user preferences files directly.
163
164
```java { .api }
165
/**
166
* Updates user preferences file with current profile settings.
167
* @param userPrefs Target user.js or prefs.js file
168
*/
169
public void updateUserPrefs(File userPrefs);
170
```
171
172
### Cache and Cleanup Management
173
174
Manages Firefox cache and temporary files.
175
176
```java { .api }
177
/**
178
* Deletes extensions cache if it exists in the profile directory.
179
* @param profileDir Profile directory to clean
180
*/
181
public void deleteExtensionsCacheIfItExists(File profileDir);
182
183
/**
184
* Cleans the specified profile directory.
185
* @param profileDir Profile directory to clean
186
*/
187
public void clean(File profileDir);
188
189
/**
190
* Cleans temporary model files.
191
*/
192
public void cleanTemporaryModel();
193
```
194
195
### Focus Library Configuration
196
197
Configures no-focus library loading for headless operation.
198
199
```java { .api }
200
/**
201
* Returns whether the no-focus library should be loaded.
202
* @return true if no-focus library should be loaded
203
*/
204
public boolean shouldLoadNoFocusLib();
205
206
/**
207
* Sets whether to always load the no-focus library.
208
* @param loadNoFocusLib true to always load no-focus library
209
*/
210
public void setAlwaysLoadNoFocusLib(boolean loadNoFocusLib);
211
```
212
213
### Certificate Management
214
215
Configures SSL certificate handling behavior.
216
217
```java { .api }
218
/**
219
* Sets whether to accept untrusted SSL certificates.
220
* @param acceptUntrustedSsl true to accept untrusted certificates
221
*/
222
public void setAcceptUntrustedCertificates(boolean acceptUntrustedSsl);
223
224
/**
225
* Sets whether to assume untrusted certificate issuers are acceptable.
226
* @param untrustedIssuer true to assume untrusted issuers are acceptable
227
*/
228
public void setAssumeUntrustedCertificateIssuer(boolean untrustedIssuer);
229
```
230
231
### Profile Persistence
232
233
Writes the profile to disk for persistence and reuse.
234
235
```java { .api }
236
/**
237
* Writes the profile to disk and returns the directory location.
238
* Creates a temporary directory if no existing directory is set.
239
* @return File representing the profile directory on disk
240
*/
241
public File layoutOnDisk();
242
```
243
244
**Complete Profile Configuration Example:**
245
246
```java
247
import org.openqa.selenium.firefox.FirefoxProfile;
248
import org.openqa.selenium.firefox.FirefoxOptions;
249
import java.io.File;
250
251
// Create and configure a comprehensive Firefox profile
252
FirefoxProfile profile = new FirefoxProfile();
253
254
// Set browser preferences
255
profile.setPreference("browser.startup.page", 0);
256
profile.setPreference("browser.startup.homepage", "about:blank");
257
profile.setPreference("browser.cache.disk.enable", false);
258
profile.setPreference("browser.cache.memory.enable", false);
259
profile.setPreference("dom.webnotifications.enabled", false);
260
profile.setPreference("media.navigator.permission.disabled", true);
261
262
// Download preferences
263
profile.setPreference("browser.download.folderList", 2);
264
profile.setPreference("browser.download.dir", "/tmp/downloads");
265
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
266
"application/pdf,application/zip,text/csv");
267
268
// Security preferences
269
profile.setAcceptUntrustedCertificates(true);
270
profile.setAssumeUntrustedCertificateIssuer(false);
271
272
// Add extensions
273
File extensionFile = new File("/path/to/extension.xpi");
274
profile.addExtension(extensionFile);
275
276
// Configure for headless operation
277
profile.setAlwaysLoadNoFocusLib(true);
278
279
// Write profile to disk
280
File profileDir = profile.layoutOnDisk();
281
System.out.println("Profile created at: " + profileDir.getAbsolutePath());
282
283
// Use with FirefoxOptions
284
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
285
WebDriver driver = new FirefoxDriver(options);
286
```