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

WebView2 Sample Code not working #18767

Open
datovy-edam opened this issue Nov 11, 2024 · 1 comment
Open

WebView2 Sample Code not working #18767

datovy-edam opened this issue Nov 11, 2024 · 1 comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/documentation triage/untriaged Indicates an issue requires triaging or verification

Comments

@datovy-edam
Copy link

On which page?

https://platform.uno/docs/articles/controls/WebView.html

What's wrong?

I created a brand-new project using uno platform templates (5.3) and updated the MainPage.xaml as follows:

<Page x:Class="UnoApp2.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:UnoApp2"
      xmlns:utu="using:Uno.Toolkit.UI"
      xmlns:um="using:Uno.Material"
      Background="{ThemeResource BackgroundBrush}">
    <Grid BorderBrush="Gray" BorderThickness="1" Padding="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Background="LightBlue">
            <TextBlock Text="Hello" />
        </StackPanel>
        <WebView2 Grid.Row="1" x:Name="WebBrowser" />
        <StackPanel Grid.Row="2" Background="LightBlue">
            <TextBlock Text="Goodbye" />
        </StackPanel>
    </Grid>
</Page>

Following the sample I wrote "MainPage.xml.cs":

using Microsoft.Web.WebView2.Core;

namespace UnoApp1.Presentation;

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        InitAsync();
    }
    public async Task InitAsync()
    {
        try
        {
            await WebBrowser.EnsureCoreWebView2Async();
            WebBrowser.CoreWebView2.SetVirtualHostNameToFolderMapping(
                "UnoNativeAssets",
                "WebContent",
                CoreWebView2HostResourceAccessKind.Allow);
            WebBrowser.CoreWebView2.Navigate("http://UnoNativeAssets/index.html");
        }
        catch (Exception ex)
        {

        }
    }
}

The above does not work in WinAppSDK, neither in WebAssembly.

Can you provide a VS (uno 5.2 and 5.3) simple Project that does work for both Win and WebAssembly targets?

I do have a project using (I guess) uno 5.2 with .Net 8.0 in where WebView2 works in WinAppSDK but not in WebAssembly. It looks like WebView2 is not implemented under WebAssembly in this case.

ANOTHER WEBVIEW2 ISSUE

Actually, that other application (see "https://github.com/datovy-edam/Edam.Data.Catalog") is using the Monaco Editor sample code in the uno-platform that uses WebView2 to view the editor and works as expected in WinAppSDK, but not in WebAssembly.

Any sugestions?

Hope to hear from you soon,

Eduardo

Any feedback?

No response

@datovy-edam datovy-edam added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/documentation triage/untriaged Indicates an issue requires triaging or verification labels Nov 11, 2024
@jeromelaban
Copy link
Member

Thanks for the report.

WebView2 support is in progress for some platforms, but we added support for Web in uno 5.5. It's required to upgrade the latest builds to use that feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/documentation triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

2 participants