是否有可能在插件中控制firefox的DNS请求?
Is it possible to control Firefox's DNS requests in an addon?
我想知道是否有可能拦截和控制/重定向由Firefox发出的DNS请求?
目的是在Firefox中设置一个独立的DNS服务器(而不是系统的DNS服务器)
没有。通过nsIDNSService
接口提供DNS解析器。该接口不是完全可脚本化的,所以您不能用自己的Javascript实现替换内置实现。
但是你能不能重写DNS服务器?
内置实现从nsDNSService
到nsHostResolver
再到PR_GetAddrByName
(nspr),最后到getaddrinfo
/gethostbyname
。这将使用系统(或实现它的库)所配置的任何内容。
还有其他选择吗?
没有。您可以安装代理并让它解析域名(当然需要某种代理服务器)。但这是一个非常黑客,我不建议(如果用户已经有一个真正的,非解析代理配置;也需要处理)
您可以检测到"问题加载页面",然后可能使用 redirectTo
方法。
基本上他们都加载about:neterror
url后面有一堆信息。即:
-
about:neterror?e=dnsNotFound&u=http%3A//www.cu.reporterror%28%27afew/&c=UTF-8&d=Firefox%20can%27t%20find%20the%20server%20at%20www.cu.reporterror%28%27afew.
-
about:neterror?e=malformedURI&u=about%3Abalk&c=&d=The%20URL%20is%20not%20valid%20and%20cannot%
但是这个信息保存在文档中。所以你必须这样做。下面的示例代码将检测加载页面时出现的问题:
var listenToPageLoad_IfProblemLoadingPage = function(event) {
var win = event.originalTarget.defaultView;
var docuri = window.gBrowser.webNavigation.document.documentURI; //this is bad practice, it returns the documentUri of the currently focused tab, need to make it get the linkedBrowser for the tab by going through the event. so use like event.originalTarget.linkedBrowser.webNavigation.document.documentURI <<i didnt test this linkedBrowser theory but its gotta be something like that
var location = win.location + ''; //I add a " + ''" at the end so it makes it a string so we can use string functions like location.indexOf etc
if (win.frameElement) {
// Frame within a tab was loaded. win should be the top window of
// the frameset. If you don't want do anything when frames/iframes
// are loaded in this web page, uncomment the following line:
// return;
// Find the root document:
//win = win.top;
if (docuri.indexOf('about:neterror') == 0) {
Components.utils.reportError('IN FRAME - PROBLEM LOADING PAGE LOADED docuri = "' + docuri + '"');
}
} else {
if (docuri.indexOf('about:neterror') == 0) {
Components.utils.reportError('IN TAB - PROBLEM LOADING PAGE LOADED docuri = "' + docuri + '"');
}
}
}
window.gBrowser.addEventListener('DOMContentLoaded', listenToPageLoad_IfProblemLoadingPage, true);
相关文章:
- ajax请求的顺序总是不同的
- Meteor如何接收HTTP请求
- 有没有一种方法可以防止img get请求使用css或js发生
- 从ajax请求中获取javascript对象
- JSONP请求返回结果,但也触发error_callback
- 在localhost Dev Box上测试JSONP请求的最佳方式
- Ajax请求文档就绪会导致jquery加载缓慢
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- 正在传递JSONP标头's数据参数到另一个文件中的AJAX请求
- 在openshift node js应用程序中获取请求
- 反应路由器弄乱了请求网址
- 在我的情况下,如何进行http请求
- 使用密码对话框Javascript请求帮助
- servlet中的请求对象,而不是从jsp接收参数值
- 否'访问控制允许来源'标头存在于IISNOde中请求的资源(AngularJS+NodeJs)上
- 405(方法不允许)仅在使用 DNS 时对 AJAX 请求
- 是否有可能在插件中控制firefox的DNS请求?
- DNS缓存请求模块- node.js
- 更新AJAX请求中域名的DNS
- Firefox插件,javascript,停止HTTP/DNS请求