Пример #1
0
        public void StartOffscreenRender(string url)
        {
#if WITHCEF
            var settings = new CefSharp.OffScreen.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"),
            };

            // play with surfaces
            settings.SetOffScreenRenderingBestPerformanceArgs();

            //Perform dependency check to make sure all relevant resources are in our output directory.
            // Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            var rqs = new RequestContextSettings();
            rqs.CachePath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache");
            var rq = new RequestContext(rqs, null);

            var bs = new BrowserSettings();
            bs.BackgroundColor = 0xff000000;

            this.theOffscreenBrowser      = new CefSharp.OffScreen.ChromiumWebBrowser(url, bs, rq);
            this.theOffscreenBrowser.Size = new System.Drawing.Size(400, 800);
            this.theOffscreenBrowser.LoadingStateChanged += TheBrowser_LoadingStateChanged;
            this.theOffscreenBrowser.FrameLoadEnd        += TheOffscreenBrowser_FrameLoadEnd;
Пример #2
0
        /// <summary>
        /// Initialize OffScreen Cef
        /// Note that we MUST use OffScreen not WinForms CefSettings, can only use one Initialize
        /// </summary>

        public static void InitializeOffScreenCef()
        {
            if (Cef.IsInitialized)
            {
                return;
            }

            Stopwatch sw = Stopwatch.StartNew();

            //Monitor parent process exit and close subprocesses if parent process exits first
            //This will at some point in the future becomes the default
            CefSharpSettings.SubprocessExitIfParentProcessClosed = true;

            var settings = new CefSharp.OffScreen.CefSettings(); // not that we MUST use OffScreen not WinForms CefSettings

            settings.CachePath =                                 // By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                                 Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache");

            settings.SetOffScreenRenderingBestPerformanceArgs();

            //Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

            var cefVersion = string.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}",
                                           Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);

            if (Debug)
            {
                DebugLog.StopwatchMessage("OffScreen Cef initialized for " + cefVersion + ", Time: ", sw);
            }

            return;
        }