0

WebBrowser's event isn't firing? I don't think its even navigating?? This is a console application. I'm unsure why isn't not doing this, I have added [STAThread] to my Main method in Program.cs

internal class ClothingDownloader
{
    private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();

    private WebBrowser _webBrowser;

    public void Load()
    {
        var downloadUrl = Program.Server.ConfigHandler.GetConfigValueByKey("clothing.figuremap.url");

        if (File.Exists("storage/figuremap.xml"))
        {
            Logger.Warn("Grabbing figuremap.xml from the cache...");
        }
        else
        {
            Logger.Trace("Attempting to download figuremap.xml from " + downloadUrl.Split('/')[0] + "...");

            _webBrowser = new WebBrowser();
            _webBrowser.DocumentCompleted += webBrowser_DocumentCompleted;
            _webBrowser.ScriptErrorsSuppressed = true;
            _webBrowser.Navigate("https://google.com");

        }
    }

    void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        Console.WriteLine(_webBrowser.DocumentText);
    }
}
hello
  • 169
  • 10
  • Where is your `Load` event called? Where is `_webBrowser` displayed on a hWnd, `Window` or `Form`? Is this code running inside a WinForms, WPF or Console application? `WebBrowser` is not intended to be used in headless environments, use `WebClient`, `HttpWebRequest` or `HttpClient` to download web-resources. – Dai Feb 03 '18 at 01:30
  • It's clear to see that you didn't read my question, It's on a Console application. I can't use WebClient as it has issues with not sending the correct headers and it requires an actual browser. My Load() method is called inside Programs main method. – hello Feb 03 '18 at 01:32
  • I did read your question, however a Console-application binary can still be loaded by a non-console application. And you are wrong about `WebClient` "requiring an actual browser" and you can add your own headers (using the `Headers` property). – Dai Feb 03 '18 at 02:09

0 Answers0