繁体   English   中英

如何使用xpcom更改firefox代理设置

[英]how to change firefox proxy settings using xpcom

我有一个在本地主机(127.0.0.1)上运行的代理服务器,我已经厌倦了必须培训用户如何在firefox中切换代理以绕过被阻止的网站的麻烦。
我决定写一个插件。 我想知道如何使用xpcom告诉firefox使用某个代理
对于http,请使用127.0.0.1端口8080。
互联网上的例子很少。

谢谢

代理服务器设置存储在首选项中 您可能想要更改network.proxy.typenetwork.proxy.httpnetwork.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM