diff --git a/CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.csproj b/CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.csproj index 0368233..98d0d63 100644 --- a/CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.csproj +++ b/CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.csproj @@ -1,7 +1,7 @@  - - + + Debug @@ -82,7 +82,7 @@ - - - + + + \ No newline at end of file diff --git a/CefSharp.MinimalExample.OffScreen/Program.cs b/CefSharp.MinimalExample.OffScreen/Program.cs index f538be0..47fbdff 100644 --- a/CefSharp.MinimalExample.OffScreen/Program.cs +++ b/CefSharp.MinimalExample.OffScreen/Program.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Threading; using CefSharp.OffScreen; namespace CefSharp.MinimalExample.OffScreen @@ -28,7 +29,7 @@ namespace CefSharp.MinimalExample.OffScreen // An event that is fired when the first page is finished loading. // This returns to us from another thread. - browser.FrameLoadEnd += BrowserFrameLoadEnd; + browser.LoadingStateChanged += BrowserLoadingStateChanged; // We have to wait for something, otherwise the process will exit too soon. Console.ReadKey(); @@ -38,39 +39,48 @@ namespace CefSharp.MinimalExample.OffScreen Cef.Shutdown(); } - private static void BrowserFrameLoadEnd(object sender, FrameLoadEndEventArgs e) + private static void BrowserLoadingStateChanged(object sender, LoadingStateChangedEventArgs e) { - // Check to ensure it is the main frame which has finished loading + // Check to see if loading is complete - this event is called twice, one when loading starts + // second time when it's finished // (rather than an iframe within the main frame). - if (e.IsMainFrame) + if (!e.IsLoading) { // Remove the load event handler, because we only want one snapshot of the initial page. - browser.FrameLoadEnd -= BrowserFrameLoadEnd; + browser.LoadingStateChanged -= BrowserLoadingStateChanged; - // Wait for the screenshot to be taken. - var task = browser.ScreenshotAsync(); - task.Wait(); + var scriptTask = browser.EvaluateScriptAsync("document.getElementById('lst-ib').value = 'CefSharp Was Here!'"); - // Make a file to save it to (e.g. C:\Users\jan\Desktop\CefSharp screenshot.png) - var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png"); + scriptTask.ContinueWith(t => + { + //Give the browser a little time to render + Thread.Sleep(500); + // Wait for the screenshot to be taken. + var task = browser.ScreenshotAsync(); + task.ContinueWith(x => + { + // Make a file to save it to (e.g. C:\Users\jan\Desktop\CefSharp screenshot.png) + var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png"); - Console.WriteLine(); - Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath); + Console.WriteLine(); + Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath); - // Save the Bitmap to the path. - // The image type is auto-detected via the ".png" extension. - task.Result.Save(screenshotPath); + // Save the Bitmap to the path. + // The image type is auto-detected via the ".png" extension. + task.Result.Save(screenshotPath); - // We no longer need the Bitmap. - // Dispose it to avoid keeping the memory alive. Especially important in 32-bit applications. - task.Result.Dispose(); + // We no longer need the Bitmap. + // Dispose it to avoid keeping the memory alive. Especially important in 32-bit applications. + task.Result.Dispose(); - Console.WriteLine("Screenshot saved. Launching your default image viewer..."); + Console.WriteLine("Screenshot saved. Launching your default image viewer..."); - // Tell Windows to launch the saved image. - Process.Start(screenshotPath); + // Tell Windows to launch the saved image. + Process.Start(screenshotPath); - Console.WriteLine("Image viewer launched. Press any key to exit."); + Console.WriteLine("Image viewer launched. Press any key to exit."); + }); + }); } } } diff --git a/CefSharp.MinimalExample.OffScreen/packages.config b/CefSharp.MinimalExample.OffScreen/packages.config index 5ec31d5..ae8469a 100644 --- a/CefSharp.MinimalExample.OffScreen/packages.config +++ b/CefSharp.MinimalExample.OffScreen/packages.config @@ -1,7 +1,7 @@  - - - - + + + + \ No newline at end of file diff --git a/CefSharp.MinimalExample.WinForms/BrowserForm.cs b/CefSharp.MinimalExample.WinForms/BrowserForm.cs index b9d60a2..e291a94 100644 --- a/CefSharp.MinimalExample.WinForms/BrowserForm.cs +++ b/CefSharp.MinimalExample.WinForms/BrowserForm.cs @@ -26,7 +26,7 @@ namespace CefSharp.MinimalExample.WinForms }; toolStripContainer.ContentPanel.Controls.Add(browser); - browser.NavStateChanged += OnBrowserNavStateChanged; + browser.LoadingStateChanged += OnLoadingStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; browser.StatusMessage += OnBrowserStatusMessage; browser.TitleChanged += OnBrowserTitleChanged; @@ -47,7 +47,7 @@ namespace CefSharp.MinimalExample.WinForms this.InvokeOnUiThreadIfRequired(() => statusLabel.Text = args.Value); } - private void OnBrowserNavStateChanged(object sender, NavStateChangedEventArgs args) + private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs args) { SetCanGoBack(args.CanGoBack); SetCanGoForward(args.CanGoForward); diff --git a/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj b/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj index e293fae..6854285 100644 --- a/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj +++ b/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj @@ -1,7 +1,7 @@  - - + + Debug AnyCPU @@ -98,7 +98,7 @@ - - - + + + \ No newline at end of file diff --git a/CefSharp.MinimalExample.WinForms/packages.config b/CefSharp.MinimalExample.WinForms/packages.config index 51af7fd..0cac287 100644 --- a/CefSharp.MinimalExample.WinForms/packages.config +++ b/CefSharp.MinimalExample.WinForms/packages.config @@ -1,7 +1,7 @@  - - - - + + + + \ No newline at end of file diff --git a/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj b/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj index 2c32d96..93a049f 100644 --- a/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj +++ b/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.csproj @@ -1,7 +1,7 @@  - - + + Debug @@ -132,9 +132,9 @@ - - - + + +