├── .gitattributes ├── .gitignore ├── CefSharp.MinimalExample.OffScreen ├── AsyncContext.cs ├── CefSharp.MinimalExample.OffScreen.csproj ├── CefSharp.MinimalExample.OffScreen.net472.csproj ├── CefSharp.MinimalExample.OffScreen.netcore.csproj ├── Program.PublishSingleFile.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── SingleThreadSynchronizationContext.cs ├── app.config ├── app.manifest ├── crash_reporter.cfg └── packages.config ├── CefSharp.MinimalExample.WinForms ├── BrowserForm.Designer.cs ├── BrowserForm.cs ├── BrowserForm.resx ├── CefSharp.MinimalExample.WinForms.csproj ├── CefSharp.MinimalExample.WinForms.net472.csproj ├── CefSharp.MinimalExample.WinForms.netcore.csproj ├── Controls │ └── ControlExtensions.cs ├── Program.PublishSingleFile.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Resources │ ├── chromium-256.png │ ├── nav_left_green.png │ ├── nav_plain_green.png │ ├── nav_plain_red.png │ └── nav_right_green.png ├── app.config ├── app.manifest ├── crash_reporter.cfg └── packages.config ├── CefSharp.MinimalExample.Wpf.HwndHost ├── App.config ├── App.xaml ├── App.xaml.cs ├── Behaviours │ ├── HoverLinkBehaviour.cs │ └── TextBoxBindingUpdateOnEnterBehaviour.cs ├── CefSharp.MinimalExample.Wpf.HwndHost.net472.csproj ├── CefSharp.MinimalExample.Wpf.HwndHost.netcore.csproj ├── Converter │ ├── EnvironmentConverter.cs │ └── TitleConverter.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Program.PublishSingleFile.cs ├── Properties │ └── AssemblyInfo.cs ├── app.manifest ├── chromium-256.ico └── crash_reporter.cfg ├── CefSharp.MinimalExample.Wpf ├── App.config ├── App.xaml ├── App.xaml.cs ├── Behaviours │ ├── HoverLinkBehaviour.cs │ └── TextBoxBindingUpdateOnEnterBehaviour.cs ├── CefSharp.MinimalExample.Wpf.csproj ├── CefSharp.MinimalExample.Wpf.net472.csproj ├── CefSharp.MinimalExample.Wpf.netcore.csproj ├── Converter │ ├── EnvironmentConverter.cs │ └── TitleConverter.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Program.PublishSingleFile.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── app.manifest ├── chromium-256.ico ├── crash_reporter.cfg └── packages.config ├── CefSharp.MinimalExample.net472.sln ├── CefSharp.MinimalExample.netcore.sln ├── CefSharp.MinimalExample.sln ├── LICENSE ├── NuGet.config ├── README.md └── UpdateNugetPackages.bat /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | [Bb]in.netcore/ 5 | [Oo]bj.netcore/ 6 | [Bb]in.net472/ 7 | [Oo]bj.net472/ 8 | 9 | # mstest test results 10 | TestResults 11 | 12 | ## Ignore Visual Studio temporary files, build results, and 13 | ## files generated by popular Visual Studio add-ons. 14 | 15 | # User-specific files 16 | *.suo 17 | *.user 18 | *.sln.docstates 19 | 20 | # Build results 21 | [Dd]ebug/ 22 | [Rr]elease/ 23 | x64/ 24 | *_i.c 25 | *_p.c 26 | *.ilk 27 | *.meta 28 | *.obj 29 | *.pch 30 | *.pdb 31 | *.pgc 32 | *.pgd 33 | *.rsp 34 | *.sbr 35 | *.tlb 36 | *.tli 37 | *.tlh 38 | *.tmp 39 | *.log 40 | *.vspscc 41 | *.vssscc 42 | .builds 43 | 44 | # Visual C++ cache files 45 | ipch/ 46 | *.aps 47 | *.ncb 48 | *.opensdf 49 | *.sdf 50 | 51 | # Visual Studio profiler 52 | *.psess 53 | *.vsp 54 | *.vspx 55 | 56 | # Guidance Automation Toolkit 57 | *.gpState 58 | 59 | # ReSharper is a .NET coding add-in 60 | _ReSharper* 61 | 62 | # NCrunch 63 | *.ncrunch* 64 | .*crunch*.local.xml 65 | 66 | # Installshield output folder 67 | [Ee]xpress 68 | 69 | # DocProject is a documentation generator add-in 70 | DocProject/buildhelp/ 71 | DocProject/Help/*.HxT 72 | DocProject/Help/*.HxC 73 | DocProject/Help/*.hhc 74 | DocProject/Help/*.hhk 75 | DocProject/Help/*.hhp 76 | DocProject/Help/Html2 77 | DocProject/Help/html 78 | 79 | # Click-Once directory 80 | publish 81 | 82 | # Publish Web Output 83 | *.Publish.xml 84 | 85 | # NuGet Packages Directory 86 | packages 87 | 88 | # Windows Azure Build Output 89 | csx 90 | *.build.csdef 91 | 92 | # Windows Store app package directory 93 | AppPackages/ 94 | 95 | # Others 96 | [Bb]in 97 | [Oo]bj 98 | sql 99 | TestResults 100 | [Tt]est[Rr]esult* 101 | *.Cache 102 | ClientBin 103 | [Ss]tyle[Cc]op.* 104 | ~$* 105 | *.dbmdl 106 | Generated_Code #added for RIA/Silverlight projects 107 | 108 | # Backup & report files from converting an old project file to a newer 109 | # Visual Studio version. Backup files are not needed, because we have git ;-) 110 | _UpgradeReport_Files/ 111 | Backup*/ 112 | UpgradeLog*.XML 113 | /.vs 114 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/AsyncContext.cs: -------------------------------------------------------------------------------- 1 | /// https://devblogs.microsoft.com/pfxteam/await-synchronizationcontext-and-console-apps/ 2 | 3 | using System; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace CefSharp.MinimalExample.OffScreen 8 | { 9 | public static class AsyncContext 10 | { 11 | public static void Run(Func func) 12 | { 13 | var prevCtx = SynchronizationContext.Current; 14 | 15 | try 16 | { 17 | var syncCtx = new SingleThreadSynchronizationContext(); 18 | 19 | SynchronizationContext.SetSynchronizationContext(syncCtx); 20 | 21 | var t = func(); 22 | 23 | t.ContinueWith(delegate 24 | { 25 | syncCtx.Complete(); 26 | }, TaskScheduler.Default); 27 | 28 | syncCtx.RunOnCurrentThread(); 29 | 30 | t.GetAwaiter().GetResult(); 31 | } 32 | finally 33 | { 34 | SynchronizationContext.SetSynchronizationContext(prevCtx); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | Debug 9 | x86 10 | {A4DEB90C-A529-4A93-ACE3-226A39EFCB00} 11 | Exe 12 | Properties 13 | CefSharp.MinimalExample.OffScreen 14 | CefSharp.MinimalExample.OffScreen 15 | v4.6.2 16 | 512 17 | 18 | 19 | ..\ 20 | 21 | 22 | true 23 | 24 | 25 | true 26 | bin\x64\Debug\net452\ 27 | DEBUG;TRACE 28 | full 29 | x64 30 | prompt 31 | MinimumRecommendedRules.ruleset 32 | false 33 | 34 | 35 | bin\x64\Release\net452\ 36 | TRACE 37 | true 38 | pdbonly 39 | x64 40 | prompt 41 | MinimumRecommendedRules.ruleset 42 | false 43 | 44 | 45 | true 46 | bin\x86\Debug\net452\ 47 | DEBUG;TRACE 48 | full 49 | x86 50 | prompt 51 | MinimumRecommendedRules.ruleset 52 | false 53 | 54 | 55 | bin\x86\Release\net452\ 56 | TRACE 57 | true 58 | pdbonly 59 | x86 60 | prompt 61 | MinimumRecommendedRules.ruleset 62 | false 63 | 64 | 65 | true 66 | bin\AnyCPU\Debug\net452\ 67 | DEBUG;TRACE;ANYCPU 68 | full 69 | AnyCPU 70 | prompt 71 | MinimumRecommendedRules.ruleset 72 | false 73 | 74 | 75 | bin\AnyCPU\Release\net452\ 76 | TRACE;ANYCPU 77 | true 78 | pdbonly 79 | AnyCPU 80 | prompt 81 | MinimumRecommendedRules.ruleset 82 | false 83 | 84 | 85 | app.manifest 86 | 87 | 88 | CefSharp.MinimalExample.OffScreen.Program 89 | 90 | 91 | 92 | ..\packages\CefSharp.Common.136.1.40\lib\net462\CefSharp.dll 93 | True 94 | 95 | 96 | ..\packages\CefSharp.Common.136.1.40\lib\net462\CefSharp.Core.dll 97 | True 98 | 99 | 100 | ..\packages\CefSharp.OffScreen.136.1.40\lib\net462\CefSharp.OffScreen.dll 101 | True 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | PreserveNewest 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.net472.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 | obj.net472\ 7 | bin.net472\ 8 | 9 | 10 | 11 | 12 | 13 | Exe 14 | net472 15 | CefSharp.MinimalExample.OffScreen 16 | app.manifest 17 | false 18 | x86;x64;AnyCPU 19 | {A4DEB90C-A529-4A93-ACE3-226A39EFCB00} 20 | CefSharp.MinimalExample.OffScreen.Program 21 | 22 | 23 | 24 | $(DefineConstants);ANYCPU 25 | 29 | AnyCPU 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | PreserveNewest 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.netcore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 | obj.netcore\ 7 | bin.netcore\ 8 | 9 | 10 | 11 | 12 | 13 | Exe 14 | netcoreapp3.1;net5.0-windows 15 | $(TargetFrameworks);net6.0-windows 16 | $(TargetFrameworks);net7.0-windows 17 | $(TargetFrameworks);net8.0-windows 18 | CefSharp.MinimalExample.OffScreen 19 | app.manifest 20 | false 21 | x86;x64;AnyCPU 22 | 26 | Major 27 | CefSharp.MinimalExample.OffScreen.Program 28 | 29 | 30 | 35 | 36 | 37 | true 38 | 39 | true 40 | 41 | 42 | CefSharp.MinimalExample.OffScreen.ProgramPublishSingleFile 43 | 44 | 45 | 46 | win-x86 47 | false 48 | 49 | 50 | 51 | win-x64 52 | false 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | PreserveNewest 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/Program.PublishSingleFile.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2021 The CefSharp Authors. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 4 | 5 | using CefSharp.OffScreen; 6 | using System; 7 | using System.Diagnostics; 8 | using System.IO; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace CefSharp.MinimalExample.OffScreen 13 | { 14 | /// 15 | /// For .Net 5.0/6.0/7.0 Publishing Single File exe requires using your own applications executable to 16 | /// act as the BrowserSubProcess. See https://github.com/cefsharp/CefSharp/issues/3407 17 | /// for further details. for the default main application entry point 18 | /// 19 | public class ProgramPublishSingleFile 20 | { 21 | private static ChromiumWebBrowser browser; 22 | 23 | public static int Main(string[] args) 24 | { 25 | //Self Hosting the BrowserSucProcess 26 | var exitCode = CefSharp.BrowserSubprocess.SelfHost.Main(args); 27 | 28 | if (exitCode >= 0) 29 | { 30 | return exitCode; 31 | } 32 | 33 | const string testUrl = "https://www.google.com/"; 34 | 35 | Console.WriteLine("This example application will load {0}, take a screenshot, and save it to your desktop.", testUrl); 36 | Console.WriteLine("You may see Chromium debugging output, please wait..."); 37 | Console.WriteLine(); 38 | 39 | var settings = new CefSettings() 40 | { 41 | //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data 42 | CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"), 43 | BrowserSubprocessPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 44 | }; 45 | 46 | //Perform dependency check to make sure all relevant resources are in our output directory. 47 | Cef.Initialize(settings, performDependencyCheck: false); 48 | 49 | // Create the offscreen Chromium browser. 50 | browser = new ChromiumWebBrowser(testUrl); 51 | 52 | // An event that is fired when the first page is finished loading. 53 | // This returns to us from another thread. 54 | browser.LoadingStateChanged += BrowserLoadingStateChanged; 55 | 56 | // We have to wait for something, otherwise the process will exit too soon. 57 | Console.ReadKey(); 58 | 59 | // Clean up Chromium objects. You need to call this in your application otherwise 60 | // you will get a crash when closing. 61 | Cef.Shutdown(); 62 | 63 | return 0; 64 | } 65 | 66 | private static void BrowserLoadingStateChanged(object sender, LoadingStateChangedEventArgs e) 67 | { 68 | // Check to see if loading is complete - this event is called twice, one when loading starts 69 | // second time when it's finished 70 | // (rather than an iframe within the main frame). 71 | if (!e.IsLoading) 72 | { 73 | // Remove the load event handler, because we only want one snapshot of the initial page. 74 | browser.LoadingStateChanged -= BrowserLoadingStateChanged; 75 | 76 | var scriptTask = browser.EvaluateScriptAsync("document.querySelector('[name=q]').value = 'CefSharp Was Here!'"); 77 | 78 | scriptTask.ContinueWith(t => 79 | { 80 | //Give the browser a little time to render 81 | Thread.Sleep(500); 82 | // Wait for the screenshot to be taken. 83 | var task = browser.CaptureScreenshotAsync(); 84 | task.ContinueWith(x => 85 | { 86 | // Make a file to save it to (e.g. C:\Users\jan\Desktop\CefSharp screenshot.png) 87 | var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png"); 88 | 89 | Console.WriteLine(); 90 | Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath); 91 | 92 | var bitmapAsByteArray = x.Result; 93 | 94 | // Save the Bitmap to the path. 95 | File.WriteAllBytes(screenshotPath, bitmapAsByteArray); 96 | 97 | Console.WriteLine("Screenshot saved. Launching your default image viewer..."); 98 | 99 | // Tell Windows to launch the saved image. 100 | Process.Start(new ProcessStartInfo(screenshotPath) 101 | { 102 | // UseShellExecute is false by default on .NET Core. 103 | UseShellExecute = true 104 | }); 105 | 106 | Console.WriteLine("Image viewer launched. Press any key to exit."); 107 | }, TaskScheduler.Default); 108 | }); 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2010-2021 The CefSharp Authors. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 4 | 5 | using CefSharp.OffScreen; 6 | using System; 7 | using System.Diagnostics; 8 | using System.IO; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace CefSharp.MinimalExample.OffScreen 13 | { 14 | /// 15 | /// CefSharp.OffScreen Minimal Example 16 | /// 17 | public static class Program 18 | { 19 | /// 20 | /// Asynchronous demo using CefSharp.OffScreen 21 | /// Loads google.com, uses javascript to fill out the search box then takes a screenshot which is opened 22 | /// in the default image viewer. 23 | /// For a synchronous demo see below. 24 | /// 25 | /// args 26 | /// exit code 27 | public static int Main(string[] args) 28 | { 29 | #if ANYCPU 30 | //Only required for PlatformTarget of AnyCPU 31 | CefRuntime.SubscribeAnyCpuAssemblyResolver(); 32 | #endif 33 | 34 | const string testUrl = "https://www.google.com/"; 35 | 36 | Console.WriteLine("This example application will load {0}, take a screenshot, and save it to your desktop.", testUrl); 37 | Console.WriteLine("You may see Chromium debugging output, please wait..."); 38 | Console.WriteLine(); 39 | 40 | //Console apps don't have a SynchronizationContext, so to ensure our await calls continue on the main thread we use a super simple implementation from 41 | //https://devblogs.microsoft.com/pfxteam/await-synchronizationcontext-and-console-apps/ 42 | //Continuations will happen on the main thread. Cef.Initialize/Cef.Shutdown must be called on the same Thread. 43 | //The Nito.AsyncEx.Context Nuget package has a more advanced implementation 44 | //should you wish to use a pre-build implementation. 45 | //https://github.com/StephenCleary/AsyncEx/blob/8a73d0467d40ca41f9f9cf827c7a35702243abb8/doc/AsyncContext.md#console-example-using-asynccontext 46 | //NOTE: This is only required if you use await 47 | 48 | AsyncContext.Run(async delegate 49 | { 50 | var settings = new CefSettings() 51 | { 52 | //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data 53 | CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache") 54 | }; 55 | 56 | //Perform dependency check to make sure all relevant resources are in our output directory. 57 | var success = await Cef.InitializeAsync(settings, performDependencyCheck: true, browserProcessHandler: null); 58 | 59 | if (!success) 60 | { 61 | var exitCode = Cef.GetExitCode(); 62 | 63 | throw new Exception($"Cef.Initialize failed with {exitCode}, check the log file for more details."); 64 | } 65 | 66 | // Create the CefSharp.OffScreen.ChromiumWebBrowser instance 67 | using (var browser = new ChromiumWebBrowser(testUrl)) 68 | { 69 | var initialLoadResponse = await browser.WaitForInitialLoadAsync(); 70 | 71 | if (!initialLoadResponse.Success) 72 | { 73 | throw new Exception(string.Format("Page load failed with ErrorCode:{0}, HttpStatusCode:{1}", initialLoadResponse.ErrorCode, initialLoadResponse.HttpStatusCode)); 74 | } 75 | 76 | _ = await browser.EvaluateScriptAsync("document.querySelector('[name=q]').value = 'CefSharp Was Here!'"); 77 | 78 | //Give the browser a little time to render 79 | await Task.Delay(500); 80 | // Wait for the screenshot to be taken. 81 | var bitmapAsByteArray = await browser.CaptureScreenshotAsync(); 82 | 83 | // File path to save our screenshot e.g. C:\Users\{username}\Desktop\CefSharp screenshot.png 84 | var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png"); 85 | 86 | Console.WriteLine(); 87 | Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath); 88 | 89 | File.WriteAllBytes(screenshotPath, bitmapAsByteArray); 90 | 91 | Console.WriteLine("Screenshot saved. Launching your default image viewer..."); 92 | 93 | // Tell Windows to launch the saved image. 94 | Process.Start(new ProcessStartInfo(screenshotPath) 95 | { 96 | // UseShellExecute is false by default on .NET Core. 97 | UseShellExecute = true 98 | }); 99 | 100 | Console.WriteLine("Image viewer launched. Press any key to exit."); 101 | } 102 | 103 | // Wait for user to press a key before exit 104 | Console.ReadKey(); 105 | 106 | // Clean up Chromium objects. You need to call this in your application otherwise 107 | // you will get a crash when closing. 108 | Cef.Shutdown(); 109 | }); 110 | 111 | return 0; 112 | } 113 | 114 | /// 115 | /// Synchronous demo using CefSharp.OffScreen 116 | /// Loads google.com, uses javascript to fill out the search box then takes a screenshot which is opened 117 | /// in the default image viewer. 118 | /// For a asynchronous demo see above. 119 | /// To use this demo simply delete the method and rename this method to Main. 120 | /// 121 | /// args 122 | /// exit code 123 | public static int MainSync(string[] args) 124 | { 125 | #if ANYCPU 126 | //Only required for PlatformTarget of AnyCPU 127 | CefRuntime.SubscribeAnyCpuAssemblyResolver(); 128 | #endif 129 | 130 | const string testUrl = "https://www.google.com/"; 131 | 132 | Console.WriteLine("This example application will load {0}, take a screenshot, and save it to your desktop.", testUrl); 133 | Console.WriteLine("You may see Chromium debugging output, please wait..."); 134 | Console.WriteLine(); 135 | 136 | var settings = new CefSettings() 137 | { 138 | //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data 139 | CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache") 140 | }; 141 | 142 | //Perform dependency check to make sure all relevant resources are in our output directory. 143 | Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); 144 | 145 | // Create the offscreen Chromium browser. 146 | var browser = new ChromiumWebBrowser(testUrl); 147 | 148 | EventHandler handler = null; 149 | 150 | handler = (s, e) => 151 | { 152 | // Check to see if loading is complete - this event is called twice, one when loading starts 153 | // second time when it's finished 154 | if (!e.IsLoading) 155 | { 156 | // Remove the load event handler, because we only want one snapshot of the page. 157 | browser.LoadingStateChanged -= handler; 158 | 159 | var scriptTask = browser.EvaluateScriptAsync("document.querySelector('[name=q]').value = 'CefSharp Was Here!'"); 160 | 161 | scriptTask.ContinueWith(t => 162 | { 163 | if(!t.Result.Success) 164 | { 165 | throw new Exception("EvaluateScriptAsync failed:" + t.Result.Message); 166 | } 167 | 168 | //Give the browser a little time to render 169 | Thread.Sleep(500); 170 | // Wait for the screenshot to be taken. 171 | var task = browser.CaptureScreenshotAsync(); 172 | task.ContinueWith(x => 173 | { 174 | // File path to save our screenshot e.g. C:\Users\{username}\Desktop\CefSharp screenshot.png 175 | var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png"); 176 | 177 | Console.WriteLine(); 178 | Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath); 179 | 180 | var bitmapAsByteArray = x.Result; 181 | 182 | // Save the Bitmap to the path. 183 | File.WriteAllBytes(screenshotPath, bitmapAsByteArray); 184 | 185 | Console.WriteLine("Screenshot saved. Launching your default image viewer..."); 186 | 187 | // Tell Windows to launch the saved image. 188 | Process.Start(new ProcessStartInfo(screenshotPath) 189 | { 190 | // UseShellExecute is false by default on .NET Core. 191 | UseShellExecute = true 192 | }); 193 | 194 | Console.WriteLine("Image viewer launched. Press any key to exit."); 195 | }, TaskScheduler.Default); 196 | }); 197 | } 198 | }; 199 | 200 | // An event that is fired when the first page is finished loading. 201 | // This returns to us from another thread. 202 | browser.LoadingStateChanged += handler; 203 | 204 | // We have to wait for something, otherwise the process will exit too soon. 205 | Console.ReadKey(); 206 | 207 | // Clean up Chromium objects. You need to call this in your application otherwise 208 | // you will get a crash when closing. 209 | //The ChromiumWebBrowser instance will be disposed 210 | Cef.Shutdown(); 211 | 212 | return 0; 213 | } 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("CefSharp.MinimalExample.OffScreen")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("CefSharp.MinimalExample.OffScreen")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // Version information for an assembly consists of the following four values: 22 | // 23 | // Major Version 24 | // Minor Version 25 | // Build Number 26 | // Revision 27 | // 28 | // You can specify all the values or you can default the Build and Revision Numbers 29 | // by using the '*' as shown below: 30 | // [assembly: AssemblyVersion("1.0.*")] 31 | [assembly: AssemblyVersion("1.0.0.0")] 32 | [assembly: AssemblyFileVersion("1.0.0.0")] 33 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/SingleThreadSynchronizationContext.cs: -------------------------------------------------------------------------------- 1 | /// https://devblogs.microsoft.com/pfxteam/await-synchronizationcontext-and-console-apps/ 2 | 3 | using System.Collections.Concurrent; 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | 7 | namespace CefSharp.MinimalExample.OffScreen 8 | { 9 | public sealed class SingleThreadSynchronizationContext : SynchronizationContext 10 | { 11 | private readonly BlockingCollection> queue = 12 | new BlockingCollection>(); 13 | 14 | public override void Post(SendOrPostCallback d, object state) 15 | { 16 | queue.Add(new KeyValuePair(d, state)); 17 | } 18 | 19 | public void RunOnCurrentThread() 20 | { 21 | while (queue.TryTake(out var workItem, Timeout.Infinite)) 22 | { 23 | workItem.Key(workItem.Value); 24 | } 25 | } 26 | 27 | public void Complete() 28 | { 29 | queue.CompleteAdding(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 9 | 10 | 11 | 12 | 13 | 14 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/crash_reporter.cfg: -------------------------------------------------------------------------------- 1 | # Crash reporting is configured using an INI-style config file named 2 | # "crash_reporter.cfg". This file must be placed next to 3 | # the main application executable. 4 | # Comments start with a hash character and must be on their own line. 5 | # See https://bitbucket.org/chromiumembedded/cef/wiki/CrashReporting.md 6 | # for further details 7 | 8 | [Config] 9 | ProductName=CefSharp.MinimalExample.OffScreen 10 | ProductVersion=1.0.0 11 | AppName=CefSharp.MinimalExample 12 | ExternalHandler=CefSharp.BrowserSubprocess.exe -------------------------------------------------------------------------------- /CefSharp.MinimalExample.OffScreen/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/BrowserForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace CefSharp.MinimalExample.WinForms 2 | { 3 | partial class BrowserForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BrowserForm)); 32 | this.toolStripContainer = new System.Windows.Forms.ToolStripContainer(); 33 | this.statusLabel = new System.Windows.Forms.Label(); 34 | this.outputLabel = new System.Windows.Forms.Label(); 35 | this.toolStrip1 = new System.Windows.Forms.ToolStrip(); 36 | this.backButton = new System.Windows.Forms.ToolStripButton(); 37 | this.forwardButton = new System.Windows.Forms.ToolStripButton(); 38 | this.urlTextBox = new System.Windows.Forms.ToolStripTextBox(); 39 | this.goButton = new System.Windows.Forms.ToolStripButton(); 40 | this.menuStrip1 = new System.Windows.Forms.MenuStrip(); 41 | this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 42 | this.showDevToolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 43 | this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 44 | this.toolStripContainer.ContentPanel.SuspendLayout(); 45 | this.toolStripContainer.TopToolStripPanel.SuspendLayout(); 46 | this.toolStripContainer.SuspendLayout(); 47 | this.toolStrip1.SuspendLayout(); 48 | this.menuStrip1.SuspendLayout(); 49 | this.SuspendLayout(); 50 | // 51 | // toolStripContainer 52 | // 53 | // 54 | // toolStripContainer.ContentPanel 55 | // 56 | this.toolStripContainer.ContentPanel.Controls.Add(this.statusLabel); 57 | this.toolStripContainer.ContentPanel.Controls.Add(this.outputLabel); 58 | this.toolStripContainer.ContentPanel.Size = new System.Drawing.Size(730, 441); 59 | this.toolStripContainer.Dock = System.Windows.Forms.DockStyle.Fill; 60 | this.toolStripContainer.LeftToolStripPanelVisible = false; 61 | this.toolStripContainer.Location = new System.Drawing.Point(0, 24); 62 | this.toolStripContainer.Name = "toolStripContainer"; 63 | this.toolStripContainer.RightToolStripPanelVisible = false; 64 | this.toolStripContainer.Size = new System.Drawing.Size(730, 466); 65 | this.toolStripContainer.TabIndex = 0; 66 | this.toolStripContainer.Text = "toolStripContainer1"; 67 | // 68 | // toolStripContainer.TopToolStripPanel 69 | // 70 | this.toolStripContainer.TopToolStripPanel.Controls.Add(this.toolStrip1); 71 | // 72 | // statusLabel 73 | // 74 | this.statusLabel.Dock = System.Windows.Forms.DockStyle.Bottom; 75 | this.statusLabel.Location = new System.Drawing.Point(0, 415); 76 | this.statusLabel.Name = "statusLabel"; 77 | this.statusLabel.Size = new System.Drawing.Size(730, 13); 78 | this.statusLabel.TabIndex = 1; 79 | // 80 | // outputLabel 81 | // 82 | this.outputLabel.Dock = System.Windows.Forms.DockStyle.Bottom; 83 | this.outputLabel.Location = new System.Drawing.Point(0, 428); 84 | this.outputLabel.Name = "outputLabel"; 85 | this.outputLabel.Size = new System.Drawing.Size(730, 13); 86 | this.outputLabel.TabIndex = 0; 87 | // 88 | // toolStrip1 89 | // 90 | this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None; 91 | this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; 92 | this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 93 | this.backButton, 94 | this.forwardButton, 95 | this.urlTextBox, 96 | this.goButton}); 97 | this.toolStrip1.Location = new System.Drawing.Point(0, 0); 98 | this.toolStrip1.Name = "toolStrip1"; 99 | this.toolStrip1.Padding = new System.Windows.Forms.Padding(0); 100 | this.toolStrip1.Size = new System.Drawing.Size(730, 25); 101 | this.toolStrip1.Stretch = true; 102 | this.toolStrip1.TabIndex = 0; 103 | this.toolStrip1.Layout += new System.Windows.Forms.LayoutEventHandler(this.HandleToolStripLayout); 104 | // 105 | // backButton 106 | // 107 | this.backButton.Enabled = false; 108 | this.backButton.Image = global::CefSharp.MinimalExample.WinForms.Properties.Resources.nav_left_green; 109 | this.backButton.ImageTransparentColor = System.Drawing.Color.Magenta; 110 | this.backButton.Name = "backButton"; 111 | this.backButton.Size = new System.Drawing.Size(52, 22); 112 | this.backButton.Text = "Back"; 113 | this.backButton.Click += new System.EventHandler(this.BackButtonClick); 114 | // 115 | // forwardButton 116 | // 117 | this.forwardButton.Enabled = false; 118 | this.forwardButton.Image = global::CefSharp.MinimalExample.WinForms.Properties.Resources.nav_right_green; 119 | this.forwardButton.ImageTransparentColor = System.Drawing.Color.Magenta; 120 | this.forwardButton.Name = "forwardButton"; 121 | this.forwardButton.Size = new System.Drawing.Size(70, 22); 122 | this.forwardButton.Text = "Forward"; 123 | this.forwardButton.Click += new System.EventHandler(this.ForwardButtonClick); 124 | // 125 | // urlTextBox 126 | // 127 | this.urlTextBox.AutoSize = false; 128 | this.urlTextBox.Name = "urlTextBox"; 129 | this.urlTextBox.Size = new System.Drawing.Size(500, 25); 130 | this.urlTextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UrlTextBoxKeyUp); 131 | // 132 | // goButton 133 | // 134 | this.goButton.Image = global::CefSharp.MinimalExample.WinForms.Properties.Resources.nav_plain_green; 135 | this.goButton.ImageTransparentColor = System.Drawing.Color.Magenta; 136 | this.goButton.Name = "goButton"; 137 | this.goButton.Size = new System.Drawing.Size(42, 22); 138 | this.goButton.Text = "Go"; 139 | this.goButton.Click += new System.EventHandler(this.GoButtonClick); 140 | // 141 | // menuStrip1 142 | // 143 | this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 144 | this.fileToolStripMenuItem}); 145 | this.menuStrip1.Location = new System.Drawing.Point(0, 0); 146 | this.menuStrip1.Name = "menuStrip1"; 147 | this.menuStrip1.Size = new System.Drawing.Size(730, 24); 148 | this.menuStrip1.TabIndex = 1; 149 | this.menuStrip1.Text = "menuStrip1"; 150 | // 151 | // fileToolStripMenuItem 152 | // 153 | this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 154 | this.showDevToolsToolStripMenuItem, 155 | this.exitToolStripMenuItem}); 156 | this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; 157 | this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); 158 | this.fileToolStripMenuItem.Text = "File"; 159 | // 160 | // showDevToolsToolStripMenuItem 161 | // 162 | this.showDevToolsToolStripMenuItem.Name = "showDevToolsToolStripMenuItem"; 163 | this.showDevToolsToolStripMenuItem.Size = new System.Drawing.Size(154, 22); 164 | this.showDevToolsToolStripMenuItem.Text = "Show DevTools"; 165 | this.showDevToolsToolStripMenuItem.Click += new System.EventHandler(this.ShowDevToolsMenuItemClick); 166 | // 167 | // exitToolStripMenuItem 168 | // 169 | this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; 170 | this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22); 171 | this.exitToolStripMenuItem.Text = "Exit"; 172 | this.exitToolStripMenuItem.Click += new System.EventHandler(this.ExitMenuItemClick); 173 | // 174 | // BrowserForm 175 | // 176 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 177 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 178 | this.ClientSize = new System.Drawing.Size(730, 490); 179 | this.Controls.Add(this.toolStripContainer); 180 | this.Controls.Add(this.menuStrip1); 181 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 182 | this.MainMenuStrip = this.menuStrip1; 183 | this.Name = "BrowserForm"; 184 | this.Text = "BrowserForm"; 185 | this.toolStripContainer.ContentPanel.ResumeLayout(false); 186 | this.toolStripContainer.ContentPanel.PerformLayout(); 187 | this.toolStripContainer.TopToolStripPanel.ResumeLayout(false); 188 | this.toolStripContainer.TopToolStripPanel.PerformLayout(); 189 | this.toolStripContainer.ResumeLayout(false); 190 | this.toolStripContainer.PerformLayout(); 191 | this.toolStrip1.ResumeLayout(false); 192 | this.toolStrip1.PerformLayout(); 193 | this.menuStrip1.ResumeLayout(false); 194 | this.menuStrip1.PerformLayout(); 195 | this.ResumeLayout(false); 196 | this.PerformLayout(); 197 | 198 | } 199 | 200 | #endregion 201 | 202 | private System.Windows.Forms.ToolStripContainer toolStripContainer; 203 | private System.Windows.Forms.ToolStrip toolStrip1; 204 | private System.Windows.Forms.ToolStripButton backButton; 205 | private System.Windows.Forms.ToolStripButton forwardButton; 206 | private System.Windows.Forms.ToolStripTextBox urlTextBox; 207 | private System.Windows.Forms.ToolStripButton goButton; 208 | private System.Windows.Forms.MenuStrip menuStrip1; 209 | private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; 210 | private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; 211 | private System.Windows.Forms.Label outputLabel; 212 | private System.Windows.Forms.Label statusLabel; 213 | private System.Windows.Forms.ToolStripMenuItem showDevToolsToolStripMenuItem; 214 | 215 | } 216 | } -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/BrowserForm.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2010-2015 The CefSharp Authors. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 4 | 5 | using CefSharp.DevTools.IO; 6 | using CefSharp.MinimalExample.WinForms.Controls; 7 | using CefSharp.WinForms; 8 | using System; 9 | using System.Net; 10 | using System.Windows.Forms; 11 | 12 | namespace CefSharp.MinimalExample.WinForms 13 | { 14 | public partial class BrowserForm : Form 15 | { 16 | #if DEBUG 17 | private const string Build = "Debug"; 18 | #else 19 | private const string Build = "Release"; 20 | #endif 21 | private readonly string title = "CefSharp.MinimalExample.WinForms (" + Build + ")"; 22 | private readonly ChromiumWebBrowser browser; 23 | 24 | public BrowserForm() 25 | { 26 | InitializeComponent(); 27 | 28 | Text = title; 29 | WindowState = FormWindowState.Maximized; 30 | 31 | browser = new ChromiumWebBrowser("www.google.com"); 32 | toolStripContainer.ContentPanel.Controls.Add(browser); 33 | 34 | browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged; 35 | browser.LoadingStateChanged += OnLoadingStateChanged; 36 | browser.ConsoleMessage += OnBrowserConsoleMessage; 37 | browser.StatusMessage += OnBrowserStatusMessage; 38 | browser.TitleChanged += OnBrowserTitleChanged; 39 | browser.AddressChanged += OnBrowserAddressChanged; 40 | browser.LoadError += OnBrowserLoadError; 41 | 42 | var version = string.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", 43 | Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion); 44 | 45 | #if NETCOREAPP 46 | // .NET Core 47 | var environment = string.Format("Environment: {0}, Runtime: {1}", 48 | System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(), 49 | System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription); 50 | #else 51 | // .NET Framework 52 | var bitness = Environment.Is64BitProcess ? "x64" : "x86"; 53 | var environment = String.Format("Environment: {0}", bitness); 54 | #endif 55 | 56 | DisplayOutput(string.Format("{0}, {1}", version, environment)); 57 | } 58 | 59 | private void OnBrowserLoadError(object sender, LoadErrorEventArgs e) 60 | { 61 | //Actions that trigger a download will raise an aborted error. 62 | //Aborted is generally safe to ignore 63 | if (e.ErrorCode == CefErrorCode.Aborted) 64 | { 65 | return; 66 | } 67 | 68 | var errorHtml = string.Format("

