我正在通过命令行启动 Firefox,我想使用代理启动特定的 Firefox 配置文件。根据Stackoverflow 上的这个答案,Firefox 代理设置存储在pref.jsFirefox Profile 文件夹中,需要编辑此文件以使用代理启动 FF。
我已编辑该文件如下:
user_pref("network.proxy.ftp", "1.0.0.1");
user_pref("network.proxy.ftp_port", 00000);
user_pref("network.proxy.gopher", "1.0.0.1");
user_pref("network.proxy.gopher_port", 00000);
user_pref("network.proxy.http", "1.0.0.1");
user_pref("network.proxy.http_port", 22222);
user_pref("network.proxy.no_proxies_on", "localhost, 1.0.0.1");
user_pref("network.proxy.socks", "1.0.0.1");
user_pref("network.proxy.socks_port", 00000);
user_pref("network.proxy.ssl", "1.0.0.1");
user_pref("network.proxy.ssl_port", 00000);
user_pref("network.proxy.type", 1);
Run Code Online (Sandbox Code Playgroud)
注意:上面使用的 IP 地址和端口仅用于演示目的。
但是,我遇到了两个问题:
1) Firefox 完全忽略这些设置并在没有任何代理的情况下启动 FF
2)当 Firefox 退出时,文本修改被还原/删除
注意:当我编辑上面的文本文件时,Firefox 没有运行。我知道顶部有一个免责声明prefs.js:
如果在应用程序运行时更改此文件,则应用程序退出时更改将被覆盖。
但是在我编辑上述文件时没有运行 Firefox 的实时实例。
使用不同的代理手动创建不同的 FF 配置文件(如另一个用户的建议)不是一种选择,因为一切都需要以编程方式完成,无需手动干预。
Firefox 是否仍然支持通过 链接代理pref.js?如果没有,通过命令行使用 Java 代理启动 Firefox 的当前工作解决方案是什么?
谢谢
我正在使用Geckodriver运行最新版本的Selenium WebDriver。我想阻止Selenium在启动WebDriver的新实例时在临时文件目录中创建临时 Firefox 配置文件。相反,我想直接使用原始的 Firefox 配置文件。这有双重好处。首先,它节省了时间(将配置文件复制到临时目录需要花费大量时间)。其次,它确保在会话期间创建的 cookie 保存到原始配置文件中。之前硒开始依赖Geckodriver我能解决这个问题,通过编辑类中,如下图所示:FirefoxProfile.classSeleniumHQ
public File layoutOnDisk() {
File profileDir;
if (this.disableTempProfileCreation) {
profileDir = this.model;
return profileDir;
} else {
try {
profileDir = TemporaryFilesystem.getDefaultTmpFS().createTempDir("ABC", "XYZ");
File userPrefs = new File(profileDir, "user.js");
this.copyModel(this.model, profileDir);
this.installExtensions(profileDir);
this.deleteLockFiles(profileDir);
this.deleteExtensionsCacheIfItExists(profileDir);
this.updateUserPrefs(userPrefs);
return profileDir;
} catch (IOException var3) {
throw new UnableToCreateProfileException(var3);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当参数disableTempProfileCreation设置为 true时,这将阻止 Selenium 创建临时 Firefox 配置文件。
但是,现在 Selenium …