如何从外部程序更改 Firefox 的代理设置?

发布于 2024-07-10 16:12:32 字数 874 浏览 4 评论 0原文

我见过一些能够修改 Firefox 代理设置的程序(例如 Charles Web Developer Proxy)。 顺序是:

  1. Firefox 正在运行,并带有用户代理设置。
  2. 用户启动外部第三方应用程序,该应用程序
  3. 会修改 Firefox 的代理设置,然后
  4. 用户退出第三方程序,
  5. Firefox 将以其原始代理设置恢复运行。

假设外部应用程序记住旧的代理设置并在退出时恢复它们,我如何读取和写入 Firefox 的代理设置? 已尝试通过 Firefox doco 进行谷歌搜索,但还没有成功。

考虑的选项:

  • 编写新的用户首选项配置文件并启动浏览器的新实例。 可以工作,但不太正确——例如,查尔斯可以修改已运行的浏览器的设置并在不重新启动的情况下恢复它们。
  • 写一个插件。 可以编写一个 Firefox 插件,向外部提供某种 IPC,然后自行处理 Firefox 首选项设置。 事实上,我认为这可能是唯一的方法。 禁用 Charles 的 Firefox 插件似乎会禁用其动态修改首选项的能力。

可能的资源

I've seen a few programs (eg Charles Web Developer Proxy) that are able to modify Firefox's proxy settings. The sequence is:

  1. Firefox is running, with the users proxy settings.
  2. User starts the external third party application, which
  3. modifies Firefox's proxy settings, and then
  4. the user exits the third party program and,
  5. Firefox resumes running with its original proxy settings.

Assuming the external application is remembering the old proxy settings and restoring them on exit how can I read and write Firefox's proxy settings? Have tried Googling through the Firefox doco but no luck yet.

Options Considered:

  • Write a new user preferences config file and start a new instance of the browser. Would work but not quite right -- Charles for example can modify the settings of an already running browser and restore them without restarting.
  • Write a plug-in. Could write a Firefox plugin that offered some kind of IPC to the outside and then handled the Firefox preference setting itself. In fact, I think this might be the only way. Disabling Charles' Firefox plug-in seems to disable its ability to modify preferences on the fly.

Possible Resources

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

掌心的温暖 2024-07-17 16:12:32

您可能想看看 Fiddler 是如何做到这一点的(www.fiddler2.com)。 C:\program files\fiddler2\fiddlerhook\ 文件夹有一个 Firefox 扩展,它显示了如何完成此操作。

You might want to look at how Fiddler does this (www.fiddler2.com). The C:\program files\fiddler2\fiddlerhook\ folder has a Firefox extension which shows how this can be done.

预谋 2024-07-17 16:12:32

从文档中我可以看到,Charles 有一个它安装/使用的匹配的 Firefox 扩展。 这可能就是它可以动态重新加载代理信息的方式。

代理信息存储在您的个人资料的 prefs.js 中,但无法即时重新加载。 Firefox 在启动时从其中读取数据,在关闭时向其中写入数据,并且在此期间不会从其中加载。 另外,如果您编辑 prefs.js 时 Firefox 正在运行,您的更改将被覆盖。

我认为您也许可以使用 PAC 文件做一些事情,但经过一番研究后,我发现它似乎也不会即时重新加载。 您必须重新启动才能重新加载对设置的任何修改。

From what I could see from the documentation, Charles has a matching Firefox extension which it installs/uses. That may be how it can reload the proxy information on the fly.

Proxy information is stored in your profile's prefs.js, but that can't be reloaded on the fly. Firefox reads from it on startup and writes to it when it shuts down, and does not load from it in between. Also, if Firefox is running when you edit prefs.js, your changes will be overwritten.

I thought you might be able to do something with a PAC file, but after digging around a bit, I've found that it doesn't seem to be reloaded on the fly either. You'd have to restart to reload any modifications to the settings.

小傻瓜 2024-07-17 16:12:32

在我的机器上,Firefox 的所有代理设置都存储在 C:\DOCUME~1\BRUCEX~1\APPLIC~1\Mozilla\Firefox\Profiles\licga1pg.default\prefs.js 中。 该文件中的标头显示:

# Mozilla User Preferences

/* Do not edit this file.
 *
 * If you make changes to this file while the application is running,
 * the changes will be overwritten when the application exits.
 *
 * To make a manual change to preferences, you can visit the URL about:config
 * For more information, see http://www.mozilla.org/unix/customizing.html#prefs
 */

customizing.html 的链接位于此处。 因此,理论上你可以调整其中的部分或全部,

user_pref("network.proxy.backup.ftp", "squid.home-server");
user_pref("network.proxy.backup.ftp_port", 3128);
user_pref("network.proxy.backup.gopher", "squid.home-server");
user_pref("network.proxy.backup.gopher_port", 3128);
user_pref("network.proxy.backup.socks", "squid.home-server");
user_pref("network.proxy.backup.socks_port", 3128);
user_pref("network.proxy.backup.ssl", "squid.home-server");
user_pref("network.proxy.backup.ssl_port", 3128);
user_pref("network.proxy.ftp", "squid.home-server");
user_pref("network.proxy.ftp_port", 3128);
user_pref("network.proxy.gopher", "squid.home-server");
user_pref("network.proxy.gopher_port", 3128);
user_pref("network.proxy.http", "squid.home-server");
user_pref("network.proxy.http_port", 3128);
user_pref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, *.my-domain");
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.proxy.socks", "squid.home-server");
user_pref("network.proxy.socks_port", 3128);
user_pref("network.proxy.ssl", "squid.home-server");
user_pref("network.proxy.ssl_port", 3128);
user_pref("network.proxy.type", 1);

