Search code examples
javascriptfirefox-addondnsxpcom

Is it possible to add and modify the dns cached entry in firefox?


I am trying to accomplish some specific test requirement.

One of the requirement now is to redirect some nonexistent url to specific ip, which is what the dns is doing. I think firefox is using internal dns cache. But I cannot find a proper service that I can use to change such kind of dns cache. On the other hand, i have no idea if firefox support some kind of service to customize the dns process, I mean give a customized result instead of really getting from DNS Server.

As I need to start many firefox process to do the work concurrently, so I cannot do this simply by changing the system hosts file, cause it will affect other process.

Any idea?


Solution

  • No, modifying DNS responses isn't possible in Firefox, the DNS service merely allows triggering a DNS request. What you could do is recognizing NS_ERROR_UNKNOWN_HOST response and somehow redirecting it to your server. While recognizing isn't particularly hard, redirecting is complicated. You could add a progress listener and check whether a request finished in onStateChange method (if (aFlag & STATE_STOP)). The parameter aStatus gives you the status of the request, you would be looking for status Components.results.NS_ERROR_UNKNOWN_HOST. And for top-level requests (aFlag & STATE_WINDOW) you could change window location to make a request to a different server instead. For other requests - don't know how one would "redirect" there.