Search code examples
c#wpfchromium-embeddedcefsharp

Chromium Embedded WPF Browser control redraws every second whenever document changes. Workaround?


It seems like a bug in package (v49.0.1). To reproduce - create new WPF project, set its architecture to x86 or x64, add CefSharp.Wpf NuGet package. Restart VS, compile. Add ChromiumBrowser to MainWinoow.xaml with Address property set to any URL, like "http://stackoverflow.com". Run application.

What I see is browser redrawing every second, completely unusable. WinForms version works fine. Since my whole big project depends on CEF - any clues what to do? What can cause control to redraw like crazy?

Update:

I found what triggers it: any DOM change. Static pages are displayed correctly. I also found that v47.0.4 works fine with WPF and dynamic content. I'd rather avoid using it because of breaking changes in API introduced in version 49.0.0.

It seems like a bug, actually it's know issue posted on GitHub as issue #1666: https://github.com/cefsharp/CefSharp/issues/1666

It's also in release notes for v49.0.0 https://github.com/cefsharp/CefSharp/releases/tag/v49.0.0

See the answer for workaroud I found.


Solution

  • Here:

    public partial class App : Application {
    
        protected override void OnStartup(StartupEventArgs e) {
            var cefSettings = new CefSettings();
            cefSettings.SetOffScreenRenderingBestPerformanceArgs();
            Cef.Initialize(cefSettings);
        }
    
    }
    

    As a workaround some specific options can be set with SetOffScreenRenderingBestPerformanceArgs() in CefSettings object passed to Cef.Initialize(). This should be called before any CEF control is created, best in App.xaml.cs in OnStartup() override.