尽管存在让 Firefox 重新读取它们的问题。

All of the proxy settings for Firefox, on my machine, are stored in C:\DOCUME~1\BRUCEX~1\APPLIC~1\Mozilla\Firefox\Profiles\licga1pg.default\prefs.js . The header in that file says

# Mozilla User Preferences

/* Do not edit this file.
 *
 * If you make changes to this file while the application is running,
 * the changes will be overwritten when the application exits.
 *
 * To make a manual change to preferences, you can visit the URL about:config
 * For more information, see http://www.mozilla.org/unix/customizing.html#prefs
 */

The link to customizing.html is here. So in theory you could tweak some or all of these

user_pref("network.proxy.backup.ftp", "squid.home-server");
user_pref("network.proxy.backup.ftp_port", 3128);
user_pref("network.proxy.backup.gopher", "squid.home-server");
user_pref("network.proxy.backup.gopher_port", 3128);
user_pref("network.proxy.backup.socks", "squid.home-server");
user_pref("network.proxy.backup.socks_port", 3128);
user_pref("network.proxy.backup.ssl", "squid.home-server");
user_pref("network.proxy.backup.ssl_port", 3128);
user_pref("network.proxy.ftp", "squid.home-server");
user_pref("network.proxy.ftp_port", 3128);
user_pref("network.proxy.gopher", "squid.home-server");
user_pref("network.proxy.gopher_port", 3128);
user_pref("network.proxy.http", "squid.home-server");
user_pref("network.proxy.http_port", 3128);
user_pref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, *.my-domain");
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.proxy.socks", "squid.home-server");
user_pref("network.proxy.socks_port", 3128);
user_pref("network.proxy.ssl", "squid.home-server");
user_pref("network.proxy.ssl_port", 3128);
user_pref("network.proxy.type", 1);

though there is the issue then of getting Firefox to re-read them.

蔚蓝源自深海 2024-07-17 16:12:32

如果您查看我之前的问题的答案中的一些链接,您可能会找到可用于根据需要调整代理设置的代码。

If you check out some of the links in the answers to my earlier question you may find code you can use to tweak the proxy settings as you required.

っ左 2024-07-17 16:12:32

通过 ActiveX Control for Hosting Netscape Plug-ins in IE 与 Firefox 建立 ActiveX 连接但我怀疑这是否会有任何帮助。 尽管如此,还是值得一看的。

There is an ActiveX connection to Firefox via ActiveX Control for Hosting Netscape Plug-ins in IE but I have my doubts whether that's going to be of any help. Still, it's worth a look.

愛上了 2024-07-17 16:12:32

即使我面临使用手动代理完成的连接设置问题,当我从第三方应用程序启动 Firefox 浏览器时也没有得到反映(我正在使用 selenium)

我厌倦了在 C:\Program Files\Mozilla 中添加 users.js 文件Firefox\defaults\profile

具有上述建议的更改(添加 user_pref)语句,但不知怎的,我的 Firefox 浏览器仍然没有接受提到的更改。 即使在同一位置的我的 prefs.js 上也是同样的事情(实际上我的 prefs.js 是空的!!)

但是有其他一些方法可以做到这一点......
在 C:\Program Files\Mozilla Firefox\greprefs\all.js 中,执行上面建议的相同更改
pref("网络.代理.类型", 0); 至 1
pref("network.proxy.http", ""); 到本地主机
pref("network.proxy.http_port", 0); 到 4444

一切开始工作..
但不确定这是否是正确的方法,因为我们正在更改安装目录中的文件。
顺便说一句,这是 Firefox 的一个错误吗?

感谢您的评论

Even I was facing the issue of connection settings done to use manual proxy was not getting reflected when i was launching firefox browser from thir party application (I am working on selenium)

I tired adding users.js file in C:\Program Files\Mozilla Firefox\defaults\profile

with the changes as suggested above (adding user_pref) statements, but somehow still my firefox browser was not picking up the changes mentioned. Same thing even on my prefs.js on same location (Actually my prefs.js is empty !!)

But got some other way of doing it...
in C:\Program Files\Mozilla Firefox\greprefs\all.js , do the same changes suggested above
pref("network.proxy.type", 0); to 1
pref("network.proxy.http", ""); to localhost
pref("network.proxy.http_port", 0); to 4444

and things started working..
But am not sure if this is the right way of doing it, since we are changing a file in installation directory..
BTW is it a bug with firefox ??

Appreciate your comments

幻梦 2024-07-17 16:12:32

我尝试下载 selenium rc 1.0.3 并使用 *chrome /usr/lib/firefox-3.0.10/firefox-bin 后跟 AUT 的 URL。它起作用了。据说他们已经从 1.0 删除了 *自定义运行模式.3(我的猜测),因为在解压缩selenium-server.jar文件时,我找不到任何custom.class文件,而不是早期版本中的selenium-server.jar文件中有一个custom.class文件。

I tried downloading the selenium rc 1.0.3 and used *chrome /usr/lib/firefox-3.0.10/firefox-bin followed by the URL of the AUT.It worked.Supposedly they have removed the *custom mode of running from 1.0.3(my guess) , because on , unzipping the selenium-server.jar file, I could not find any custom.class file as opposed to earlier versions where there was present a custom.class file in the selenium-server.jar file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文