[英]how to change firefox proxy settings using xpcom
我有一个在本地主机(127.0.0.1)上运行的代理服务器,我已经厌倦了必须培训用户如何在firefox中切换代理以绕过被阻止的网站的麻烦。
我决定写一个插件。 我想知道如何使用xpcom告诉firefox使用某个代理
对于http,请使用127.0.0.1端口8080。
互联网上的例子很少。
谢谢
代理服务器设置存储在首选项中 。 您可能想要更改network.proxy.type
, network.proxy.http
和network.proxy.http_port
( 文档 )。 像这样:
Components.utils.import("resource://gre/modules/Services.jsm");
Services.prefs.setIntPref("network.proxy.type", 1);
Services.prefs.setCharPref("network.proxy.http", "127.0.0.1");
Services.prefs.setIntPref("network.proxy.http_port", 8080);
如果需要动态确定每个URL的代理,则可以通过nsIProtocolProxyService
接口使用功能提供程序-它允许您定义“代理过滤器”。 这样的事情应该起作用:
var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"]
.getService(Components.interfaces.nsIProtocolProxyService);
// Create the proxy info object in advance to avoid creating one every time
var myProxyInfo = pps.newProxyInfo("http", "127.0.0.1", 8080, 0, -1, 0);
var filter = {
applyFilter: function(pps, uri, proxy)
{
if (uri.spec == ...)
return myProxyInfo;
else
return proxy;
}
};
pps.registerFilter(filter, 1000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.