Transferred from bug 1353510 Is there any chance of providing any form of Domain to IP conversion? It can be fresh DNS query or even grabbing the IP from the Firefox DNS cache. Domain based proxy selection, while mostly adequate, does not cover all of the required possibilities. The PAC implementation (direct via Network - Connections - Settings) seems to use a C++ synchronous dnsResolve. As mentioned in comment 7 (above bug), there is API access to asyncResolve() (and I have already prepared the code) but that may or may not work in WebExtension implementation of Proxy API. It appears that the WebExtension Proxy API is also synchronous. Is there any way to pass the IP to ProxyScriptContext.jsm so that it can be retrieved by the addon?
This could be provided as one of the extended arguments to FindProxyForUrl() like the others in bug 1368559 by calling https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDNSService#resolve() before we invoke FindProxyForUrl(). However: "Warning this method may block the calling thread for a long period of time. It is extremely unwise to call this function on the User Interface thread of an application." I don't know if we can use https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDNSService#asyncResolve() instead: FindProxyForURL() is synchronous, and we will not have called it yet, but I don't know if the calling thread is synchronous, too, nor what other possible performance implications there are. Presumably the DNS lookup has already been done or is about to be done since nsIProtocolProxyService.registerChannelFilter() hands an nsIChannel instance to nsIProtocolProxyChannelFilter.applyFilter()
I was thinking of using an exciting process instead of creating a new one. It depends if the browser (not the API) checks the DNS BEFORE or AFTER processing FindProxyForURL() If the browser checks the DNS BEFORE processing FindProxyForURL(), then we can find a way of passing the already collected IP to the function. In that case, there would be no need for a separate DNS resolve (async or sync). If browser checks the DNS AFTER processing FindProxyForURL(), then a new IP based function could be created to pass to the browser. The browser need to do its DNS check anyway and in both cases, the DNS checking is left to the browser without creating a new DNS check process.
Bug 1353510 provides helper functions to handle dns resolution.