-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Windows] Remove 2nd WebView used to add
base
tag when using HtmlWe…
…bViewSource (#21892) ### Description of Change This PR removes the use of a 2nd "hidden" WebView2 that was used to parse and add a HTML `base` tag to the `head` tag when setting the HTML source of a WebView to a string. This was done by appending the `base` tag script to the start of the user's HTML string, which the WebView then adds into the `head` element. While this is technically not valid HTML, all current browsers correct this behavior. This is a work-around for the lack of being able to set the base URL when navigating to a string using WebView2 (MicrosoftEdge/WebView2Feedback#530). As a bonus, using `HtmlWebViewSource` should now be 2x faster 😅 ### Issues Fixed Fixes #21631
- Loading branch information
Showing
5 changed files
with
73 additions
and
54 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/Controls/samples/Controls.Sample.UITests/Issues/Issue21631.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue21631"> | ||
<WebView | ||
AutomationId="WaitForWebView" | ||
x:Name="WaitForWebView"> | ||
<WebView.Source> | ||
<HtmlWebViewSource | ||
Html="<html><body><h1>hello world</h1><img src='appiconLargeTile.scale-100.png'/></html>"/> | ||
</WebView.Source> | ||
</WebView> | ||
</ContentPage> |
15 changes: 15 additions & 0 deletions
15
src/Controls/samples/Controls.Sample.UITests/Issues/Issue21631.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 21631, "Injecting base tag in Webview2 works", PlatformAffected.UWP)] | ||
public partial class Issue21631 : ContentPage | ||
{ | ||
public Issue21631() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.AppiumTests.Issues | ||
{ | ||
public class Issue21631 : _IssuesUITest | ||
{ | ||
public Issue21631(TestDevice device) : base(device) { } | ||
|
||
public override string Issue => | ||
"Injecting base tag in Webview2 works"; | ||
|
||
[Test] | ||
public async Task NavigateToStringWithWebviewWorks() | ||
{ | ||
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.iOS }); | ||
|
||
App.WaitForElement("WaitForWebView"); | ||
await Task.Delay(500); | ||
VerifyScreenshot(); | ||
} | ||
} | ||
} |
Binary file added
BIN
+9.86 KB
src/Controls/tests/UITests/snapshots/windows/NavigateToStringWithWebviewWorks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters