Search code examples
c#seleniumproxyfiddlerfiddlercore

Fiddler often ignoring some Http traffic on localhost. Fiddler or Selenium Proxy settings?


I'm using Fiddler to monitor traffic from my selenium instance.

I am using the following code to start Fiddler with Fiddler.Core

static void StartProxy()
{
    FiddlerApplication.Shutdown();
    FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
    FiddlerApplication.Startup(8888, FiddlerCoreStartupFlags.DecryptSSL);
}

I'm launching Selenium to use the proxy via the following:

StartProxy();

var seleniumProxy = new Proxy { HttpProxy = "localhost:8888", SslProxy = "localhost:8888" };
var chromeOptions = new ChromeOptions { Proxy = seleniumProxy };

var path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\ChromeDriver\\";
var chromeService = ChromeDriverService.CreateDefaultService(path);

var driver = new ChromeDriver(chromeService, chromeOptions);

Selenium will then navigate to my web page and Fiddler will be collecting HTTP requests. Most data will always come through (GET for the HTML for example), but the data that I want to collect with Fiddler (updates to the page) is only collected some of the time (it used to be very consistent but now it rarely works).

I read here and here that browsers can ignore proxies if they're set on localhost.

I tried changing this line to machine name and IP address with no luck, Chrome will launch and say "Unable to connect to proxy server" for each of these. I also tried each with "http://" in front.

// Original
var seleniumProxy = new Proxy { HttpProxy = "localhost:8888", SslProxy = "localhost:8888" }; 

// "Dot Trick"
var seleniumProxy = new Proxy { HttpProxy = "localhost.:8888", SslProxy = "localhost.:8888" }; 
// With this line, chrome will start and connect to proxy server but it will still not get the traffic I want consistently.

// IP Address
var seleniumProxy = new Proxy { HttpProxy = "192.168.1.5:8888", SslProxy = "192.168.1.5:8888" }; 

// Machine Name
var seleniumProxy = new Proxy { HttpProxy = "machine_name:8888", SslProxy = "machine_name:8888" }; 

I'm certain that this is launching Fiddler because if I try to run the Fiddler desktop application I get "Port 8888 is already in use...".

Is there some setting for starting the proxy (my StartProxy()) where you have to specify the end point if it's not the default "localhost"?

Thanks for your help.


Solution

  • It's not completely clear what you're asking.

    Chrome has no problem sending requests to FiddlerCore; you shouldn't need any special steps.

    Your StartProxy method shouldn't call Shutdown at all.

    You're using AfterSessionComplete, which means that you're only getting called after traffic has completed; if there are delays that could prevent you from seeing traffic until much later.

    Where in your code do you clear the browser's cache so that you ensure that it's always pulling from the network (and thus FiddlerCore) and not pulling it from the web browser's cache?