I've been trying to use C# to get the HAR for a website. Or specifically to retrieve URLs containing m3u8 in them as it's not in the source of the HTML but does show in the Network tab of Chrome dev tools.
I've found lots of old examples and none of them compile. Usually find namespace issues with Server, Client, HarResult, Log, Entry. Below is an example. Does anyone have any current examples that would work and what I need to install in Visual Studio to make it work including versions?
// Supply the path to the Browsermob Proxy batch file
Server server = new Server(@"C:\temp\browsermob-proxy-2.1.4\bin\BrowserMobProxybinbrowsermob-proxy.bat");
server.Start();
Thread.Sleep(1000);
Client client = server.CreateProxy();
client.NewHar("assertselenium");
var chromeOptions = new ChromeOptions();
var seleniumProxy = new Proxy { HttpProxy = client.SeleniumProxy, SslProxy = client.SeleniumProxy };
chromeOptions.Proxy = seleniumProxy;
var dr = new ChromeDriver(chromeOptions);
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;
}
dr.Quit();
client.Close();
server.Stop();