Intercept DNS request in a Chrome Extension?

五迷三道 提交于 2020-01-03 08:39:50

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/6045674/intercept-dns-request-in-a-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!