python-2.7selenium-webdriverbrowsermob

BrowserMob not proxying localhost pages


I'm trying to use BrowserMob to proxy pages with Selenium WebDriver. When the (Python) test case tries to load pages from localhost, BrowserMob fails to proxy them.

Is it possible for BrowserMob to proxy connections to the webserver at localhost?


Solution

  • BrowserMob Proxy will work with localhost, but only in the latest version (2.0.0), and only when defining the bmp.allowNativeDnsFallback Java property when running the proxy. I'm not familiar with the Python wrapper, but it's unlikely that it meets those criteria.

    The problem is the DNS resolution that BrowserMob Proxy uses, which essentially ignores the hosts file that defines localhost. If you use 127.0.0.1 instead of localhost when making requests it should work for you.