制作 Firefox 插件的最简单方法是什么,它重复了这个 chrome 功能:
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
if(info.url.indexOf("notifier") + 1){
return {redirectUrl: "https://domain.null/1.js"};
}
},
{
urls: [
"*://domain2.null/*"
],
types: ["script"]
}, ["blocking"]);
我知道关于nsI内容政策在firefox中,但我不明白如何使用它。
所有意见、建议和帮助将不胜感激
Answer
我已经确定了不可重新启动扩展的问题。
要阻止内容,我们可以使用 nsIContentPolicy,正如 Wladimir 所说。我们还可以将脚本注入到页面中窗口监听器(窗口.浏览器)。
例如,这种做法非常有效:https://github.com/jvillalobos/AMO-Admin-Assistant/blob/master/src/bootstrap.js https://github.com/jvillalobos/AMO-Admin-Assistant/blob/master/src/bootstrap.js
我认为现在如果不进行重大黑客攻击就无法做到这一点。这是主题错误 765934 https://bugzilla.mozilla.org/show_bug.cgi?id=765934这将添加一个redirectTo() method
to the nsIHttpChannel界面 https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIHttpChannel。一旦实现,这样的代码应该可以工作:
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
var observer = {
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIObserver,
Ci.nsISupportsWeakReference
]),
observe: function(subject, topic, data)
{
if (topic == "http-on-modify-request" &&
subject instanceof Ci.nsIHttpChannel)
{
var uri = subject.URI;
if (uri.host == "domain2.null" && /\.js(\?|$)/.test(uri.path))
{
var redirectUri = Services.io.newURI("https://domain.null/1.js",
null, null);
subject.redirectTo(redirectUri);
}
}
}
};
Services.obs.addObserver(observer, "http-on-modify-request", true);
以供参考:服务.jsm https://developer.mozilla.org/en-US/docs/JavaScript_code_modules/Services.jsm, XPCOMUtils.jsm https://developer.mozilla.org/en-US/docs/JavaScript_code_modules/XPCOMUtils.jsm, 观察员通知 https://developer.mozilla.org/en-US/docs/Observer_Notifications#HTTP_requests, nsIHttpChannel https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIHttpChannel, nsIURI https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIURI
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)