在 Chrome 扩展程序中拦截 DNS 请求?
如果我想测试 http://www.domain.com,但我想通过切换 IP 来测试它的两个版本(例如,一个解析为 127.0.0.1,另一个解析为 192.168.1.200)是否可以编写/使用 Chrome 扩展来处理拦截 DNS 查询并解析为我选择的 IP?
当前的解决方法是利用主机文件并刷新 DNS 缓存来在它们之间进行切换,但这并不是最佳的,并且希望浏览器扩展可以处理同样的事情。
If I want to test http://www.domain.com, but I want to test two versions of it by switching the IP out (e.g. one resolves to 127.0.0.1 and the other 192.168.1.200) is it possible to write/use a chrome extension to handle intercepting the DNS query and resolving to my IP of choice?
The current workaround is to utilize the hosts file and flush the DNS cache to switch between them but that's less than optimal and was hoping a browser extension could handle the same thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Chrome 内部没有原生操作 DNS 请求/响应的机制,甚至无法通过即将推出的 WebRequest API 进行操作。
您是否需要使用完全相同的域名进行测试?在 http://dev.example.com/ (或 http://example.dev/(如果您运行自己的 DNS 或编辑了主机文件)是一种干净的机制,可以产生您想要的效果想要以一种与您有权访问的 API 兼容的方式;编写一个扩展程序,为您提供一个按钮,只需按一下按钮即可在两个域之间切换,这将是微不足道的
There's no mechanism to manipulate DNS requests/responses natively inside Chrome, not even via the upcoming WebRequest API.
Is there a reason that you need to test with exactly the same domain name? Setting up a dev environment on something like http://dev.example.com/ (or http://example.dev/ if you run your own DNS or have edited your hosts file) is a clean mechanism for producing the effect you want in a way that's functional with the APIs you have access to; writing an extension that gave you a button to toggle between the two domains with the push of a button would be trivial