Firefox addon 使用Firefox插件阻止JS

Firefox addon 使用Firefox插件阻止JS,firefox-addon,firefox-addon-sdk,Firefox Addon,Firefox Addon Sdk,我正在用mozilla提供的插件sdk开发一个firefox插件。插件应该只在一个特定的网站上工作,它需要阻止该网站的js文件。我花了好几个小时研究如何阻止这样的请求 希望有人知道答案是的,你必须主要通过手工完成。SDK在这里对您没有多大帮助,但它在某种程度上是可能的 这是你需要做的事情。请注意,这并没有经过测试,也不会开箱即用,只是为了让您了解所涉及的组件以及在哪里可以找到更多资源 const { Cc, Ci, Cm, components } = require("chrome"); Cu

我正在用mozilla提供的插件sdk开发一个firefox插件。插件应该只在一个特定的网站上工作,它需要阻止该网站的js文件。我花了好几个小时研究如何阻止这样的请求


希望有人知道答案

是的,你必须主要通过手工完成。SDK在这里对您没有多大帮助,但它在某种程度上是可能的

这是你需要做的事情。请注意,这并没有经过测试,也不会开箱即用,只是为了让您了解所涉及的组件以及在哪里可以找到更多资源

const { Cc, Ci, Cm, components } = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
const CategoryManager = Cc["@mozilla.org/categorymanager;1"]
                                .getService(Ci.nsICategoryManager);

function PolicyComponent() { }  

PolicyComponent.prototype = {  
  desc:             "My nsIContentPolicy XPCOM Component",  
  classID:          components.ID("{3ffd2f60-3784-11e1-b86c-0800200c9a66}"),  
  contractID:       "@abc.def.com/policycomp;1",
  QueryInterface:   XPCOMUtils.generateQI([Ci.nsIContentPolicy]),

  shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
    if (contentLocation.spec != BLOCKED_JS) { return return Ci.nsIContentPolicy.ACCEPT; }
    else { return Ci.nsIContentPolicy.REJECT_REQUEST; }
  },
  shouldProcess: function() {
    return CI.nsIContentPolicy.ACCEPT;
  }
}

var pc = new PolicyComponent()

// Register the Interface
Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(pc.uuid, pc.desc, pc.contractID, pc);

// Add the content policy 
CategoryManager.addCategoryEntry("content-policy",pc.className,pc.contractID, true, true);  // not sure you should replace (last true statement)
有关更多信息,请参阅此帖子:


还可以看看这些文档:

是的,你必须主要通过手工完成。SDK在这里对您没有多大帮助,但它在某种程度上是可能的

这是你需要做的事情。请注意,这并没有经过测试,也不会开箱即用,只是为了让您了解所涉及的组件以及在哪里可以找到更多资源

const { Cc, Ci, Cm, components } = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
const CategoryManager = Cc["@mozilla.org/categorymanager;1"]
                                .getService(Ci.nsICategoryManager);

function PolicyComponent() { }  

PolicyComponent.prototype = {  
  desc:             "My nsIContentPolicy XPCOM Component",  
  classID:          components.ID("{3ffd2f60-3784-11e1-b86c-0800200c9a66}"),  
  contractID:       "@abc.def.com/policycomp;1",
  QueryInterface:   XPCOMUtils.generateQI([Ci.nsIContentPolicy]),

  shouldLoad: function(contentType, contentLocation, requestOrigin, aContext, mimeTypeGuess, extra) {
    if (contentLocation.spec != BLOCKED_JS) { return return Ci.nsIContentPolicy.ACCEPT; }
    else { return Ci.nsIContentPolicy.REJECT_REQUEST; }
  },
  shouldProcess: function() {
    return CI.nsIContentPolicy.ACCEPT;
  }
}

var pc = new PolicyComponent()

// Register the Interface
Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(pc.uuid, pc.desc, pc.contractID, pc);

// Add the content policy 
CategoryManager.addCategoryEntry("content-policy",pc.className,pc.contractID, true, true);  // not sure you should replace (last true statement)
有关更多信息,请参阅此帖子:


还可以看看这些文档:

阻塞请求通常是通过创建XPCOM组件来实现的。但是,它非常重要,SDK没有为此提供任何工具。阻止请求通常是通过创建XPCOM组件来实现的。这是非常不平凡的,但是SDK并没有为您提供任何工具。