public static void Init(bool osr) { // 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("ppapi-flash-path", @"C:\WINDOWS\SysWOW64\Macromed\Flash\pepflashplayer32_18_0_0_209.dll"); //Load a specific pepper flash version (Step 1 of 2) //settings.CefCommandLineArgs.Add("ppapi-flash-version", "18.0.0.209"); //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"); // Off Screen rendering (WPF/Offscreen) if(osr) { settings.WindowlessRenderingEnabled = true; // Disable Surfaces so internal PDF viewer works for OSR // https://bitbucket.org/chromiumembedded/cef/issues/1689 //settings.CefCommandLineArgs.Add("disable-surfaces", "1"); settings.EnableInternalPdfViewerOffScreen(); 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() }); settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); settings.RegisterExtension(new CefExtension("cefsharp/example", Resources.extension)); Cef.OnContextInitialized = delegate { var cookieManager = Cef.GetGlobalCookieManager(); cookieManager.SetStoragePath("cookies", true); cookieManager.SetSupportedSchemes("custom"); }; if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: !DebuggingSubProcess)) { throw new Exception("Unable to Initialize Cef"); } }
private void initEditor() { // cef setting var setting = new CefSettings(); setting.RegisterScheme(new CefCustomScheme() { SchemeName = LocalSchemeHandler.SchemeName, SchemeHandlerFactory = new LocalSchemeHanlderFactory() }); Cef.Initialize(setting); // var editorInfo = new FileInfo(@".\static\editor.html"); // _browser = new ChromiumWebBrowser(editorInfo.FullName) _browser = new ChromiumWebBrowser("http://cef/editor.html") { Dock = DockStyle.Fill }; _browser.RegisterJsObject("cef", new CefCallTest()); mainPanel.Controls.Add(_browser); }
private static void InitializeCefSharp() { var 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"); settings.CefCommandLineArgs.Add("--disable-web-security"); settings.CefCommandLineArgs.Add("enable-gpu", "1"); settings.CefCommandLineArgs.Add("enable-webgl", "1"); settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); settings.CefCommandLineArgs.Add("--off-screen-frame-rate", "60"); settings.RegisterScheme(new CefCustomScheme { SchemeName = ResourceSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new ResourceSchemeHandlerFactory() }); settings.RegisterScheme(new CefCustomScheme { SchemeName = FileSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new FileSchemeHandlerFactory() }); // Make sure you set performDependencyCheck false Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); }
public static void Initialize() { //todo: grab all the cool settings stuff from the main github repo winforms sample var settings = new CefSettings(); settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); //https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting settings.CefCommandLineArgs.Add("disable-gpu", "1"); //https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting settings.CachePath = "cache"; // Register localfile scheme settings.RegisterScheme(new CefCustomScheme() { IsStandard = true, SchemeName = LocalFileSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new LocalFileSchemeHandlerFactory() }); // Register resouce scheme settings.RegisterScheme(new CefCustomScheme() { SchemeName = EmbeddedResourceSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new EmbeddedResourceSchemeHandlerFactory() }); Cef.Initialize(settings); }
public static void Initialize() { //todo: grab all the cool settings stuff from the main github repo winforms sample var settings = new CefSettings(); settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1");//https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting settings.CefCommandLineArgs.Add("disable-gpu", "1");//https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting settings.CachePath = "cache"; // Register localfile scheme settings.RegisterScheme(new CefCustomScheme() { IsStandard = true, SchemeName = LocalFileSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new LocalFileSchemeHandlerFactory() }); // Register resouce scheme settings.RegisterScheme(new CefCustomScheme() { SchemeName = EmbeddedResourceSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new EmbeddedResourceSchemeHandlerFactory() }); Cef.Initialize(settings); }
public void RegisterSchemeHandlers() { // Register scheme handlers object[] schemeHandlerObjs = IoC.GetAllInstances(typeof(ChromelySchemeHandler)); if (schemeHandlerObjs != null) { var schemeHandlers = schemeHandlerObjs.ToList(); foreach (var item in schemeHandlers) { if (item is ChromelySchemeHandler) { ChromelySchemeHandler handler = (ChromelySchemeHandler)item; if (handler.HandlerFactory == null) { if (handler.UseDefaultResource) { m_settings.RegisterScheme(new CefCustomScheme { SchemeName = handler.SchemeName, DomainName = handler.DomainName, IsSecure = handler.IsSecure, IsCorsEnabled = handler.IsCorsEnabled, SchemeHandlerFactory = new CefSharpResourceSchemeHandlerFactory() }); } if (handler.UseDefaultHttp) { m_settings.RegisterScheme(new CefCustomScheme { SchemeName = handler.SchemeName, DomainName = handler.DomainName, IsSecure = handler.IsSecure, IsCorsEnabled = handler.IsCorsEnabled, SchemeHandlerFactory = new CefSharpHttpSchemeHandlerFactory() }); } } else if (handler.HandlerFactory is ISchemeHandlerFactory) { if (item is ChromelySchemeHandler) { m_settings.RegisterScheme(new CefCustomScheme { SchemeName = handler.SchemeName, DomainName = handler.DomainName, IsSecure = handler.IsSecure, IsCorsEnabled = handler.IsCorsEnabled, SchemeHandlerFactory = (ISchemeHandlerFactory)handler.HandlerFactory }); } } } } } }
public void InitBrowser() { var settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", DomainName = "cefsharp", SchemeHandlerFactory = new FolderSchemeHandlerFactory( rootFolder: @"C:\Users\sp\source\repos\WpfApp3_WebBrowser\WpfApp3_WebBrowser\wwwroot", hostName: "cefsharp", defaultPage: "CSWebSampleInterop.html" // will default to index.html ) }); Cef.Initialize(settings); //CefSharpSettings.WcfEnabled = true; webBrowser = new ChromiumWebBrowser("localfolder://cefsharp/"); webBrowser.Height = 400; webBrowser.JavascriptObjectRepository.Settings.LegacyBindingEnabled = true; webBrowser.JavascriptObjectRepository.Register("csObj", jsCallbackObj); webPanel.Children.Add(webBrowser); }
//// Will attempt to load missing assembly from either x86 or x64 subdir //// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU //static Assembly Resolver(object sender, ResolveEventArgs args) //{ // if (args.Name.StartsWith("CefSharp")) { // string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll"; // string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, // Environment.Is64BitProcess ? "x64" : "x86", // assemblyName); // return File.Exists(archSpecificPath) // ? Assembly.LoadFile(archSpecificPath) // : null; // } // return null; //} //[MethodImpl(MethodImplOptions.NoInlining)] private static void initializeCefSharp() { var settings = new CefSettings { RemoteDebuggingPort = 8088, }; settings.RegisterScheme(new CefCustomScheme { SchemeName = "lyrics", DomainName = "live", SchemeHandlerFactory = new FolderSchemeHandlerFactory( rootFolder: @"D:\P_Dev\Prolyric\ProLyric\data", hostName: "live", defaultPage: "index.html" // will default to index.html ) }); //// Set BrowserSubProcessPath based on app bitness at runtime: //settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, // Environment.Is64BitProcess ? "x64" : "x86", // "CefSharp.BrowserSubprocess.exe"); //// Make sure you set performDependencyCheck to false: //Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); // Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); Cef.Initialize(settings); }
protected void InitializeWebView() { CefSettings settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = AppSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new AppSchemeHandlerFactory(AppProcess.DomainPath) }); // Initialize cef with the provided settings Cef.Initialize(settings); // Create a browser component WebView = new ChromiumWebBrowser($"{AppSchemeHandlerFactory.SchemeName}://{ViewName}") { Dock = DockStyle.Fill }; ApplyDependencies(); WebView.IsBrowserInitializedChanged += OnWebViewInitialised; // Add it to the form and fill it to the form window. this.Controls.Add(WebView); }
public static void Init() { // 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", ""); var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "renderer-startup-dialog"); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "1"); 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() }); if (!Cef.Initialize(settings)) { throw new Exception("Unable to Initialize Cef"); } }
private bool InitCEF() { Cef.EnableHighDPISupport(); var exitCode = Cef.ExecuteProcess(); if (exitCode >= 0) { return(false); } scheme = new CefCustomScheme() { DomainName = "local.com", IsCorsEnabled = false, IsCSPBypassing = true, IsSecure = false, SchemeName = "http", SchemeHandlerFactory = new AppScheme(Program.BasePath, "http://local.com") }; settings = new CefSettings() { RemoteDebuggingPort = 54477, IgnoreCertificateErrors = true, }; settings.RegisterScheme(scheme); CefSharpSettings.WcfEnabled = true; CefSharpSettings.WcfTimeout = TimeSpan.FromSeconds(10); CefSharpSettings.LegacyJavascriptBindingEnabled = true; Cef.Initialize(settings); return(true); }
private static void InitializeCef(AppConfiguration appConfiguration) { if (Cef.IsInitialized) return; string assetsDir = @"..\assets"; Directory.CreateDirectory(assetsDir); var settings = new CefSettings { PersistSessionCookies = appConfiguration.PersistSessionCookies, PersistUserPreferences = appConfiguration.PersistUserPreferences, CachePath = appConfiguration.CachePath, UserDataPath = appConfiguration.UserDataPath }; settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", DomainName = "cefsharp", SchemeHandlerFactory = new FolderSchemeHandlerFactory( @"..\assets", hostName: "cefsharp" ) }); Cef.EnableHighDPISupport(); Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); }
public static void Init() { Cef.EnableHighDPISupport(); CefSharpSettings.ShutdownOnExit = false; var settings = new CefSettings() { // Increase the log severity so CEF outputs detailed information, useful for debugging LogSeverity = LogSeverity.Verbose, // By default CEF uses an in memory cache, to save cached data e.g. passwords you need to specify a cache path // NOTE: The executing user must have sufficient privileges to write to this folder. CachePath = "cache" }; settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe"); settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", DomainName = "cefsharp", SchemeHandlerFactory = new FolderSchemeHandlerFactory(rootFolder: GetPath(@"Library\html"), hostName: "cefsharp", //Optional param no hostname/domain checking if null defaultPage: "home.html") //Optional param will default to index.html }); Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); }
public static void Init() { var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; if (debuggingSubProcess) { settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\x86\\Debug\\CefSharp.BrowserSubprocess.exe"; } settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); if (!Cef.Initialize(settings)) { if (Environment.GetCommandLineArgs().Contains("--type=renderer")) { Environment.Exit(0); } else { return; } } Cef.RegisterJsObject("bound", new BoundObject()); }
private void InitializeChromium() { try { CefSettings settings = new CefSettings(); string workingDirectory = Environment.CurrentDirectory; string projectDirectory = Directory.GetParent(workingDirectory).Parent.FullName; settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", DomainName = "cefsharp", SchemeHandlerFactory = new FolderSchemeHandlerFactory( rootFolder: projectDirectory + @"\..\Webpage", hostName: "cefsharp", defaultPage: "index.html" // will default to index.html ) }); // Initizlie cef with provided settins. if (Cef.IsInitialized == false) { Cef.Initialize(settings); } chromeBrowser = new ChromiumWebBrowser("localfolder://cefsharp/"); this.Controls.Add(chromeBrowser); chromeBrowser.Dock = DockStyle.Fill; } catch (Exception ex) { MessageBox.Show("Webpage not found. " + ex.Message, "SCC Kiosk", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private static void InitializeCef() { if (!Cef.IsInitialized) { CefSettings cefSettings = new CefSettings(); cefSettings.LogSeverity = LogSeverity.Disable; cefSettings.UncaughtExceptionStackSize = 100; cefSettings.CachePath = WebView.TempDir; cefSettings.WindowlessRenderingEnabled = true; CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSharpSettings.SubprocessExitIfParentProcessClosed = true; foreach (string schemeName in WebView.CustomSchemes) { cefSettings.RegisterScheme(new CefCustomScheme { SchemeName = schemeName, SchemeHandlerFactory = new CefSchemeHandlerFactory() }); } cefSettings.BrowserSubprocessPath = CefLoader.GetBrowserSubProcessPath(); Cef.Initialize(cefSettings, false, browserProcessHandler: null); if (System.Windows.Application.Current != null) { System.Windows.Application.Current.Exit += WebView.OnApplicationExit; WebView.subscribedApplicationExit = true; } } }
private static void InitializeCef() { if (!Cef.IsInitialized) { var cefSettings = new CefSettings(); cefSettings.LogSeverity = string.IsNullOrWhiteSpace(LogFile) ? LogSeverity.Disable : (EnableErrorLogOnly ? LogSeverity.Error : LogSeverity.Verbose); cefSettings.LogFile = LogFile; cefSettings.UncaughtExceptionStackSize = 100; // enable stack capture cefSettings.CachePath = TempDir; // enable cache for external resources to speedup loading cefSettings.WindowlessRenderingEnabled = true; CefSharpSettings.ConcurrentTaskExecution = true; CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSharpSettings.SubprocessExitIfParentProcessClosed = true; foreach (var scheme in CustomSchemes) { cefSettings.RegisterScheme(new CefCustomScheme() { SchemeName = scheme, SchemeHandlerFactory = new CefSchemeHandlerFactory() }); } cefSettings.BrowserSubprocessPath = CefLoader.GetBrowserSubProcessPath(); Cef.Initialize(cefSettings, performDependencyCheck: false, browserProcessHandler: null); if (Application.Current != null) { Application.Current.Exit += OnApplicationExit; subscribedApplicationExit = true; } } }
private void CefInitialize() { if (!Cef.IsInitialized) { var isDefault = AppDomain.CurrentDomain.IsDefaultAppDomain(); if (!isDefault) { throw new Exception(@"Add <add key=""xunit.appDomain"" value=""denied""/> to your app.config to disable appdomains"); } Cef.EnableWaitForBrowsersToClose(); CefSharpSettings.ShutdownOnExit = false; var settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = "https", SchemeHandlerFactory = new CefSharpSchemeHandlerFactory(), DomainName = CefExample.ExampleDomain }); //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 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Tests\\Cache"); settings.RootCachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Tests"); Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); } }
private static void InitializeCefSharp() { var settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = "http", DomainName = "internal", IsLocal = true, SchemeHandlerFactory = new FolderSchemeHandlerFactory( rootFolder: @"WebResources", hostName: "internal", defaultPage: "map.html" ), }); #if DEBUG settings.RemoteDebuggingPort = 8088; #endif // Set BrowserSubProcessPath based on app bitness at runtime //System.Windows.Forms.MessageBox.Show(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, // Environment.Is64BitProcess ? "x64" : "x86").ToString()); settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "CefSharp.BrowserSubprocess.exe"); // Make sure you set performDependencyCheck false Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); }
public ViewportView(ViewportWindowViewModel vm) { if (vm == null) { return; } this.DataContext = vm; // CEF will already by loaded by sandbox or revit if (!Cef.IsInitialized) { var settings = new CefSettings { RemoteDebuggingPort = 8088 }; settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); Cef.Initialize(settings); } InitializeComponent(); // When view model is updated call javascript update function vm.PropertyChanged += ExecuteJavascript; }
/// <summary> /// this is done just once, to globally initialize CefSharp/CEF /// </summary> private void InitBrowser() { CefSettings settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = "CefSpider", SchemeHandlerFactory = new SchemeHandlerFactory() }); settings.UserAgent = UserAgent; settings.IgnoreCertificateErrors = true; settings.CachePath = GetAppDir("Cache"); settings.Locale = "zh-CN"; //配置代理运行 //settings.CefCommandLineArgs.Add("no-proxy-server", "1"); settings.CefCommandLineArgs.Add("proxy-server", "192.168.1.60:9999"); Cef.Initialize(settings, true, true);//Cef.Initialize(settings); dHandler = new DownloadHandler(this); lHandler = new LifeSpanHandler(this); mHandler = new ContextMenuHandler(this); kHandler = new KeyboardHandler(this); rHandler = new RequestHandler(this); InitDownloads(); host = new HostHandler(this); AddNewBrowser(tabStrip1, HomepageURL); }
public static void Init() { var settings = new CefSettings(); //settings.RemoteDebuggingPort = 8088; settings.LogSeverity = LogSeverity.Verbose; settings.CefCommandLineArgs.Add("js-flags", "--harmony-proxies"); //if (debuggingSubProcess) //{ // settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\x86\\Debug\\CefSharp.BrowserSubprocess.exe"; //} settings.BrowserSubprocessPath = "CefSharp.WinForms.Example.exe"; settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); if (!Cef.Initialize(settings)) { if (Environment.GetCommandLineArgs().Contains("--type=renderer")) { Environment.Exit(0); } else { return; } } Cef.RegisterJsObject("bound", new BoundObject()); }
public void DoInit() { #region Cef.IsInitialized try { if (!Cef.IsInitialized) { LogUtil.HWLogger.UI.InfoFormat("init cefsharp..."); //Cef.EnableHighDPISupport(); CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSettings settings = new CefSettings() { CachePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache") //, PackLoadingDisabled = true }; settings.RegisterScheme(new CefCustomScheme() { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); settings.UserAgent = "FD Browser" + Cef.CefSharpVersion; //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("no-proxy-server", "1"); settings.CefCommandLineArgs.Add("disable-plugins-discovery", "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 = true; //Chromium Command Line args //http://peter.sh/experiments/chromium-command-line-switches/ //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); settings.WindowlessRenderingEnabled = true;//Set to true (1) to enable windowless (off-screen) rendering support. Do not enable this value if the application does not use windowless rendering as it may reduce rendering performance on some systems. //Cef.Initialize(settings, true, false); Cef.Initialize(settings); //首次加载页面需要等待cef初始化完成 SafeInvoke(form, () => { form.JumpToPage(form.Url); }); mEvent.WaitOne(); Cef.Shutdown(); } } catch (TaskCanceledException te) { LogUtil.HWLogger.UI.Error("Error occurred when init cefsharp(TaskCanceledException): ", te); } catch (Exception ex) { LogUtil.HWLogger.UI.Error("Error occurred when init cefsharp: ", ex); } #endregion }
/// <summary> /// 设置代理 /// </summary> /// <param name="ProxyAddress"></param> //public void Init(string ProxyAddress) //{ // Init(ProxyAddress, false); // //if (!Cef.IsInitialized) // //{ // // var setting = new CefSharp.CefSettings(); // // setting.RegisterScheme(new CefCustomScheme // // { // // SchemeName = CefSharpSchemeHandlerFactory.SchemeName, // // SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() // // }); // // setting.CachePath = "cache";//设置代理 // // setting.CefCommandLineArgs.Add("proxy-server", ProxyAddress);//设置代理 // // // 设置语言 // // setting.Locale = "zh-CN"; // en-US // // Cef.Initialize(setting); // // // CefSharp.Cef.Initialize(setting, true, false); // //} //} /// <summary> /// 初始化 /// </summary> /// <param name="ProxyAddress">代理地址</param> /// <param name="phone">User-Agent设置为iphone手机浏览器</param> public void Init(string ProxyAddress, bool phone = false) { if (!Cef.IsInitialized) { var setting = new CefSettings(); setting.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); //设置代理 if (!string.IsNullOrEmpty(ProxyAddress)) { setting.CachePath = "cache"; //设置代理 setting.CefCommandLineArgs.Add("proxy-server", ProxyAddress); //设置代理 } //设置手机 if (phone) { setting.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53"; } // 设置语言 setting.Locale = "zh-CN"; // en-US setting.AcceptLanguageList = "zh-CN"; Cef.Initialize(setting); //Cef.Initialize() // CefSharp.Cef.Initialize(setting, true, false); } }
private bool InitCef() { //// refer here: //// https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp.Example/CefExample.cs#L54 var settings = new CefSettings { CachePath = FileUtils.GetBrowserCacheFolder(), LogFile = FileUtils.GetBrowserLogFilePath(), LogSeverity = LogSeverity.Info }; settings.CefCommandLineArgs.Add("no-proxy-server", "1"); settings.CefCommandLineArgs.Add("force-device-scale-factor", "1"); //// this setting is automatically added. It means that if the user has //// Pepper Flash installed it will be detected and used. //// settings.CefCommandLineArgs.Add("enable-system-flash", "1"); // custom pdf scheme... settings.RegisterScheme(new CefCustomScheme { SchemeName = PdfSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new PdfSchemeHandlerFactory(), IsCSPBypassing = true }); // prevents orphaned CelSharp.BrowserSubprocess.exe instances // caused by an OnlyM crash. CefSharpSettings.SubprocessExitIfParentProcessClosed = true; return(Cef.Initialize(settings)); }
public static void Init() { var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "renderer-startup-dialog"); 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() }); if (!Cef.Initialize(settings)) { if (Environment.GetCommandLineArgs().Contains("--type=renderer")) { Environment.Exit(0); } else { return; } } }
/// <summary> /// this is done just once, to globally initialize CefSharp/CEF /// </summary> private void InitBrowser() { CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSharpSettings.WcfEnabled = false; CefSettings settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = InternalURL, SchemeHandlerFactory = new SchemeHandlerFactory() }); settings.UserAgent = UserAgent; settings.AcceptLanguageList = AcceptLanguage; settings.IgnoreCertificateErrors = true; settings.CachePath = GetAppDir("Cache"); //settings.BrowserSubprocessPath = AppDomain.CurrentDomain.BaseDirectory + "PortDiscrd.Subprocess.exe"; Cef.Initialize(settings); dHandler = new DownloadHandler(this); lHandler = new LifeSpanHandler(this); mHandler = new ContextMenuHandler(this); kHandler = new KeyboardHandler(this); rHandler = new RequestHandler(this); InitDownloads(); host = new HostHandler(this); AddNewBrowser(tabStrip1, HomepageURL); }
static BrowserContext() { CefSharpSettings.SubprocessExitIfParentProcessClosed = true; Cef.EnableHighDPISupport(); var settings = new CefSettings() { LogSeverity = LogSeverity.Verbose, BrowserSubprocessPath = Process.GetCurrentProcess().MainModule.FileName, CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Nano\\Cache") }; settings.CefCommandLineArgs.Add("no-proxy-server"); settings.CefCommandLineArgs.Add("disable-plugins-discovery"); settings.CefCommandLineArgs.Add("disable-extensions"); settings.CefCommandLineArgs.Add("disable-pdf-extension"); settings.CefCommandLineArgs.Add("disable-demo-mode"); settings.CefCommandLineArgs.Add("disable-default-apps"); settings.CefCommandLineArgs.Add("disable-dinosaur-easter-egg"); settings.CefCommandLineArgs.Add("disable-features", "ExtendedMouseButtons"); //@TODO: Move UI to server-side settings.RegisterScheme(new CefCustomScheme { SchemeName = "localfolder", DomainName = "nano", SchemeHandlerFactory = new FolderSchemeHandlerFactory( rootFolder: @"ui", hostName: "nano" ) }); Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); }
private void IniCefSettings() { CefSharpSettings.LegacyJavascriptBindingEnabled = true; var settings = new CefSettings(); settings.Locale = "zh-CN"; settings.AcceptLanguageList = settings.Locale; settings.MultiThreadedMessageLoop = true; settings.CefCommandLineArgs.Add("enable-media-stream", "1"); settings.CefCommandLineArgs.Add("no-proxy-server", "1"); settings.LogSeverity = LogSeverity.Disable; var subprocess = getBrowserSubprocess(); if (subprocess != null) { settings.BrowserSubprocessPath = subprocess.FullName; } var cachedir = new DirectoryInfo(Path.Combine(LocalPath.CurrentTempPath.FullName, "cache")); if (cachedir.Exists) { cachedir.Delete(true); } settings.CachePath = cachedir.FullName; var schemes = getCefCustomSchemes(); foreach (var scheme in schemes) { settings.RegisterScheme(scheme); } Cef.Initialize(settings); Cef.EnableHighDPISupport(); }
public ViewportWindow(ViewportWindowViewModel vm) { if (!Cef.IsInitialized) { var settings = new CefSettings { RemoteDebuggingPort = 8088 }; settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); Cef.Initialize(settings); } InitializeComponent(); // When view model is updated call javascript update function if (vm == null) { return; } vm.PropertyChanged += ExecuteJavascript; // Center initial viewport window upon launch WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; ScriptTextBox.KeyDown += new KeyEventHandler(textBoxKeyDown); }
/// <summary> /// this is done just once, to globally initialize CefSharp/CEF /// </summary> private void InitBrowser() { CefSettings settings = new CefSettings(); settings.Locale = "zh-CN"; //指定flash的版本,不使用系统安装的flash版本 settings.CefCommandLineArgs.Add("ppapi-flash-path", System.AppDomain.CurrentDomain.BaseDirectory + "plugins\\pepflashplayer.dll"); var flashVerison = "18.0.0.160"; settings.CefCommandLineArgs.Add("ppapi-flash-version", flashVerison); settings.RegisterScheme(new CefCustomScheme { SchemeName = "v5yxBrowser", SchemeHandlerFactory = new SchemeHandlerFactory() }); settings.UserAgent = UserAgent; settings.IgnoreCertificateErrors = true; settings.CachePath = GetAppDir("Cache"); Cef.Initialize(settings); dHandler = new DownloadHandler(this); lHandler = new LifeSpanHandler(this); mHandler = new ContextMenuHandler(this); kHandler = new KeyboardHandler(this); rHandler = new RequestHandler(this); InitDownloads(); host = new HostHandler(this); AddNewBrowser(tabStrip1, HomepageURL); }
/// <summary> /// this is done just once, to globally initialize CefSharp/CEF /// </summary> private void InitBrowser() { CefSettings settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = "WebBrowserDemo", SchemeHandlerFactory = new SchemeHandlerFactory() }); settings.UserAgent = UserAgent; settings.IgnoreCertificateErrors = true; settings.CachePath = GetAppDir("Cache"); Cef.Initialize(settings); dHandler = new DownloadHandler(this); lHandler = new LifeSpanHandler(this); mHandler = new ContextMenuHandler(this); kHandler = new KeyboardHandler(this); rHandler = new RequestHandler(this); InitDownloads(); host = new HostHandler(this); AddNewBrowser(tabStrip1, HomepageURL); }
private static void InitializeCef() { if (!Cef.IsInitialized) { var cefSettings = new CefSettings(); cefSettings.LogSeverity = LogSeverity.Disable; // disable writing of debug.log cefSettings.UncaughtExceptionStackSize = 100; // enable stack capture cefSettings.CachePath = TempDir; // enable cache for external resources to speedup loading CefSharpSettings.LegacyJavascriptBindingEnabled = true; foreach (var scheme in CustomSchemes) { cefSettings.RegisterScheme(new CefCustomScheme() { SchemeName = scheme, SchemeHandlerFactory = new CefSchemeHandlerFactory() }); } cefSettings.BrowserSubprocessPath = CefLoader.GetBrowserSubProcessPath(); Cef.Initialize(cefSettings, performDependencyCheck: false, browserProcessHandler: null); if (Application.Current != null) { Application.Current.Exit += OnApplicationExit; subscribedApplicationExit = true; } } }
static void RegisterSettings() { var settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme() { SchemeName = LocalSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new LocalSchemeHandlerFactory() }); Cef.Initialize(settings); }
public MainWindow() { var settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeHandlerFactory = new LocalSchemeHandlerFactory(), SchemeName = LocalSchemeHandler.SchemeName }); Cef.Initialize(settings); InitializeComponent(); }
private static void InitializeCef() { var cefSettings = new CefSettings(); cefSettings.RegisterScheme(new CefCustomScheme() { SchemeName = "local", SchemeHandlerFactory = new CustomSchemeHandlerfactory(), }); cefSettings.RegisterScheme(new CefCustomScheme() { SchemeName = "embedded", SchemeHandlerFactory = new CustomSchemeHandlerfactory(), }); if (!Cef.Initialize(cefSettings)) { throw new Exception("Unable to Initialize Cef"); } }
private static void StartChromiumBrowser() { Cef.EnableHighDPISupport(); var settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = LocalSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new LocalSchemeHandlerFactory() }); Cef.Initialize(settings); }
protected override void OnCreateMainForm() { var settings = new CefSettings(); settings.LogSeverity = LogSeverity.Disable; settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); if (!Cef.Initialize(settings)) { throw new Exception("Unable to Initialize Cef"); } MainForm = new FormMain(); }
public static void Init() { // 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: Note all relevant in relation to `CefSharp`, use for reference purposes only. var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "renderer-startup-dialog"); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "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. //Disables the DirectWrite font rendering system on windows. //Possibly useful when experiencing blury fonts. //settings.CefCommandLineArgs.Add("disable-direct-write", "1"); 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() }); if (!Cef.Initialize(settings)) { throw new Exception("Unable to Initialize Cef"); } }
public BrowserWrapper(string url) { var factory = new LocalSchemeHandlerFactory(); var settings = new CefSettings(); settings.RegisterScheme(new CefCustomScheme { SchemeName = "local", SchemeHandlerFactory = factory }); CefSharp.Cef.Initialize(settings); _browser = new ChromiumWebBrowser(url); _browser.BrowserSettings = new BrowserSettings() { FileAccessFromFileUrlsAllowed = true, UniversalAccessFromFileUrlsAllowed = true, TabToLinksDisabled = true }; _handler = new QCmdHandler(new CommandStore(), new EngineWrapper()); _browser.RegisterJsObject("qcmd", new QCmdCallback(_handler), false); }
private void InitializeCef() { CefSettings settings = new CefSettings(); settings.Locale = "en-US"; settings.RegisterScheme(new CefCustomScheme() { IsDisplayIsolated = true, IsStandard = true, SchemeName = AppSchemeHandlerFactory.SchemeName, SchemeHandlerFactory = new AppSchemeHandlerFactory() }); Cef.Initialize(settings, true, true); }
public static void Init() { // 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; //settings.UserAgent = "CefSharp Browser" + Cef.CefSharpVersion; // Example User Agent //settings.CefCommandLineArgs.Add("renderer-process-limit", "1"); //settings.CefCommandLineArgs.Add("renderer-startup-dialog", "renderer-startup-dialog"); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "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. //Disables the DirectWrite font rendering system on windows. //Possibly useful when experiencing blury fonts. //settings.CefCommandLineArgs.Add("disable-direct-write", "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() }); Cef.OnContextInitialized = delegate { Cef.SetCookiePath("cookies", true); }; //Cef will check if all dependencies are present //For special case when Checking Windows Xp Dependencies //DependencyChecker.IsWindowsXp = true; if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: !DebuggingSubProcess)) { throw new Exception("Unable to Initialize Cef"); } }
public static void Init(bool osr, bool multiThreadedMessageLoop) { // 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("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; // Off Screen rendering (WPF/Offscreen) if(osr) { settings.WindowlessRenderingEnabled = true; // Disable Surfaces so internal PDF viewer works for OSR // https://bitbucket.org/chromiumembedded/cef/issues/1689 //settings.CefCommandLineArgs.Add("disable-surfaces", "1"); settings.EnableInternalPdfViewerOffScreen(); settings.CefCommandLineArgs.Add("enable-begin-frame-scheduling", "1"); // Disable GPU in WPF and Offscreen examples until #1634 has been resolved settings.CefCommandLineArgs.Add("disable-gpu", "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() }); settings.RegisterScheme(new CefCustomScheme { SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest, SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() }); settings.RegisterExtension(new CefExtension("cefsharp/example", Resources.extension)); settings.FocusedNodeChangedEnabled = true; //The Request Context has been initialized, you can now set preferences, like proxy server settings Cef.OnContextInitialized = delegate { var cookieManager = Cef.GetGlobalCookieManager(); cookieManager.SetStoragePath("cookies", true); cookieManager.SetSupportedSchemes("custom"); //Dispose of context when finished - preferable not to keep a reference if possible. using (var context = Cef.GetGlobalRequestContext()) { string errorMessage; //You can set most preferences using a `.` notation rather than having to create a complex set of dictionaries. //The default is true, you can change to false to disable context.SetPreference("webkit.webprefs.plugins_enabled", true, out errorMessage); } }; if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: !DebuggingSubProcess)) { throw new Exception("Unable to Initialize Cef"); } }
public static void Init() { // 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", "renderer-startup-dialog"); //settings.CefCommandLineArgs.Add("disable-gpu", "1"); //settings.CefCommandLineArgs.Add("disable-gpu-vsync", "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 //Disables the DirectWrite font rendering system on windows. //Possibly useful when experiencing blury fonts. //settings.CefCommandLineArgs.Add("disable-direct-write", "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() }); Cef.OnContextInitialized = delegate { Cef.SetCookiePath("cookies", true); }; if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: !DebuggingSubProcess)) { 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 FrameworkElement Initialize() { if (!Cef.IsInitialized) { var path = PluginsManager.Instance.GetPluginDirectory("CefSharp"); var settings = new CefSettings { UserAgent = DefaultUserAgent, MultiThreadedMessageLoop = true, LogSeverity = LogSeverity.Disable, CachePath = FilesStorage.Instance.GetTemporaryFilename(@"Cef"), UserDataPath = FilesStorage.Instance.GetTemporaryFilename(@"Cef"), BrowserSubprocessPath = Path.Combine(path, "CefSharp.BrowserSubprocess.exe"), LocalesDirPath = Path.Combine(path, "locales"), ResourcesDirPath = Path.Combine(path), Locale = SettingsHolder.Locale.LocaleName, #if DEBUG RemoteDebuggingPort = 45451, #endif }; settings.RegisterScheme(new CefCustomScheme { SchemeName = AltFilesHandlerFactory.SchemeName, SchemeHandlerFactory = new AltFilesHandlerFactory() }); Cef.Initialize(settings, false, null); } _requestHandler = new RequestHandler { UserAgent = DefaultUserAgent }; _inner = new ChromiumWebBrowser { BrowserSettings = { FileAccessFromFileUrls = CefState.Enabled, UniversalAccessFromFileUrls = CefState.Enabled, WebSecurity = CefState.Disabled }, RequestHandler = _requestHandler, MenuHandler = new MenuHandler() }; _inner.FrameLoadStart += OnFrameLoadStart; _inner.FrameLoadEnd += OnFrameLoadEnd; return _inner; }