I am trying to use GeckoFx. Sample program:
class Program
{
private GeckoWebBrowser browser;
private Thread thread;
static void Main(string[] args)
{
Xpcom.AfterInitalization += () =>
{
Console.WriteLine("init ok");
};
Xpcom.Initialize(Utils.AppPath + "xul");
Program prog = new Program();
prog.Start();
Thread.Sleep(1000); // wait for browser instance be created
prog.Test();
}
private void Test()
{
browser.NavigationError += (sender, args) =>
{
Console.WriteLine("err");
};
browser.Navigated += (sender, args) =>
{
var text = browser.Window.Document.TextContent;
// text is null
};
browser.Navigate("http://google.com");
Console.ReadKey();
}
/// <summary>
/// application thread method
/// </summary>
private void AppThread()
{
browser = new GeckoWebBrowser();
Application.Run();
}
/// <summary>
/// start thread
/// </summary>
private void Start()
{
thread = new Thread(AppThread);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}
As You see, I create STA thead and run application and create browser instance within it. In Test method I trying to get text of document but it is empty! Is problem about I am not created Form? So is it possible to use GeckoFx without UI? Thanks.