Use of WebView2 in Studio plugins

Dear developers,

I was wondering if some of you have experience with the WebView2 component in Studio plugins.

I followed the instructions here: Get started with WebView2 in WinForms apps - Microsoft Edge Development | Microsoft Docs and can create a Windows Form app which displays a webpage using webview2. I tried to do the same in a Studio plugin but I am not successful. I have added references to the core and winform dlls of webview2 in the plugin manifest. When running the plugin, the winform window opens but the browser is not displayed (empty winform). Any idea about what is missing?

I first initiated the discussion in another post (see here) and Paul Filkin told me about the cefsharp component used in the Report Viewer Plus. I will have a look at cefsharp, as it sounds interesting.

Thank you for your support.

Laurent

Parents Reply Children
  • Dear ,

    Thank you for your prompt reply. I already had a look at the Report Viewer in Github and still did not manage to make CefSharp work in my plugin. I was going through all steps again to describe them here when I noticed that the package for WPF (used in Report Viewer) is slightly different from the one for Winforms that I want to use. After noticing this and combining it with other information found here and here, I finally managed to use CefSharp as browser in my plugin.

    Here are the steps I followed, in case it is of any use for other community members:

    1. Add CefSharp.WinForms (version 96.0.170) NuGet package to the project
    2. Change pluginmanifest and included the following references (this is based on what is used in Reports Viewer + other references which were missing when running the plugin for the first time). It might be that all references are not required:

    <Include>
    	<File>CefSharp.WinForms.dll</File>
    	<File>CefSharp.Core.dll</File>
    
    	<File>x86\CefSharp.dll</File>
    	<File>x86\CefSharp.Core.Runtime.dll</File>
    	<File>x86\CefSharp.BrowserSubprocess.Core.dll</File>
    	<File>x86\CefSharp.BrowserSubprocess.exe</File>
    
    	<File>x86\chrome_elf.dll</File>
    	<File>x86\libcef.dll</File>
    	<File>x86\icudtl.dat</File>
    	<File>x86\libEGL.dll</File>
    	<File>x86\libGLESv2.dll</File>
    
    	<File>x86\chrome_100_percent.pak</File>
    	<File>x86\chrome_200_percent.pak</File>
    
    	<File>x86\snapshot_blob.bin</File>
    	<File>x86\v8_context_snapshot.bin</File>
    
    	<File>x86\resources.pak</File>
    	<File>x86\d3dcompiler_47.dll</File>
    	<File>x86\CefSharp.Core.dll</File>
    	<File>x86\locales\en-US.pak</File>
    </Include>

    3. Add <CefSharpAnyCpuSupport>true</CefSharpAnyCpuSupport> to the first <PropertyGroup> in the csproj file
    4. Add the following code to the form which should display the browser:

    namespace CefSharpPlugin
    {
        public partial class TestForm : Form
        {
            public ChromiumWebBrowser _chromiumBrowser;
    
            public TestForm()
            {
                CefRuntime.SubscribeAnyCpuAssemblyResolver();
    
                InitializeComponent();
    
                InitializeCefSharp();
            }
    
            [MethodImpl(MethodImplOptions.NoInlining)]
            private void InitializeCefSharp()
            {
                var settings = new CefSettings();
                settings.BrowserSubprocessPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"x86\CefSharp.BrowserSubprocess.exe");
    
                Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
    
                _chromiumBrowser = new ChromiumWebBrowser(WebSiteURLasString);
                this.Controls.Add(_chromiumBrowser);
                _chromiumBrowser.Dock = DockStyle.Fill;
            }
    
            private void TestForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                Cef.Shutdown();
            }
        }
    }

    Subscribe to any CPU should be done before any component is initialized. Important is also to set the Browser Suprocess Path. I set the performDependencyCheck to false because it raised an error in debugging.

    I don't know if it is the best way to do it but at least it worked for me.

    Nevertheless, I am still not 100% convinced by CefSharp. My plugin size is over a 130MB and accessing DOM objects does not look straightforward. If anyone has experience with Webview2, which implementation and use seems closer to the one of the old Webbrowser control, I am still interested.

    Thanks.

    Laurent