geckofx

How to Redirect Gecko Javascript Console messages to a file?


Is there any way to redirect the javascript console to a file?

I found this link

https://bitbucket.org/geckofx/geckofx-29.0/issues/9/how-to-get-javascript-consolelog-error

but it requires using devtools that im not going to have in the field.

There must be a simple way to redirect to a C# method.

Any help is appreciated.


Solution

  • Capture the ConsoleMessage event and save each row to a file:

    geckoWebBrowser.ConsoleMessage += GeckoWebBrowserOnConsoleMessage;
    
    void GeckoWebBrowserOnConsoleMessage(object sender, ConsoleMessageEventArgs e)
    {
        AppendToFile(e.Message);
    }