/// <summary> /// Initialize cef with the provided settings. /// </summary> /// <param name="performDependencyCheck"></param> /// <param name="browserProcessHandler"></param> /// <param name="settingsAction"></param> public static bool InitializeCef(bool performDependencyCheck, IBrowserProcessHandler browserProcessHandler, Action <CefSettings> settingsAction = null) { if (Cef.IsInitialized) { return(true); } var settings = new CefSettings(); settingsAction?.Invoke(settings); return(Cef.Initialize(settings, performDependencyCheck, browserProcessHandler)); }
public static void InitCEF(AbstractCefSettings settings, IBrowserProcessHandler browserProcessHandler) { settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; settings.CefCommandLineArgs.Add("no-proxy-server", "1"); settings.CefCommandLineArgs.Add("disable-extensions", "1"); settings.CefCommandLineArgs.Add("disable-pdf-extension", "1"); settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); CefSharpSettings.SubprocessExitIfParentProcessClosed = true; Cef.EnableHighDPISupport(); if (!Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: browserProcessHandler)) { throw new Exception("Unable to Initialize Cef"); } }
public static int Main(string[] args) { //if (!File.Exists("url.txt") || !File.Exists("proxy.txt")) //{ // MessageBox.Show("Please config files: url.txt, proxy.txt "); // return 0; //} //if (string.IsNullOrWhiteSpace(File.ReadAllText("url.txt")) || string.IsNullOrWhiteSpace(File.ReadAllText("proxy.txt"))) //{ // MessageBox.Show("Please input files: url.txt, proxy.txt. They must not be empty."); // return 0; //} //if (!Directory.Exists(File.ReadAllLines("proxy.txt").Select(x=>x.Trim()).Where(x=>x.Length > 0).ToArray()[0])) //{ // MessageBox.Show("[proxy.txt] Cannot path: " + File.ReadAllLines("proxy.txt").Select(x => x.Trim()).Where(x => x.Length > 0).ToArray()[0]); // return 0; //} Cef.EnableHighDPISupport(); var browser = new BrowserForm(true); IBrowserProcessHandler browserProcessHandler = null; browserProcessHandler = new BrowserProcessHandler(); var settings = new CefSettings(); //settings.MultiThreadedMessageLoop = true; settings.ExternalMessagePump = false; //////// http://xxx.com/.. //////string[] a = File.ReadAllText("url.txt").ToLower().Trim().Split('/'); //////settings.RegisterScheme(new CefCustomScheme //////{ ////// SchemeName = a[0].Substring(0, a[0].Length - 1), ////// DomainName = a[2].Split(':')[0], ////// SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() //////}); CefExample.Init(settings, browserProcessHandler: browserProcessHandler); Application.Run(browser); return(0); }
private static void InitializeCefSharp(IBrowserProcessHandler browserProcessHandler) { CefSettings settings; try { settings = new CefSettings(); // Set BrowserSubProcessPath based on app bitness at runtime settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe"); Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: browserProcessHandler); } catch (FileNotFoundException exception) { Debug.WriteLine(exception.Message); } }
public static void Init( Action appInitializer, string distFolder, Action <CefSettings> settingsBuilder = null, bool performDependencyCheck = true, IBrowserProcessHandler browserProcessHandler = null ) { _appInitializer = appInitializer; _distFolder = distFolder; CefSharpSettings.WcfEnabled = true; var settings = new CefSettings() { //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache") }; settingsBuilder?.Invoke(settings); //Perform dependency check to make sure all relevant resources are in our output directory. Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); }
public static void Init(AbstractCefSettings settings, IBrowserProcessHandler browserProcessHandler) { // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", ""); // Widevine CDM registration - pass in directory where Widevine CDM binaries and manifest.json are located. // For more information on support for DRM content with Widevine see: https://github.com/cefsharp/CefSharp/issues/1934 //Cef.RegisterWidevineCdm(@".\WidevineCdm"); //Chromium Command Line args //http://peter.sh/experiments/chromium-command-line-switches/ //NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only. //CEF specific command line args //https://bitbucket.org/chromiumembedded/cef/src/master/libcef/common/cef_switches.cc?fileviewer=file-view-default //IMPORTANT: For enabled/disabled command line arguments like disable-gpu specifying a value of "0" like //settings.CefCommandLineArgs.Add("disable-gpu", "0"); will have no effect as the second argument is ignored. settings.RemoteDebuggingPort = 8088; //The location where cache data will be stored on disk. If empty an in-memory cache will be used for some features and a temporary disk cache for others. //HTML5 databases such as localStorage will only persist across sessions if a cache path is specified. settings.CachePath = "cache"; //settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog"); //settings.CefCommandLineArgs.Add("enable-media-stream"); //Enable WebRTC //settings.CefCommandLineArgs.Add("no-proxy-server"); //Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed. //settings.CefCommandLineArgs.Add("debug-plugin-loading"); //Dumps extra logging about plugin loading to the log file. //settings.CefCommandLineArgs.Add("disable-plugins-discovery"); //Disable discovering third-party plugins. Effectively loading only ones shipped with the browser plus third-party ones as specified by --extra-plugin-dir and --load-plugin switches //settings.CefCommandLineArgs.Add("enable-system-flash"); //Automatically discovered and load a system-wide installation of Pepper Flash. //settings.CefCommandLineArgs.Add("allow-running-insecure-content"); //By default, an https page cannot run JavaScript, CSS or plugins from http URLs. This provides an override to get the old insecure behavior. Only available in 47 and above. //settings.CefCommandLineArgs.Add("enable-logging"); //Enable Logging for the Renderer process (will open with a cmd prompt and output debug messages - use in conjunction with setting LogSeverity = LogSeverity.Verbose;) //settings.LogSeverity = LogSeverity.Verbose; // Needed for enable-logging to output messages //settings.CefCommandLineArgs.Add("disable-extensions"); //Extension support can be disabled //settings.CefCommandLineArgs.Add("disable-pdf-extension"); //The PDF extension specifically can be disabled //Load the pepper flash player that comes with Google Chrome - may be possible to load these values from the registry and query the dll for it's version info (Step 2 not strictly required it seems) //settings.CefCommandLineArgs.Add("ppapi-flash-path", @"C:\Program Files (x86)\Google\Chrome\Application\47.0.2526.106\PepperFlash\pepflashplayer.dll"); //Load a specific pepper flash version (Step 1 of 2) //settings.CefCommandLineArgs.Add("ppapi-flash-version", "20.0.0.228"); //Load a specific pepper flash version (Step 2 of 2) //Audo play example //settings.CefCommandLineArgs["autoplay-policy"] = "no-user-gesture-required"; //NOTE: For OSR best performance you should run with GPU disabled: // `--disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling` // (you'll loose WebGL support but gain increased FPS and reduced CPU usage). // http://magpcss.org/ceforum/viewtopic.php?f=6&t=13271#p27075 //https://bitbucket.org/chromiumembedded/cef/commits/e3c1d8632eb43c1c2793d71639f3f5695696a5e8 //NOTE: The following function will set all three params //settings.SetOffScreenRenderingBestPerformanceArgs(); //settings.CefCommandLineArgs.Add("disable-gpu"); //settings.CefCommandLineArgs.Add("disable-gpu-compositing"); //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync"); //Disable Vsync // The following options control accessibility state for all frames. // These options only take effect if accessibility state is not set by IBrowserHost.SetAccessibilityState call. // --force-renderer-accessibility enables browser accessibility. // --disable-renderer-accessibility completely disables browser accessibility. //settings.CefCommandLineArgs.Add("force-renderer-accessibility"); //settings.CefCommandLineArgs.Add("disable-renderer-accessibility"); //Disable Network Service in WPF //settings.CefCommandLineArgs.Add("disable-features", "NetworkService,VizDisplayCompositor"); //Disable Network Service in WinForms //settings.CefCommandLineArgs.Add("disable-features", "NetworkService"); //Enables Uncaught exception handler settings.UncaughtExceptionStackSize = 10; // Off Screen rendering (WPF/Offscreen) if (settings.WindowlessRenderingEnabled) { //Disable Direct Composition to test https://github.com/cefsharp/CefSharp/issues/1634 //settings.CefCommandLineArgs.Add("disable-direct-composition"); // DevTools doesn't seem to be working when this is enabled // http://magpcss.org/ceforum/viewtopic.php?f=6&t=14095 //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling"); } var proxy = ProxyConfig.GetProxyInformation(); switch (proxy.AccessType) { case InternetOpenType.Direct: { //Don't use a proxy server, always make direct connections. settings.CefCommandLineArgs.Add("no-proxy-server"); break; } case InternetOpenType.Proxy: { settings.CefCommandLineArgs.Add("proxy-server", proxy.ProxyAddress); break; } case InternetOpenType.PreConfig: { settings.CefCommandLineArgs.Add("proxy-auto-detect"); break; } } //settings.LogSeverity = LogSeverity.Verbose; if (DebuggingSubProcess) { var architecture = Environment.Is64BitProcess ? "x64" : "x86"; settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\" + architecture + "\\Debug\\CefSharp.BrowserSubprocess.exe"; } settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), IsSecure = true, //treated with the same security rules as those applied to "https" URLs }); settings.RegisterScheme(new CefCustomScheme { SchemeName = "https", SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), DomainName = "cefsharp.example" }); settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), IsSecure = true //treated with the same security rules as those applied to "https" URLs }); //You can use the http/https schemes - best to register for a specific domain settings.RegisterScheme(new CefCustomScheme { SchemeName = "https", SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), DomainName = "cefsharp.com", IsSecure = true //treated with the same security rules as those applied to "https" URLs }); settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", SchemeHandlerFactory = new FolderSchemeHandlerFactory(rootFolder: @"..\..\..\..\CefSharp.Example\Resources", schemeName: "localfolder", //Optional param no schemename checking if null hostName: "cefsharp", //Optional param no hostname checking if null defaultPage: "home.html") //Optional param will default to index.html }); settings.RegisterExtension(new V8Extension("cefsharp/example", Resources.extension)); //This must be set before Cef.Initialized is called CefSharpSettings.FocusedNodeChangedEnabled = true; //Async Javascript Binding - methods are queued on TaskScheduler.Default. //Set this to true to when you have methods that return Task<T> //CefSharpSettings.ConcurrentTaskExecution = true; //Legacy Binding Behaviour - Same as Javascript Binding in version 57 and below //See issue https://github.com/cefsharp/CefSharp/issues/1203 for details //CefSharpSettings.LegacyJavascriptBindingEnabled = true; //Exit the subprocess if the parent process happens to close //This is optional at the moment //https://github.com/cefsharp/CefSharp/pull/2375/ CefSharpSettings.SubprocessExitIfParentProcessClosed = true; //NOTE: Set this before any calls to Cef.Initialize to specify a proxy with username and password //One set this cannot be changed at runtime. If you need to change the proxy at runtime (dynamically) then //see https://github.com/cefsharp/CefSharp/wiki/General-Usage#proxy-resolution //CefSharpSettings.Proxy = new ProxyOptions(ip: "127.0.0.1", port: "8080", username: "******", password: "******"); if (!Cef.Initialize(settings, performDependencyCheck: !DebuggingSubProcess, browserProcessHandler: browserProcessHandler)) { throw new Exception("Unable to Initialize Cef"); } Cef.AddCrossOriginWhitelistEntry(BaseUrl, "https", "cefsharp.com", false); }
public DefaultApp(IBrowserProcessHandler browserProcessHandler, IEnumerable <CefCustomScheme> schemes) { BrowserProcessHandler = browserProcessHandler; Schemes = schemes; }
static void Init(bool multiThreadedMessageLoop, IBrowserProcessHandler browserProcessHandler) { CefSharpSettings.ShutdownOnExit = true; CefSharpSettings.FocusedNodeChangedEnabled = true; // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", ""); // Widevine CDM registration - pass in directory where Widevine CDM binaries and manifest.json are located. // For more information on support for DRM content with Widevine see: https://github.com/cefsharp/CefSharp/issues/1934 //Cef.RegisterWidevineCdm(@".\WidevineCdm"); //Chromium Command Line args //http://peter.sh/experiments/chromium-command-line-switches/ //NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only. var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; settings.CefCommandLineArgs.Add("transparent-painting-enabled", "1"); //The location where cache data will be stored on disk. If empty an in-memory cache will be used for some features and a temporary disk cache for others. //HTML5 databases such as localStorage will only persist across sessions if a cache path is specified. settings.CachePath = CachePath; //settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "1"); //settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enable WebRTC //settings.CefCommandLineArgs.Add("no-proxy-server", "1"); //Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed. //settings.CefCommandLineArgs.Add("debug-plugin-loading", "1"); //Dumps extra logging about plugin loading to the log file. //settings.CefCommandLineArgs.Add("disable-plugins-discovery", "1"); //Disable discovering third-party plugins. Effectively loading only ones shipped with the browser plus third-party ones as specified by --extra-plugin-dir and --load-plugin switches //settings.CefCommandLineArgs.Add("enable-system-flash", "1"); //Automatically discovered and load a system-wide installation of Pepper Flash. //settings.CefCommandLineArgs.Add("allow-running-insecure-content", "1"); //By default, an https page cannot run JavaScript, CSS or plugins from http URLs. This provides an override to get the old insecure behavior. Only available in 47 and above. //settings.CefCommandLineArgs.Add("enable-logging", "1"); //Enable Logging for the Renderer process (will open with a cmd prompt and output debug messages - use in conjunction with setting LogSeverity = LogSeverity.Verbose;) //settings.LogSeverity = LogSeverity.Verbose; // Needed for enable-logging to output messages //settings.CefCommandLineArgs.Add("disable-extensions", "1"); //Extension support can be disabled //settings.CefCommandLineArgs.Add("disable-pdf-extension", "1"); //The PDF extension specifically can be disabled //NOTE: For OSR best performance you should run with GPU disabled: // `--disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling` // (you'll loose WebGL support but gain increased FPS and reduced CPU usage). // http://magpcss.org/ceforum/viewtopic.php?f=6&t=13271#p27075 //https://bitbucket.org/chromiumembedded/cef/commits/e3c1d8632eb43c1c2793d71639f3f5695696a5e8 //NOTE: The following function will set all three params settings.SetOffScreenRenderingBestPerformanceArgs(); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-compositing", "1"); //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); //Disable Vsync //Disables the DirectWrite font rendering system on windows. //Possibly useful when experiencing blury fonts. //settings.CefCommandLineArgs.Add("disable-direct-write", "1"); settings.MultiThreadedMessageLoop = multiThreadedMessageLoop; settings.ExternalMessagePump = !multiThreadedMessageLoop; // Off Screen rendering (WPF/Offscreen) settings.WindowlessRenderingEnabled = true; //Disable Direct Composition to test https://github.com/cefsharp/CefSharp/issues/1634 //settings.CefCommandLineArgs.Add("disable-direct-composition", "1"); // DevTools doesn't seem to be working when this is enabled // http://magpcss.org/ceforum/viewtopic.php?f=6&t=14095 //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); var proxy = ProxyConfig.GetProxyInformation(); switch (proxy.AccessType) { case InternetOpenType.Direct: { //Don't use a proxy server, always make direct connections. settings.CefCommandLineArgs.Add("no-proxy-server", "1"); break; } case InternetOpenType.Proxy: { settings.CefCommandLineArgs.Add("proxy-server", proxy.ProxyAddress); break; } case InternetOpenType.PreConfig: { settings.CefCommandLineArgs.Add("proxy-auto-detect", "1"); break; } } //settings.LogSeverity = LogSeverity.Verbose; if (DebuggingSubProcess) { var architecture = Environment.Is64BitProcess ? "x64" : "x86"; settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\" + architecture + "\\Debug\\CefSharp.BrowserSubprocess.exe"; } settings.RegisterScheme(new CefCustomScheme { SchemeName = SchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new SchemeHandlerFactory(), IsSecure = true //treated with the same security rules as those applied to "https" URLs }); if (!Cef.Initialize(settings, performDependencyCheck: !DebuggingSubProcess, browserProcessHandler: browserProcessHandler)) { throw new Exception("Unable to Initialize Cef"); } Cef.AddCrossOriginWhitelistEntry(BaseUrl, "https", "cefsharp.com", false); //Experimental option where bound async methods are queued on TaskScheduler.Default. //CefSharpSettings.ConcurrentTaskExecution = true; }
/// <summary> /// Initializes CefSharp with user-provided settings. /// It's important to note that Initialize/Shutdown <strong>MUST</strong> be called on your main /// application thread (typically the UI thread). If you call them on different /// threads, your application will hang. See the documentation for Cef.Shutdown() for more details. /// </summary> /// <param name="settings">CefSharp configuration settings.</param> /// <param name="performDependencyCheck">Check that all relevant dependencies available, throws exception if any are missing</param> /// <param name="browserProcessHandler">The handler for functionality specific to the browser process. Null if you don't wish to handle these events</param> /// <returns>true if successful; otherwise, false.</returns> public static bool Initialize(CefSettingsBase settings, bool performDependencyCheck, IBrowserProcessHandler browserProcessHandler) { using (settings.settings) { return(Core.Cef.Initialize(settings.settings, performDependencyCheck, browserProcessHandler)); } }
/// <summary> /// Initializes CefSharp with user-provided settings. This method allows you to wait for /// <see cref="IBrowserProcessHandler.OnContextInitialized"/> to be called before continuing. /// It's important to note that Initialize and Shutdown <strong>MUST</strong> be called on your main /// application thread (typically the UI thread). If you call them on different /// threads, your application will hang. See the documentation for Cef.Shutdown() for more details. /// </summary> /// <param name="settings">CefSharp configuration settings.</param> /// <param name="performDependencyCheck">Check that all relevant dependencies available, throws exception if any are missing</param> /// <param name="browserProcessHandler">The handler for functionality specific to the browser process. Null if you don't wish to handle these events</param> /// <returns>returns a Task that can be awaited. true if successful; otherwise, false. If false check the log file for possible errors</returns> /// <remarks> /// If successful then the Task will be completed successfully when <see cref="IBrowserProcessHandler.OnContextInitialized"/> is called. /// If successful then the continuation will happen syncrionously on the CEF UI thread. /// </remarks> public static Task <bool> InitializeAsync(CefSettingsBase settings, bool performDependencyCheck = true, IBrowserProcessHandler browserProcessHandler = null) { using (settings.settings) { try { //Ignore the result, the Task will be set in Core.Cef.Initialze Core.Cef.Initialize(settings.settings, performDependencyCheck, browserProcessHandler); } catch (Exception ex) { GlobalContextInitialized.SetException(ex); } } return(GlobalContextInitialized.Task); }
public static void Init(bool osr, bool multiThreadedMessageLoop, IBrowserProcessHandler browserProcessHandler) { // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", ""); //Chromium Command Line args //http://peter.sh/experiments/chromium-command-line-switches/ //NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only. var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //The location where cache data will be stored on disk. If empty an in-memory cache will be used for some features and a temporary disk cache for others. //HTML5 databases such as localStorage will only persist across sessions if a cache path is specified. settings.CachePath = "cache"; //settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "1"); //settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enable WebRTC //settings.CefCommandLineArgs.Add("no-proxy-server", "1"); //Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed. //settings.CefCommandLineArgs.Add("debug-plugin-loading", "1"); //Dumps extra logging about plugin loading to the log file. //settings.CefCommandLineArgs.Add("disable-plugins-discovery", "1"); //Disable discovering third-party plugins. Effectively loading only ones shipped with the browser plus third-party ones as specified by --extra-plugin-dir and --load-plugin switches //settings.CefCommandLineArgs.Add("enable-system-flash", "1"); //Automatically discovered and load a system-wide installation of Pepper Flash. //settings.CefCommandLineArgs.Add("allow-running-insecure-content", "1"); //By default, an https page cannot run JavaScript, CSS or plugins from http URLs. This provides an override to get the old insecure behavior. Only available in 47 and above. //settings.CefCommandLineArgs.Add("enable-logging", "1"); //Enable Logging for the Renderer process (will open with a cmd prompt and output debug messages - use in conjunction with setting LogSeverity = LogSeverity.Verbose;) //settings.LogSeverity = LogSeverity.Verbose; // Needed for enable-logging to output messages //settings.CefCommandLineArgs.Add("disable-extensions", "1"); //Extension support can be disabled //settings.CefCommandLineArgs.Add("disable-pdf-extension", "1"); //The PDF extension specifically can be disabled //Load the pepper flash player that comes with Google Chrome - may be possible to load these values from the registry and query the dll for it's version info (Step 2 not strictly required it seems) //settings.CefCommandLineArgs.Add("ppapi-flash-path", @"C:\Program Files (x86)\Google\Chrome\Application\47.0.2526.106\PepperFlash\pepflashplayer.dll"); //Load a specific pepper flash version (Step 1 of 2) //settings.CefCommandLineArgs.Add("ppapi-flash-version", "20.0.0.228"); //Load a specific pepper flash version (Step 2 of 2) //NOTE: For OSR best performance you should run with GPU disabled: // `--disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling` // (you'll loose WebGL support but gain increased FPS and reduced CPU usage). // http://magpcss.org/ceforum/viewtopic.php?f=6&t=13271#p27075 //https://bitbucket.org/chromiumembedded/cef/commits/e3c1d8632eb43c1c2793d71639f3f5695696a5e8 //NOTE: The following function will set all three params //settings.SetOffScreenRenderingBestPerformanceArgs(); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-compositing", "1"); //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); //Disable Vsync //Disables the DirectWrite font rendering system on windows. //Possibly useful when experiencing blury fonts. //settings.CefCommandLineArgs.Add("disable-direct-write", "1"); settings.MultiThreadedMessageLoop = multiThreadedMessageLoop; settings.ExternalMessagePump = !multiThreadedMessageLoop; // Off Screen rendering (WPF/Offscreen) if(osr) { settings.WindowlessRenderingEnabled = true; //Disable Direct Composition to test https://github.com/cefsharp/CefSharp/issues/1634 //settings.CefCommandLineArgs.Add("disable-direct-composition", "1"); // DevTools doesn't seem to be working when this is enabled // http://magpcss.org/ceforum/viewtopic.php?f=6&t=14095 //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); } var proxy = ProxyConfig.GetProxyInformation(); switch (proxy.AccessType) { case InternetOpenType.Direct: { //Don't use a proxy server, always make direct connections. settings.CefCommandLineArgs.Add("no-proxy-server", "1"); break; } case InternetOpenType.Proxy: { settings.CefCommandLineArgs.Add("proxy-server", proxy.ProxyAddress); break; } case InternetOpenType.PreConfig: { settings.CefCommandLineArgs.Add("proxy-auto-detect", "1"); break; } } //settings.LogSeverity = LogSeverity.Verbose; if (DebuggingSubProcess) { var architecture = Environment.Is64BitProcess ? "x64" : "x86"; settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\" + architecture + "\\Debug\\CefSharp.BrowserSubprocess.exe"; } settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() //SchemeHandlerFactory = new InMemorySchemeAndResourceHandlerFactory() }); settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", SchemeHandlerFactory = new FolderSchemeHandlerFactory(rootFolder: @"..\..\..\..\CefSharp.Example\Resources", schemeName: "localfolder", //Optional param no schemename checking if null hostName: "cefsharp", //Optional param no hostname checking if null defaultPage: "home.html") //Optional param will default to index.html }); settings.RegisterExtension(new CefExtension("cefsharp/example", Resources.extension)); settings.FocusedNodeChangedEnabled = true; if (!Cef.Initialize(settings, performDependencyCheck: !DebuggingSubProcess, browserProcessHandler: browserProcessHandler)) { throw new Exception("Unable to Initialize Cef"); } }
public static void Init(bool osr, bool multiThreadedMessageLoop, IBrowserProcessHandler browserProcessHandler) { // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", ""); //Chromium Command Line args //http://peter.sh/experiments/chromium-command-line-switches/ //NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only. var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //The location where cache data will be stored on disk. If empty an in-memory cache will be used for some features and a temporary disk cache for others. //HTML5 databases such as localStorage will only persist across sessions if a cache path is specified. settings.CachePath = "cache"; //settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "1"); //settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //Enable WebRTC //settings.CefCommandLineArgs.Add("no-proxy-server", "1"); //Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed. //settings.CefCommandLineArgs.Add("debug-plugin-loading", "1"); //Dumps extra logging about plugin loading to the log file. //settings.CefCommandLineArgs.Add("disable-plugins-discovery", "1"); //Disable discovering third-party plugins. Effectively loading only ones shipped with the browser plus third-party ones as specified by --extra-plugin-dir and --load-plugin switches //settings.CefCommandLineArgs.Add("enable-system-flash", "1"); //Automatically discovered and load a system-wide installation of Pepper Flash. //settings.CefCommandLineArgs.Add("allow-running-insecure-content", "1"); //By default, an https page cannot run JavaScript, CSS or plugins from http URLs. This provides an override to get the old insecure behavior. Only available in 47 and above. //settings.CefCommandLineArgs.Add("enable-logging", "1"); //Enable Logging for the Renderer process (will open with a cmd prompt and output debug messages - use in conjunction with setting LogSeverity = LogSeverity.Verbose;) //settings.LogSeverity = LogSeverity.Verbose; // Needed for enable-logging to output messages //settings.CefCommandLineArgs.Add("disable-extensions", "1"); //Extension support can be disabled //settings.CefCommandLineArgs.Add("disable-pdf-extension", "1"); //The PDF extension specifically can be disabled //Load the pepper flash player that comes with Google Chrome - may be possible to load these values from the registry and query the dll for it's version info (Step 2 not strictly required it seems) //settings.CefCommandLineArgs.Add("ppapi-flash-path", @"C:\Program Files (x86)\Google\Chrome\Application\47.0.2526.106\PepperFlash\pepflashplayer.dll"); //Load a specific pepper flash version (Step 1 of 2) //settings.CefCommandLineArgs.Add("ppapi-flash-version", "20.0.0.228"); //Load a specific pepper flash version (Step 2 of 2) //NOTE: For OSR best performance you should run with GPU disabled: // `--disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling` // (you'll loose WebGL support but gain increased FPS and reduced CPU usage). // http://magpcss.org/ceforum/viewtopic.php?f=6&t=13271#p27075 //https://bitbucket.org/chromiumembedded/cef/commits/e3c1d8632eb43c1c2793d71639f3f5695696a5e8 //NOTE: The following function will set all three params //settings.SetOffScreenRenderingBestPerformanceArgs(); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-compositing", "1"); //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); //Disable Vsync //Disables the DirectWrite font rendering system on windows. //Possibly useful when experiencing blury fonts. //settings.CefCommandLineArgs.Add("disable-direct-write", "1"); settings.MultiThreadedMessageLoop = multiThreadedMessageLoop; settings.ExternalMessagePump = !multiThreadedMessageLoop; // Off Screen rendering (WPF/Offscreen) if (osr) { settings.WindowlessRenderingEnabled = true; //Disable Direct Composition to test https://github.com/cefsharp/CefSharp/issues/1634 //settings.CefCommandLineArgs.Add("disable-direct-composition", "1"); // DevTools doesn't seem to be working when this is enabled // http://magpcss.org/ceforum/viewtopic.php?f=6&t=14095 //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); } var proxy = ProxyConfig.GetProxyInformation(); switch (proxy.AccessType) { case InternetOpenType.Direct: { //Don't use a proxy server, always make direct connections. settings.CefCommandLineArgs.Add("no-proxy-server", "1"); break; } case InternetOpenType.Proxy: { settings.CefCommandLineArgs.Add("proxy-server", proxy.ProxyAddress); break; } case InternetOpenType.PreConfig: { settings.CefCommandLineArgs.Add("proxy-auto-detect", "1"); break; } } //settings.LogSeverity = LogSeverity.Verbose; if (DebuggingSubProcess) { var architecture = Environment.Is64BitProcess ? "x64" : "x86"; settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\" + architecture + "\\Debug\\CefSharp.BrowserSubprocess.exe"; } settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() //SchemeHandlerFactory = new InMemorySchemeAndResourceHandlerFactory() }); settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", SchemeHandlerFactory = new FolderSchemeHandlerFactory(rootFolder: @"..\..\..\..\CefSharp.Example\Resources", schemeName: "localfolder", //Optional param no schemename checking if null hostName: "cefsharp", //Optional param no hostname checking if null defaultPage: "home.html") //Optional param will default to index.html }); settings.RegisterExtension(new CefExtension("cefsharp/example", Resources.extension)); settings.FocusedNodeChangedEnabled = true; if (!Cef.Initialize(settings, performDependencyCheck: !DebuggingSubProcess, browserProcessHandler: browserProcessHandler)) { throw new Exception("Unable to Initialize Cef"); } }
public static void Init(CefSettingsBase settings, IBrowserProcessHandler browserProcessHandler) { // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_ID", ""); // Environment.SetEnvironmentVariable("GOOGLE_DEFAULT_CLIENT_SECRET", ""); //Chromium Command Line args //http://peter.sh/experiments/chromium-command-line-switches/ //NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only. //CEF specific command line args //https://bitbucket.org/chromiumembedded/cef/src/master/libcef/common/cef_switches.cc?fileviewer=file-view-default //**IMPORTANT**: For enabled/disabled command line arguments like disable-gpu specifying a value of "0" like //settings.CefCommandLineArgs.Add("disable-gpu", "0"); will have no effect as the second argument is ignored. //**IMPORTANT**: When using command line arguments the behaviour may change between Chromium versions, if you are experiencing //issues after upgrading to a newer version, you should remove all custom command line arguments and add test them in //isolation to determine if they are causing issues. //The command line arguments shown here are here as a reference only and are not tested to confirm they work with each version settings.RemoteDebuggingPort = 8088; //The location where cache data will be stored on disk. If empty an in-memory cache will be used for some features and a temporary disk cache for others. //HTML5 databases such as localStorage will only persist across sessions if a cache path is specified. settings.RootCachePath = Path.GetFullPath("cache"); //If non-null then CachePath must be equal to or a child of RootCachePath //We're using a sub folder. // settings.CachePath = Path.GetFullPath("cache\\global"); //settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent //settings.CefCommandLineArgs.Add("renderer-startup-dialog"); //settings.CefCommandLineArgs.Add("enable-media-stream"); //Enable WebRTC //settings.CefCommandLineArgs.Add("no-proxy-server"); //Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed. //settings.CefCommandLineArgs.Add("allow-running-insecure-content"); //By default, an https page cannot run JavaScript or CSS from http URLs. This provides an override to get the old insecure behavior. Only available in 47 and above. //https://peter.sh/experiments/chromium-command-line-switches/#disable-site-isolation-trials //settings.CefCommandLineArgs.Add("disable-site-isolation-trials"); //NOTE: Running the Network Service in Process is not something CEF officially supports //It may or may not work for newer versions. //settings.CefCommandLineArgs.Add("enable-features", "CastMediaRouteProvider,NetworkServiceInProcess"); //settings.CefCommandLineArgs.Add("enable-logging"); //Enable Logging for the Renderer process (will open with a cmd prompt and output debug messages - use in conjunction with setting LogSeverity = LogSeverity.Verbose;) //settings.LogSeverity = LogSeverity.Verbose; // Needed for enable-logging to output messages //settings.CefCommandLineArgs.Add("disable-extensions"); //Extension support can be disabled //settings.CefCommandLineArgs.Add("disable-pdf-extension"); //The PDF extension specifically can be disabled //Audo play example //settings.CefCommandLineArgs["autoplay-policy"] = "no-user-gesture-required"; //NOTE: For OSR best performance you should run with GPU disabled: // `--disable-gpu --disable-gpu-compositing --enable-begin-frame-scheduling` // (you'll loose WebGL support but gain increased FPS and reduced CPU usage). // http://magpcss.org/ceforum/viewtopic.php?f=6&t=13271#p27075 //https://bitbucket.org/chromiumembedded/cef/commits/e3c1d8632eb43c1c2793d71639f3f5695696a5e8 //NOTE: The following function will set all three params //settings.SetOffScreenRenderingBestPerformanceArgs(); //settings.CefCommandLineArgs.Add("disable-gpu"); //settings.CefCommandLineArgs.Add("disable-gpu-compositing"); //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync"); //Disable Vsync // The following options control accessibility state for all frames. // These options only take effect if accessibility state is not set by IBrowserHost.SetAccessibilityState call. // --force-renderer-accessibility enables browser accessibility. // --disable-renderer-accessibility completely disables browser accessibility. //settings.CefCommandLineArgs.Add("force-renderer-accessibility"); //settings.CefCommandLineArgs.Add("disable-renderer-accessibility"); //Enables Uncaught exception handler settings.UncaughtExceptionStackSize = 10; //Disable WebAssembly //settings.JavascriptFlags = "--noexpose_wasm"; // Off Screen rendering (WPF/Offscreen) if (settings.WindowlessRenderingEnabled) { //Disable Direct Composition to test https://github.com/cefsharp/CefSharp/issues/1634 //settings.CefCommandLineArgs.Add("disable-direct-composition"); // DevTools doesn't seem to be working when this is enabled // http://magpcss.org/ceforum/viewtopic.php?f=6&t=14095 //settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling"); } var proxy = ProxyConfig.GetProxyInformation(); switch (proxy.AccessType) { case InternetOpenType.Direct: { //Don't use a proxy server, always make direct connections. settings.CefCommandLineArgs.Add("no-proxy-server"); break; } case InternetOpenType.Proxy: { settings.CefCommandLineArgs.Add("proxy-server", proxy.ProxyAddress); break; } case InternetOpenType.PreConfig: { settings.CefCommandLineArgs.Add("proxy-auto-detect"); break; } } //settings.LogSeverity = LogSeverity.Verbose; //Experimental setting see https://bitbucket.org/chromiumembedded/cef/issues/2969/support-chrome-windows-with-cef-callbacks //for details //settings.ChromeRuntime = true; if (DebuggingSubProcess) { var architecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); #if NETCOREAPP settings.BrowserSubprocessPath = Path.GetFullPath("..\\..\\..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin.netcore\\" + architecture + "\\Debug\\netcoreapp3.1\\CefSharp.BrowserSubprocess.exe"); #else settings.BrowserSubprocessPath = Path.GetFullPath("..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\" + architecture + "\\Debug\\CefSharp.BrowserSubprocess.exe"); #endif } settings.CookieableSchemesList = "custom"; settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), IsSecure = true, //treated with the same security rules as those applied to "https" URLs }); settings.RegisterScheme(new CefCustomScheme { SchemeName = "https", SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), DomainName = ExampleDomain }); settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), IsSecure = true //treated with the same security rules as those applied to "https" URLs }); //You can use the http/https schemes - best to register for a specific domain settings.RegisterScheme(new CefCustomScheme { SchemeName = "https", SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), DomainName = "cefsharp.com", IsSecure = true //treated with the same security rules as those applied to "https" URLs }); const string cefSharpExampleResourcesFolder = #if !NETCOREAPP @"..\..\..\..\CefSharp.Example\Resources"; #else @"..\..\..\..\..\..\CefSharp.Example\Resources"; #endif settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", SchemeHandlerFactory = new FolderSchemeHandlerFactory(rootFolder: cefSharpExampleResourcesFolder, schemeName: "localfolder", //Optional param no schemename checking if null hostName: "cefsharp", //Optional param no hostname checking if null defaultPage: "home.html") //Optional param will default to index.html }); //This must be set before Cef.Initialized is called CefSharpSettings.FocusedNodeChangedEnabled = true; //Async Javascript Binding - methods are queued on TaskScheduler.Default. //Set this to true to when you have methods that return Task<T> //CefSharpSettings.ConcurrentTaskExecution = true; //Legacy Binding Behaviour - Same as Javascript Binding in version 57 and below //See issue https://github.com/cefsharp/CefSharp/issues/1203 for details //CefSharpSettings.LegacyJavascriptBindingEnabled = true; //Exit the subprocess if the parent process happens to close //This is optional at the moment //https://github.com/cefsharp/CefSharp/pull/2375/ CefSharpSettings.SubprocessExitIfParentProcessClosed = true; //NOTE: Set this before any calls to Cef.Initialize to specify a proxy with username and password //One set this cannot be changed at runtime. If you need to change the proxy at runtime (dynamically) then //see https://github.com/cefsharp/CefSharp/wiki/General-Usage#proxy-resolution //CefSharpSettings.Proxy = new ProxyOptions(ip: "127.0.0.1", port: "8080", username: "******", password: "******"); bool performDependencyCheck = !DebuggingSubProcess; if (!Cef.Initialize(settings, performDependencyCheck: performDependencyCheck, browserProcessHandler: browserProcessHandler)) { throw new Exception("Unable to Initialize Cef"); } Cef.AddCrossOriginWhitelistEntry(BaseUrl, "https", "cefsharp.com", false); }