using DotNetBrowser;
using DotNetBrowser.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace JavaScriptCSBridgeSample
{
    class Program
    {
        static void Main(string[] args)
        {
            using (Browser browser = BrowserFactory.Create())
            {
                ManualResetEvent waitEvent = new ManualResetEvent(false);

                // Modifies document.title value via JavaScript-Java Bridge API
                JSValue document = browser.ExecuteJavaScriptAndReturnValue("document");
                if (document.IsObject())
                {
                    document.AsObject().SetProperty("title", "My Title");
                }

                browser.TitleChangedEvent += delegate(object sender, TitleEventArgs e)
                {
                    Console.Out.WriteLine("\"document.title\" \"" + e.Title + "\"");
                    waitEvent.Set();
                };

                browser.LoadHTML(@"<html>
                                     <body>
                                     </body>
                                   </html>");

                waitEvent.WaitOne();
                Thread.Sleep(2000);
            }
         }
    }
}