Failed to load URL {0} with error {1} ({2}).

", 69 | e.FailedUrl, e.ErrorText, e.ErrorCode); 70 | 71 | _ = e.Browser.SetMainFrameDocumentContentAsync(errorHtml); 72 | 73 | //AddressChanged isn't called for failed Urls so we need to manually update the Url TextBox 74 | this.InvokeOnUiThreadIfRequired(() => urlTextBox.Text = e.FailedUrl); 75 | } 76 | 77 | private void OnIsBrowserInitializedChanged(object sender, EventArgs e) 78 | { 79 | var b = ((ChromiumWebBrowser)sender); 80 | 81 | this.InvokeOnUiThreadIfRequired(() => b.Focus()); 82 | } 83 | 84 | private void OnBrowserConsoleMessage(object sender, ConsoleMessageEventArgs args) 85 | { 86 | DisplayOutput(string.Format("Line: {0}, Source: {1}, Message: {2}", args.Line, args.Source, args.Message)); 87 | } 88 | 89 | private void OnBrowserStatusMessage(object sender, StatusMessageEventArgs args) 90 | { 91 | this.InvokeOnUiThreadIfRequired(() => statusLabel.Text = args.Value); 92 | } 93 | 94 | private void OnLoadingStateChanged(object sender, LoadingStateChangedEventArgs args) 95 | { 96 | SetCanGoBack(args.CanGoBack); 97 | SetCanGoForward(args.CanGoForward); 98 | 99 | this.InvokeOnUiThreadIfRequired(() => SetIsLoading(!args.CanReload)); 100 | } 101 | 102 | private void OnBrowserTitleChanged(object sender, TitleChangedEventArgs args) 103 | { 104 | this.InvokeOnUiThreadIfRequired(() => Text = title + " - " + args.Title); 105 | } 106 | 107 | private void OnBrowserAddressChanged(object sender, AddressChangedEventArgs args) 108 | { 109 | this.InvokeOnUiThreadIfRequired(() => urlTextBox.Text = args.Address); 110 | } 111 | 112 | private void SetCanGoBack(bool canGoBack) 113 | { 114 | this.InvokeOnUiThreadIfRequired(() => backButton.Enabled = canGoBack); 115 | } 116 | 117 | private void SetCanGoForward(bool canGoForward) 118 | { 119 | this.InvokeOnUiThreadIfRequired(() => forwardButton.Enabled = canGoForward); 120 | } 121 | 122 | private void SetIsLoading(bool isLoading) 123 | { 124 | goButton.Text = isLoading ? 125 | "Stop" : 126 | "Go"; 127 | goButton.Image = isLoading ? 128 | Properties.Resources.nav_plain_red : 129 | Properties.Resources.nav_plain_green; 130 | 131 | HandleToolStripLayout(); 132 | } 133 | 134 | public void DisplayOutput(string output) 135 | { 136 | this.InvokeOnUiThreadIfRequired(() => outputLabel.Text = output); 137 | } 138 | 139 | private void HandleToolStripLayout(object sender, LayoutEventArgs e) 140 | { 141 | HandleToolStripLayout(); 142 | } 143 | 144 | private void HandleToolStripLayout() 145 | { 146 | var width = toolStrip1.Width; 147 | foreach (ToolStripItem item in toolStrip1.Items) 148 | { 149 | if (item != urlTextBox) 150 | { 151 | width -= item.Width - item.Margin.Horizontal; 152 | } 153 | } 154 | urlTextBox.Width = Math.Max(0, width - urlTextBox.Margin.Horizontal - 18); 155 | } 156 | 157 | private void ExitMenuItemClick(object sender, EventArgs e) 158 | { 159 | browser.Dispose(); 160 | Cef.Shutdown(); 161 | Close(); 162 | } 163 | 164 | private void GoButtonClick(object sender, EventArgs e) 165 | { 166 | LoadUrl(urlTextBox.Text); 167 | } 168 | 169 | private void BackButtonClick(object sender, EventArgs e) 170 | { 171 | browser.Back(); 172 | } 173 | 174 | private void ForwardButtonClick(object sender, EventArgs e) 175 | { 176 | browser.Forward(); 177 | } 178 | 179 | private void UrlTextBoxKeyUp(object sender, KeyEventArgs e) 180 | { 181 | if (e.KeyCode != Keys.Enter) 182 | { 183 | return; 184 | } 185 | 186 | LoadUrl(urlTextBox.Text); 187 | } 188 | 189 | private void LoadUrl(string urlString) 190 | { 191 | // No action unless the user types in some sort of url 192 | if (string.IsNullOrEmpty(urlString)) 193 | { 194 | return; 195 | } 196 | 197 | Uri url; 198 | 199 | var success = Uri.TryCreate(urlString, UriKind.RelativeOrAbsolute, out url); 200 | 201 | // Basic parsing was a success, now we need to perform additional checks 202 | if (success) 203 | { 204 | // Load absolute urls directly. 205 | // You may wish to validate the scheme is http/https 206 | // e.g. url.Scheme == Uri.UriSchemeHttp || url.Scheme == Uri.UriSchemeHttps 207 | if (url.IsAbsoluteUri) 208 | { 209 | browser.LoadUrl(urlString); 210 | 211 | return; 212 | } 213 | 214 | // Relative Url 215 | // We'll do some additional checks to see if we can load the Url 216 | // or if we pass the url off to the search engine 217 | var hostNameType = Uri.CheckHostName(urlString); 218 | 219 | if (hostNameType == UriHostNameType.IPv4 || hostNameType == UriHostNameType.IPv6) 220 | { 221 | browser.LoadUrl(urlString); 222 | 223 | if (browser.CanSelect) 224 | { 225 | browser.Select(); 226 | } 227 | 228 | return; 229 | } 230 | 231 | if (hostNameType == UriHostNameType.Dns) 232 | { 233 | try 234 | { 235 | var hostEntry = Dns.GetHostEntry(urlString); 236 | if (hostEntry.AddressList.Length > 0) 237 | { 238 | browser.LoadUrl(urlString); 239 | 240 | if (browser.CanSelect) 241 | { 242 | browser.Select(); 243 | } 244 | 245 | return; 246 | } 247 | } 248 | catch (Exception) 249 | { 250 | // Failed to resolve the host 251 | } 252 | } 253 | } 254 | 255 | // Failed parsing load urlString is a search engine 256 | var searchUrl = "https://www.google.com/search?q=" + Uri.EscapeDataString(urlString); 257 | 258 | browser.LoadUrl(searchUrl); 259 | 260 | if (browser.CanSelect) 261 | { 262 | browser.Select(); 263 | } 264 | } 265 | 266 | private void ShowDevToolsMenuItemClick(object sender, EventArgs e) 267 | { 268 | browser.ShowDevTools(); 269 | } 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | 9.0.30729 10 | 2.0 11 | {C043FFF7-5F71-4FFC-989A-E09E18548589} 12 | WinExe 13 | Properties 14 | CefSharp.MinimalExample.WinForms 15 | CefSharp.MinimalExample.WinForms 16 | v4.6.2 17 | 512 18 | 19 | 20 | 21 | 22 | 23 | 24 | 3.5 25 | 26 | 27 | ..\ 28 | 29 | 30 | true 31 | Content 32 | 33 | 34 | x64 35 | bin\x64\Debug\net452\ 36 | DEBUG 37 | false 38 | 39 | 40 | x64 41 | bin\x64\Release\net452\ 42 | false 43 | 44 | 45 | true 46 | bin\x86\Debug\net452\ 47 | x86 48 | MinimumRecommendedRules.ruleset 49 | DEBUG 50 | false 51 | 52 | 53 | bin\x86\Release\net452\ 54 | x86 55 | MinimumRecommendedRules.ruleset 56 | false 57 | 58 | 59 | true 60 | bin\AnyCPU\Debug\net452\ 61 | AnyCPU 62 | DEBUG;TRACE;ANYCPU 63 | false 64 | 65 | 66 | bin\AnyCPU\Release\net452\ 67 | AnyCPU 68 | TRACE;ANYCPU 69 | false 70 | 71 | 72 | app.manifest 73 | 74 | 75 | 76 | ..\packages\CefSharp.Common.136.1.40\lib\net462\CefSharp.dll 77 | True 78 | 79 | 80 | ..\packages\CefSharp.Common.136.1.40\lib\net462\CefSharp.Core.dll 81 | True 82 | 83 | 84 | ..\packages\CefSharp.WinForms.136.1.40\lib\net462\CefSharp.WinForms.dll 85 | True 86 | 87 | 88 | 89 | 3.5 90 | 91 | 92 | 93 | 94 | 95 | 96 | Form 97 | 98 | 99 | BrowserForm.cs 100 | 101 | 102 | 103 | 104 | 105 | 106 | True 107 | True 108 | Resources.resx 109 | 110 | 111 | 112 | 113 | BrowserForm.cs 114 | Designer 115 | 116 | 117 | ResXFileCodeGenerator 118 | Resources.Designer.cs 119 | Designer 120 | 121 | 122 | 123 | 124 | 125 | 126 | PreserveNewest 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.net472.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 | obj.net472\ 7 | bin.net472\ 8 | 9 | 10 | 11 | 12 | 13 | WinExe 14 | net472 15 | true 16 | CefSharp.MinimalExample.WinForms 17 | app.manifest 18 | false 19 | x86;x64;AnyCPU 20 | {1D1D63D1-5257-4AA0-A284-7EF4574878CB} 21 | CefSharp.MinimalExample.WinForms.Program 22 | 23 | 24 | 25 | $(DefineConstants);ANYCPU 26 | 30 | AnyCPU 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | PreserveNewest 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.netcore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 | obj.netcore\ 7 | bin.netcore\ 8 | 9 | 10 | 11 | 12 | 13 | WinExe 14 | netcoreapp3.1;net5.0-windows 15 | $(TargetFrameworks);net6.0-windows 16 | $(TargetFrameworks);net7.0-windows 17 | $(TargetFrameworks);net8.0-windows 18 | true 19 | CefSharp.MinimalExample.WinForms 20 | app.manifest 21 | false 22 | x86;x64;AnyCPU 23 | 27 | Major 28 | CefSharp.MinimalExample.WinForms.Program 29 | 30 | 31 | 36 | 37 | 38 | true 39 | 40 | true 41 | 42 | 43 | CefSharp.MinimalExample.WinForms.ProgramPublishSingleFile 44 | 45 | 46 | 50 | 51 | CefSharp.MinimalExample.WinForms.ProgramPublishSingleFile 52 | true 53 | 54 | 55 | 56 | win-x86 57 | false 58 | 59 | 60 | 61 | win-x64 62 | false 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | PreserveNewest 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Controls/ControlExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2010-2015 The CefSharp Authors. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 4 | 5 | using System; 6 | using System.Windows.Forms; 7 | 8 | namespace CefSharp.MinimalExample.WinForms.Controls 9 | { 10 | public static class ControlExtensions 11 | { 12 | /// 13 | /// Executes the Action asynchronously on the UI thread, does not block execution on the calling thread. 14 | /// 15 | /// the control for which the update is required 16 | /// action to be performed on the control 17 | public static void InvokeOnUiThreadIfRequired(this Control control, Action action) 18 | { 19 | //If you are planning on using a similar function in your own code then please be sure to 20 | //have a quick read over https://stackoverflow.com/questions/1874728/avoid-calling-invoke-when-the-control-is-disposed 21 | //No action 22 | if (control.Disposing || control.IsDisposed || !control.IsHandleCreated) 23 | { 24 | return; 25 | } 26 | 27 | if (control.InvokeRequired) 28 | { 29 | control.BeginInvoke(action); 30 | } 31 | else 32 | { 33 | action.Invoke(); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Program.PublishSingleFile.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2021 The CefSharp Authors. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 4 | 5 | using CefSharp.WinForms; 6 | using System; 7 | using System.IO; 8 | using System.Windows.Forms; 9 | 10 | namespace CefSharp.MinimalExample.WinForms 11 | { 12 | /// 13 | /// For .Net 5.0/6.0/7.0 Publishing Single File exe requires using your own applications executable to 14 | /// act as the BrowserSubProcess. See https://github.com/cefsharp/CefSharp/issues/3407 15 | /// for further details. for the default main application entry point 16 | /// 17 | public class ProgramPublishSingleFile 18 | { 19 | [STAThread] 20 | public static int Main(string[] args) 21 | { 22 | //To support High DPI this must be before CefSharp.BrowserSubprocess.SelfHost.Main so the BrowserSubprocess is DPI Aware 23 | Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); 24 | 25 | var exitCode = CefSharp.BrowserSubprocess.SelfHost.Main(args); 26 | 27 | if (exitCode >= 0) 28 | { 29 | return exitCode; 30 | } 31 | 32 | var settings = new CefSettings() 33 | { 34 | //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data 35 | CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"), 36 | BrowserSubprocessPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 37 | }; 38 | 39 | //Example of setting a command line argument 40 | //Enables WebRTC 41 | // - CEF Doesn't currently support permissions on a per browser basis see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access 42 | // - CEF Doesn't currently support displaying a UI for media access permissions 43 | // 44 | //NOTE: WebRTC Device Id's aren't persisted as they are in Chrome see https://bitbucket.org/chromiumembedded/cef/issues/2064/persist-webrtc-deviceids-across-restart 45 | settings.CefCommandLineArgs.Add("enable-media-stream"); 46 | //https://peter.sh/experiments/chromium-command-line-switches/#use-fake-ui-for-media-stream 47 | settings.CefCommandLineArgs.Add("use-fake-ui-for-media-stream"); 48 | //For screen sharing add (see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access#comment-58677180) 49 | settings.CefCommandLineArgs.Add("enable-usermedia-screen-capturing"); 50 | 51 | //Don't perform a dependency check 52 | Cef.Initialize(settings, performDependencyCheck: false); 53 | 54 | var browser = new BrowserForm(); 55 | Application.EnableVisualStyles(); 56 | Application.Run(browser); 57 | 58 | return 0; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2010-2015 The CefSharp Authors. All rights reserved. 2 | // 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 4 | 5 | using CefSharp.WinForms; 6 | using System; 7 | using System.IO; 8 | using System.Windows.Forms; 9 | 10 | namespace CefSharp.MinimalExample.WinForms 11 | { 12 | public static class Program 13 | { 14 | [STAThread] 15 | public static int Main(string[] args) 16 | { 17 | 18 | #if ANYCPU 19 | CefRuntime.SubscribeAnyCpuAssemblyResolver(); 20 | #endif 21 | 22 | var cachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache2"); 23 | 24 | var settings = new CefSettings() 25 | { 26 | // You must spcify a unique cache path per instance of your application 27 | CachePath = cachePath 28 | }; 29 | 30 | //Example of setting a command line argument 31 | //Enables WebRTC 32 | // - CEF Doesn't currently support permissions on a per browser basis see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access 33 | // - CEF Doesn't currently support displaying a UI for media access permissions 34 | // 35 | //NOTE: WebRTC Device Id's aren't persisted as they are in Chrome see https://bitbucket.org/chromiumembedded/cef/issues/2064/persist-webrtc-deviceids-across-restart 36 | settings.CefCommandLineArgs.Add("enable-media-stream"); 37 | //https://peter.sh/experiments/chromium-command-line-switches/#use-fake-ui-for-media-stream 38 | settings.CefCommandLineArgs.Add("use-fake-ui-for-media-stream"); 39 | //For screen sharing add (see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access#comment-58677180) 40 | settings.CefCommandLineArgs.Add("enable-usermedia-screen-capturing"); 41 | 42 | settings.CefCommandLineArgs.Add("disable-features", "OptimizationGuideOnDeviceModel"); 43 | //-- 44 | 45 | //Perform dependency check to make sure all relevant resources are in our output directory. 46 | var initialized = Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); 47 | 48 | if (!initialized) 49 | { 50 | var exitCode = Cef.GetExitCode(); 51 | 52 | if (exitCode == Enums.ResultCode.NormalExitProcessNotified) 53 | { 54 | MessageBox.Show($"Cef.Initialize failed with {exitCode}, another process is already using cache path {cachePath}"); 55 | } 56 | else 57 | { 58 | MessageBox.Show($"Cef.Initialize failed with {exitCode}, check the log file for more details."); 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | Application.EnableVisualStyles(); 65 | Application.Run(new BrowserForm()); 66 | 67 | return 0; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("CefSharp.MinimalExample.WinForms")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("CefSharp.MinimalExample.WinForms")] 12 | [assembly: AssemblyCopyright("Copyright © 2015")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // Version information for an assembly consists of the following four values: 22 | // 23 | // Major Version 24 | // Minor Version 25 | // Build Number 26 | // Revision 27 | // 28 | // You can specify all the values or you can default the Build and Revision Numbers 29 | // by using the '*' as shown below: 30 | // [assembly: AssemblyVersion("1.0.*")] 31 | [assembly: AssemblyVersion("1.0.0.0")] 32 | [assembly: AssemblyFileVersion("1.0.0.0")] 33 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18034 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CefSharp.MinimalExample.WinForms.Properties { 12 | /// 13 | /// A strongly-typed resource class, for looking up localized strings, etc. 14 | /// 15 | // This class was auto-generated by the StronglyTypedResourceBuilder 16 | // class via a tool like ResGen or Visual Studio. 17 | // To add or remove a member, edit your .ResX file then rerun ResGen 18 | // with the /str option, or rebuild your VS project. 19 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 20 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 21 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 22 | internal class Resources { 23 | 24 | private static global::System.Resources.ResourceManager resourceMan; 25 | 26 | private static global::System.Globalization.CultureInfo resourceCulture; 27 | 28 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 29 | internal Resources() { 30 | } 31 | 32 | /// 33 | /// Returns the cached ResourceManager instance used by this class. 34 | /// 35 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 36 | internal static global::System.Resources.ResourceManager ResourceManager { 37 | get { 38 | if (object.ReferenceEquals(resourceMan, null)) { 39 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CefSharp.MinimalExample.WinForms.Properties.Resources", typeof(Resources).Assembly); 40 | resourceMan = temp; 41 | } 42 | return resourceMan; 43 | } 44 | } 45 | 46 | /// 47 | /// Overrides the current thread's CurrentUICulture property for all 48 | /// resource lookups using this strongly typed resource class. 49 | /// 50 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 51 | internal static global::System.Globalization.CultureInfo Culture { 52 | get { 53 | return resourceCulture; 54 | } 55 | set { 56 | resourceCulture = value; 57 | } 58 | } 59 | 60 | /// 61 | /// Looks up a localized resource of type System.Drawing.Bitmap. 62 | /// 63 | internal static System.Drawing.Bitmap chromium256 { 64 | get { 65 | object obj = ResourceManager.GetObject("chromium256", resourceCulture); 66 | return ((System.Drawing.Bitmap)(obj)); 67 | } 68 | } 69 | 70 | /// 71 | /// Looks up a localized resource of type System.Drawing.Bitmap. 72 | /// 73 | internal static System.Drawing.Bitmap nav_left_green { 74 | get { 75 | object obj = ResourceManager.GetObject("nav_left_green", resourceCulture); 76 | return ((System.Drawing.Bitmap)(obj)); 77 | } 78 | } 79 | 80 | /// 81 | /// Looks up a localized resource of type System.Drawing.Bitmap. 82 | /// 83 | internal static System.Drawing.Bitmap nav_plain_green { 84 | get { 85 | object obj = ResourceManager.GetObject("nav_plain_green", resourceCulture); 86 | return ((System.Drawing.Bitmap)(obj)); 87 | } 88 | } 89 | 90 | /// 91 | /// Looks up a localized resource of type System.Drawing.Bitmap. 92 | /// 93 | internal static System.Drawing.Bitmap nav_plain_red { 94 | get { 95 | object obj = ResourceManager.GetObject("nav_plain_red", resourceCulture); 96 | return ((System.Drawing.Bitmap)(obj)); 97 | } 98 | } 99 | 100 | /// 101 | /// Looks up a localized resource of type System.Drawing.Bitmap. 102 | /// 103 | internal static System.Drawing.Bitmap nav_right_green { 104 | get { 105 | object obj = ResourceManager.GetObject("nav_right_green", resourceCulture); 106 | return ((System.Drawing.Bitmap)(obj)); 107 | } 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\nav_right_green.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\nav_left_green.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\Resources\nav_plain_red.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\Resources\nav_plain_green.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | 134 | ..\Resources\chromium-256.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 135 | 136 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Resources/chromium-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cefsharp/CefSharp.MinimalExample/c6debe452a4a1ec113716606d7af40bf64c83cf6/CefSharp.MinimalExample.WinForms/Resources/chromium-256.png -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Resources/nav_left_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cefsharp/CefSharp.MinimalExample/c6debe452a4a1ec113716606d7af40bf64c83cf6/CefSharp.MinimalExample.WinForms/Resources/nav_left_green.png -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Resources/nav_plain_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cefsharp/CefSharp.MinimalExample/c6debe452a4a1ec113716606d7af40bf64c83cf6/CefSharp.MinimalExample.WinForms/Resources/nav_plain_green.png -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Resources/nav_plain_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cefsharp/CefSharp.MinimalExample/c6debe452a4a1ec113716606d7af40bf64c83cf6/CefSharp.MinimalExample.WinForms/Resources/nav_plain_red.png -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/Resources/nav_right_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cefsharp/CefSharp.MinimalExample/c6debe452a4a1ec113716606d7af40bf64c83cf6/CefSharp.MinimalExample.WinForms/Resources/nav_right_green.png -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/crash_reporter.cfg: -------------------------------------------------------------------------------- 1 | # Crash reporting is configured using an INI-style config file named 2 | # "crash_reporter.cfg". This file must be placed next to 3 | # the main application executable. 4 | # Comments start with a hash character and must be on their own line. 5 | # See https://bitbucket.org/chromiumembedded/cef/wiki/CrashReporting.md 6 | # for further details 7 | 8 | [Config] 9 | ProductName=CefSharp.MinimalExample.WinForms 10 | ProductVersion=1.0.0 11 | AppName=CefSharp.MinimalExample 12 | ExternalHandler=CefSharp.BrowserSubprocess.exe -------------------------------------------------------------------------------- /CefSharp.MinimalExample.WinForms/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using CefSharp.Wpf.HwndHost; 2 | using System; 3 | using System.IO; 4 | using System.Windows; 5 | 6 | namespace CefSharp.MinimalExample.Wpf.HwndHost 7 | { 8 | public partial class App : Application 9 | { 10 | public App() 11 | { 12 | var cachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"); 13 | 14 | #if ANYCPU 15 | //Only required for PlatformTarget of AnyCPU 16 | CefRuntime.SubscribeAnyCpuAssemblyResolver(); 17 | #endif 18 | var settings = new CefSettings() 19 | { 20 | //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data 21 | CachePath = cachePath 22 | }; 23 | 24 | //Example of setting a command line argument 25 | //Enables WebRTC 26 | // - CEF Doesn't currently support permissions on a per browser basis see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access 27 | // - CEF Doesn't currently support displaying a UI for media access permissions 28 | // 29 | //NOTE: WebRTC Device Id's aren't persisted as they are in Chrome see https://bitbucket.org/chromiumembedded/cef/issues/2064/persist-webrtc-deviceids-across-restart 30 | settings.CefCommandLineArgs.Add("enable-media-stream"); 31 | //https://peter.sh/experiments/chromium-command-line-switches/#use-fake-ui-for-media-stream 32 | settings.CefCommandLineArgs.Add("use-fake-ui-for-media-stream"); 33 | //For screen sharing add (see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access#comment-58677180) 34 | settings.CefCommandLineArgs.Add("enable-usermedia-screen-capturing"); 35 | 36 | //Example of checking if a call to Cef.Initialize has already been made, we require this for 37 | //our .Net 5.0 Single File Publish example, you don't typically need to perform this check 38 | //if you call Cef.Initialze within your WPF App constructor. 39 | if (Cef.IsInitialized == null) 40 | { 41 | //Perform dependency check to make sure all relevant resources are in our output directory. 42 | var initialized = Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); 43 | 44 | if(!initialized) 45 | { 46 | var exitCode = Cef.GetExitCode(); 47 | 48 | if (exitCode == Enums.ResultCode.NormalExitProcessNotified) 49 | { 50 | MessageBox.Show($"Cef.Initialize failed with {exitCode}, another process is already using cache path {cachePath}"); 51 | } 52 | else 53 | { 54 | MessageBox.Show($"Cef.Initialize failed with {exitCode}, check the log file for more details."); 55 | } 56 | 57 | Shutdown(); 58 | } 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/Behaviours/HoverLinkBehaviour.cs: -------------------------------------------------------------------------------- 1 | using CefSharp.Wpf.HwndHost; 2 | using System.Windows; 3 | using System; 4 | using Microsoft.Xaml.Behaviors; 5 | 6 | namespace CefSharp.MinimalExample.Wpf.HwndHost.Behaviours 7 | { 8 | public class HoverLinkBehaviour : Behavior 9 | { 10 | // Using a DependencyProperty as the backing store for HoverLink. This enables animation, styling, binding, etc... 11 | public static readonly DependencyProperty HoverLinkProperty = DependencyProperty.Register("HoverLink", typeof(string), typeof(HoverLinkBehaviour), new PropertyMetadata(string.Empty)); 12 | 13 | public string HoverLink 14 | { 15 | get { return (string)GetValue(HoverLinkProperty); } 16 | set { SetValue(HoverLinkProperty, value); } 17 | } 18 | 19 | protected override void OnAttached() 20 | { 21 | AssociatedObject.StatusMessage += OnStatusMessageChanged; 22 | } 23 | 24 | protected override void OnDetaching() 25 | { 26 | AssociatedObject.StatusMessage -= OnStatusMessageChanged; 27 | } 28 | 29 | private void OnStatusMessageChanged(object sender, StatusMessageEventArgs e) 30 | { 31 | var chromiumWebBrowser = sender as ChromiumWebBrowser; 32 | chromiumWebBrowser.Dispatcher.BeginInvoke((Action)(() => HoverLink = e.Value)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/Behaviours/TextBoxBindingUpdateOnEnterBehaviour.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | using System.Windows.Input; 3 | using Microsoft.Xaml.Behaviors; 4 | 5 | namespace CefSharp.MinimalExample.Wpf.HwndHost.Behaviours 6 | { 7 | public class TextBoxBindingUpdateOnEnterBehaviour : Behavior 8 | { 9 | protected override void OnAttached() 10 | { 11 | AssociatedObject.KeyDown += OnTextBoxKeyDown; 12 | } 13 | 14 | protected override void OnDetaching() 15 | { 16 | AssociatedObject.KeyDown -= OnTextBoxKeyDown; 17 | } 18 | 19 | private void OnTextBoxKeyDown(object sender, KeyEventArgs e) 20 | { 21 | if (e.Key == Key.Enter) 22 | { 23 | var txtBox = sender as TextBox; 24 | txtBox.GetBindingExpression(TextBox.TextProperty).UpdateSource(); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/CefSharp.MinimalExample.Wpf.HwndHost.net472.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 | obj.net472\ 7 | bin.net472\ 8 | 9 | 10 | 11 | 12 | 13 | WinExe 14 | net472 15 | true 16 | CefSharp.MinimalExample.Wpf.HwndHost 17 | app.manifest 18 | false 19 | x86;x64;AnyCPU 20 | CefSharp.MinimalExample.Wpf.HwndHost.App 21 | 22 | 23 | 24 | $(DefineConstants);ANYCPU 25 | 29 | AnyCPU 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | PreserveNewest 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/CefSharp.MinimalExample.Wpf.HwndHost.netcore.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 5 | 6 | obj.netcore\ 7 | bin.netcore\ 8 | 9 | 10 | 11 | 12 | 13 | WinExe 14 | netcoreapp3.1;net5.0-windows 15 | $(TargetFrameworks);net6.0-windows 16 | $(TargetFrameworks);net7.0-windows 17 | $(TargetFrameworks);net8.0-windows 18 | true 19 | CefSharp.MinimalExample.HwndHost.Wpf 20 | chromium-256.ico 21 | app.manifest 22 | false 23 | x86;x64;AnyCPU 24 | 28 | Major 29 | CefSharp.MinimalExample.Wpf.HwndHost.App 30 | 31 | 32 | 33 | win-x86 34 | false 35 | 36 | 37 | 38 | win-x64 39 | false 40 | 41 | 42 | 47 | 48 | 49 | true 50 | 51 | true 52 | 53 | 54 | CefSharp.MinimalExample.Wpf.HwndHost.ProgramPublishSingleFile 55 | 56 | 57 | 61 | 62 | CefSharp.MinimalExample.Wpf.HwndHost.ProgramPublishSingleFile 63 | true 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | PreserveNewest 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/Converter/EnvironmentConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace CefSharp.MinimalExample.Wpf.HwndHost.Converter 6 | { 7 | public class EnvironmentConverter : IValueConverter 8 | { 9 | object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) 10 | { 11 | return Environment.Is64BitProcess ? "x64" : "x86"; 12 | } 13 | 14 | object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | return Binding.DoNothing; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/Converter/TitleConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | 5 | namespace CefSharp.MinimalExample.Wpf.HwndHost.Converter 6 | { 7 | public class TitleConverter : IValueConverter 8 | { 9 | #if DEBUG 10 | private const string Build = "Debug"; 11 | #else 12 | private const string Build = "Release"; 13 | #endif 14 | object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | return "CefSharp.MinimalExample.Wpf.HwndHost (" + Build + ") - " + (value ?? "No Title Specified"); 17 | } 18 | 19 | object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 20 | { 21 | return Binding.DoNothing; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CefSharp.MinimalExample.Wpf.HwndHost/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |