private static void Main(string[] args) { // Load CEF. This checks for the correct CEF version. CefRuntime.Load(); // Start the secondary CEF process. var cefMainArgs = new CefMainArgs(new string[0]); var cefApp = new DemoCefApp(); // This is where the code path divereges for child processes. if (CefRuntime.ExecuteProcess(cefMainArgs, cefApp) != -1) { Console.Error.WriteLine("CefRuntime could not the secondary process."); } // Settings for all of CEF (e.g. process management and control). var cefSettings = new CefSettings { SingleProcess = false, MultiThreadedMessageLoop = true }; // Start the browser process (a child process). CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp); // Instruct CEF to not render to a window at all. CefWindowInfo cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsOffScreen(IntPtr.Zero); // Settings for the browser window itself (e.g. should JavaScript be enabled?). var cefBrowserSettings = new CefBrowserSettings(); // Initialize some the cust interactions with the browser process. // The browser window will be 1280 x 720 (pixels). var cefClient = new DemoCefClient(1280, 720); // Start up the browser instance. string url = "http://www.reddit.com/"; CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, url); // Hang, to let the browser to do its work. Console.WriteLine("Press a key at any time to end the program."); Console.ReadKey(); // Clean up CEF. CefRuntime.Shutdown(); }
public bool InitializeBrowser() { AllocConsole(); CefRuntime.Load(); var settings = new CefSettings(); settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows; settings.ReleaseDCheckEnabled = true; settings.LogSeverity = CefLogSeverity.Info; settings.LogFile = "cef.log"; //settings.ResourcesDirPath = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath); settings.RemoteDebuggingPort = 20480; settings.Locale = "zh-CN"; var a = Config.JsFunctionAssembly; var mainArgs = new CefMainArgs(new string[0]); var app = new DemoCefApp(); var exitCode = CefRuntime.ExecuteProcess(mainArgs, app); Console.WriteLine("CefRuntime.ExecuteProcess() returns {0}", exitCode); //返回值-1为成功 if (exitCode != -1) { return(false); } //初始化 CefRuntime.Initialize(mainArgs, settings, app); CefRuntime.RegisterSchemeHandlerFactory("http", DumpRequestDomain, new DemoAppSchemeHandlerFactory()); browserCtl = new CefWebBrowser(); browserCtl.Parent = this.panel1; browserCtl.Dock = DockStyle.Fill; browserCtl.BringToFront(); var browser = browserCtl.WebBrowser; browser.StartUrl = HomeUrl; //navBox.Attach(browser); return(true); }