1
即时通过Mozilla提供的addon-sdk开发一个小小的Firefox插件。该插件只能在一个特定的网站上工作,它需要阻止来自该网站的js文件。我正在寻找如何阻止此类请求的小时。用火狐插件封锁JS
希望有人知道答案
即时通过Mozilla提供的addon-sdk开发一个小小的Firefox插件。该插件只能在一个特定的网站上工作,它需要阻止来自该网站的js文件。我正在寻找如何阻止此类请求的小时。用火狐插件封锁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)
而且看看这些文档:https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads#Content_Policy
阻止请求的东西,你通常会通过创建XPCOM组件实现[nsIContentPolicy]做(HTTPS ://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIContentPolicy)。这是非常不平凡的,但SDK并没有给你任何工具。 – 2012-03-01 07:07:25