//static void Main(string[] args) //{ //} public static void Main(String[] args) { Console.WriteLine("Started...."); WebView wv = WebCore.CreateWebView(1024, 600); wv.Source = new Uri("https://accounts.google.com/"); FrameEventHandler handler = null; handler = (s, e) => { if (e.IsMainFrame) { // we have finished loading main page, // let's unhook ourselves wv.LoadingFrameComplete -= handler; LoginAndTakeScreenShot(wv); } }; wv.LoadingFrameComplete += handler; WebCore.Run(); }
private static void LoginAndTakeScreenShot(WebView wv) { dynamic document = (JSObject)wv.ExecuteJavascriptWithResult("document"); using (document) { //Works var tbox = document.getElementById("Email"); tbox.value = "*****@*****.**"; //Works var pbox = document.getElementById("Passwd"); pbox.value = "**********"; FrameEventHandler handler = null; handler = (sender, args) => { if (args.IsMainFrame) { wv.LoadingFrameComplete -= handler; BitmapSurface surface = (BitmapSurface)wv.Surface; surface.SaveToPNG("result.png", true); System.Diagnostics.Process.Start("result.png"); WebCore.Shutdown(); } }; wv.LoadingFrameComplete += handler; var sbox = document.getElementById("signIn"); sbox.click(); } }
public static async Task <bool> WaitPageLoadComplete(this IWebView view, Action TriggerPageChangeAction, int timeOutSec = 0, CancellationToken ct = new CancellationToken()) { SemaphoreSlim signal = new SemaphoreSlim(0, 1); bool result = false; FrameEventHandler frameEvent = (o, e) => { if (e.IsMainFrame) { result = true; signal.Release(); } }; view.LoadingFrameComplete += frameEvent; TriggerPageChangeAction.Invoke(); if (timeOutSec > 0) { await signal.WaitAsync(TimeSpan.FromSeconds(timeOutSec), ct); } else { await signal.WaitAsync(ct); } view.LoadingFrameComplete -= frameEvent; return(result); }
public void SetHtml(string content) { if (Application.Current == null) { return; } Application.Current.Dispatcher.BeginInvoke(new Action(() => { Html = content; if (wb == null) { return; } wb.CacheMode = new BitmapCache(); FrameEventHandler webControlOnLoadCompleted = null; webControlOnLoadCompleted = (sender, args) => { if (args.IsMainFrame) { wb.LoadingFrameComplete -= webControlOnLoadCompleted; WbProcentualZoom(); wb.CacheMode = null; awesomiumInitialised = true; } }; wb.LoadingFrameComplete += webControlOnLoadCompleted; wb.LoadHTML(content); })); }
private void doTest(FrameEventHandler handler) { List <Exception> exceptions = new List <Exception>(); var newWindowThread = new Thread(() => { // Create and show the Window _window = new Backend.MainWindow(); _window.Closed += (s, e) => Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background); // Close the window after initialisation finished _window.webControl.LoadingFrameComplete += (s, e) => { try { handler.Invoke(s, e); } catch (Exception ex) { exceptions.Add(ex); _window.Close(); } _window.Close(); }; _window.Show(); // Start the Dispatcher Processing Dispatcher.Run(); }); // Set the apartment state newWindowThread.SetApartmentState(ApartmentState.STA); // Make the thread a background thread newWindowThread.IsBackground = true; // Start the thread newWindowThread.Start(); // Wait for thread to finish before completing test newWindowThread.Join(); foreach (Exception ex in exceptions) { throw ex; } }
private void doTest(FrameEventHandler handler) { List<Exception> exceptions = new List<Exception>(); var newWindowThread = new Thread(() => { // Create and show the Window _window = new Backend.MainWindow(); _window.Closed += (s, e) => Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background); // Close the window after initialisation finished _window.webControl.LoadingFrameComplete += (s, e) => { try { handler.Invoke(s, e); } catch (Exception ex) { exceptions.Add(ex); _window.Close(); } _window.Close(); }; _window.Show(); // Start the Dispatcher Processing Dispatcher.Run(); }); // Set the apartment state newWindowThread.SetApartmentState(ApartmentState.STA); // Make the thread a background thread newWindowThread.IsBackground = true; // Start the thread newWindowThread.Start(); // Wait for thread to finish before completing test newWindowThread.Join(); foreach (Exception ex in exceptions) throw ex; }
public async Task Navigate(String url) { Debug.WriteLine("Navigating"); TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); FrameEventHandler handler = (sender, args) => { Debug.WriteLine(args.Url); if (!_webView.IsNavigating && !_webView.IsLoading) { tcs.SetResult(true); } }; _webView.LoadingFrameComplete += handler; _synchronizationContext.Send(SetWebViewSource, url); await tcs.Task; _webView.LoadingFrameComplete -= handler; Debug.WriteLine("Done"); }
public Task <EventArgs> WaitForLoadingComplete(CancellationToken token) { var tcs = new TaskCompletionSource <EventArgs>(); FrameEventHandler handler = ((sender, e) => { if (!(sender as WebControl).IsLoading) { result = "DONE"; tcs.TrySetResult(e); } } ); var registration = token.Register(() => { result = "CANCELLED"; tcs.TrySetCanceled(); }); webControlnow.LoadingFrameComplete += handler; tcs.Task.ContinueWith(_ => { webControlnow.LoadingFrameComplete -= handler; registration.Dispose(); }, TaskContinuationOptions.ExecuteSynchronously); return(tcs.Task); }
public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, FrameEventHandler lParam);
public static extern Handle Construct( FrameEventHandler frameStarted, FrameEventHandler frameEnded, FrameEventHandler frameRenderingQueued);
public static bool capSetCallbackOnFrame(IntPtr lwnd, FrameEventHandler fpProc) { return SendMessage(lwnd, WM_CAP_SET_CALLBACK_FRAME, 0, fpProc); }
[DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, FrameEventHandler lParam);