1

I am writing some simple C# code to try automatically getting HAR file from Chrome browser. I am using browser-mob-proxy and there is a function: GetHar() which is supposed to return some different entries of URL, request and response time, etc. However, it always return me only 1 entry which is the original URL I am negativing to: www.google.com

I've tried to use dr.Navigate().Refresh() to make sure the page is reloaded so there are some activities on chrome DevTool Network section.

        server.Start();
        Thread.Sleep(1000);
        Client client = server.CreateProxy();
        client.NewHar("google");
        var chromeOptions = new ChromeOptions();
        var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy };
        chromeOptions.Proxy = seleniumProxy;
        var dr = new ChromeDriver(chromeOptions);       

        dr.Navigate().GoToUrl("http://www.google.com");
        dr.FindElementByClassName("gb_e").Click();

        Thread.Sleep(3500);
        dr.Navigate().Refresh();


        // Get the performance stats
        HarResult harData = client.GetHar();
        Log log = harData.Log;
        Entry[] entries = log.Entries;

        foreach (var e in entries)
        {
            Request request = e.Request;
            Response response = e.Response;
            var url = request.Url;
            var time = e.Time;
            var status = response.Status;
            var testStr = "Url: " + url + " - Time: " + time + " Response: " + status;
        }

I expected GetHar() function will return more entries instead of only 1.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Peng Yang
  • 21
  • 4
  • Seen the example [here](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools.network/getHAR)? – Jeroen Heier Aug 14 '19 at 17:21
  • How did you create the server? I have been looking for the C# version of browsermob but could nt find anything. Thanks in advance – cocacho Jun 30 '20 at 19:51

1 Answers1

1

Not sure why, but the issue has been resolved by adding SSL proxy:

var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy , SslProxy = client.SeleniumProxy };

Hopefully this can help someone who is dealing with the same issue.... thanks!

Peng Yang
  • 21
  • 4
  • What do you use for using for Server and Client? I can't get them to be recognized and the one way I can with a Microsoft library installs a boat load of stuff and doesn't support the Stop() method so probably the wrong library to link – John Nov 28 '20 at 04:19