Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two webviews in one winform won't work #204

Closed
PaulYBChiang opened this issue May 24, 2020 · 7 comments
Closed

Two webviews in one winform won't work #204

PaulYBChiang opened this issue May 24, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@PaulYBChiang
Copy link

PaulYBChiang commented May 24, 2020

It's really weird that if I add two webview2s in one WinForm, only one works and the other always sleeping. The code is pretty straight forward.

   private void Form1_Load(object sender, EventArgs e)
    {
        webView21.Source = new Uri(url1);
        webView22.Source = new Uri(url2);
    }

AB#26584427

@nicholasdgoodman
Copy link

I have observed something similar yesterday - it appears timing related. I could get multiple views on one form only if I put a delay between their creation.

@david-risney david-risney added .NET bug Something isn't working labels May 26, 2020
@david-risney
Copy link
Contributor

Thanks for reporting the issue! We'll look into this a get back to you.

@mikemeinz
Copy link

@PaulYBChiang
@nicholasdgoodman

This works for me.

using System;
using Imports Microsoft.Web.WebView2.Core;
public partial class Main
{
    public Main()
    {
        this.Load += WebView2Test_Load;
    }

    private string HTMLText1 = "<!doctype html><html lang=\"en\"><head><title>Test 1</title></head><body><p>Test 1</p></body></html>";
    private string HTMLText2 = "<!doctype html><html lang=\"en\"><head><title>Test 2</title></head><body><p>Test 2</p></body></html>";

    public void WebView2Test_Load(object sender, EventArgs e)
    {
        InitializeAsync();
    }

    public async void InitializeAsync()
    {
        await WebView21.EnsureCoreWebView2Async();
        WebView21.NavigateToString(HTMLText1);
        await WebView22.EnsureCoreWebView2Async();
        WebView22.NavigateToString(HTMLText2);
    }
}

@oggy22
Copy link
Member

oggy22 commented Oct 9, 2020

We are working on the issue. The problem seems to be the same UserDataFolder. Even though officially supported it seems to be problematic in Winforms, so a temporary workaround for this issue before it's fixed would be choosing not default UserDataFolder for the second webview2.

    var createProps = new CoreWebView2CreationProperties();
    createProps.UserDataFolder += "2";
    webView22.CreationProperties = createProps;

@mikemeinz
Copy link

@oggy22

CoreWebView2CreationProperties() is in Microsoft.Web.WebView2.Wpf. It doesn't seem right to use a class that is part of the WPF part of WebView2 in a WinForms app. Furthermore, CreationProperties() is not in WebView2.

WebView2 Version 0.9.628-prerelease

Imports Microsoft.Web.WebView2.Core
Imports Microsoft.Web.WebView2.Wpf


 24       Dim createProps As New CoreWebView2CreationProperties
 25       createProps.UserDataFolder += "2"
 26       WebView22.CreationProperties = createProps
 27       Await WebView22.EnsureCoreWebView2Async()

VB .NET IDE gives these errors: for lines 25 and 26

Error	BC30652	Reference required to assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' containing the type 'DependencyObject'. Add one to your project.	WebMon	C:\Users\Me\Documents\Visual Studio 2017\Projects\WebCam\WebMon\Main.vb	25	Active
Error	BC30456	'CreationProperties' is not a member of 'WebView2'.	WebMon	C:\Users\Me\Documents\Visual Studio 2017\Projects\WebCam\WebMon\Main.vb	26	Active

@champnic
Copy link
Member

We're adding CreationProperties support to Winforms in the next release. In the meantime, you can accomplish the workaround by explicitly creating the environment instead of using the Source property, and specifying the UserDataFolder there:
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/dotnet/0-9-628/microsoft-web-webview2-core-corewebview2environment#createasync

We're currently working on a fix for the underlying issue.

@champnic
Copy link
Member

This should be fixed in WebView2 SDK 1.0.674-prerelease. If this is still failing please let us know. Thanks!

@champnic champnic added this to the SDK 1.0.674-prerelease milestone Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants