Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue32030.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 32030, "Android - WebView in a grid expands beyond it's cell", PlatformAffected.Android)]

public class Issue32030 : ContentPage
{
WebView webView;

public Issue32030()
{
// Create Grid
var grid = new Grid
{
RowDefinitions = new RowDefinitionCollection
{
new RowDefinition { Height = new GridLength(50) },
new RowDefinition { Height = GridLength.Star },
new RowDefinition { Height = new GridLength(50) }
}
};

// Create "above webview" Label
var topLabel = new Label
{
Text = "Above webview",
AutomationId = "TopLabel",
HorizontalTextAlignment = TextAlignment.Center
};
grid.Add(topLabel);
Grid.SetRow(topLabel, 0);

// Create WebView
webView = new WebView
{
BackgroundColor = Colors.BurlyWood
};
webView.Navigated += WebView_Navigated;
grid.Add(webView);
Grid.SetRow(webView, 1);

// Create "below webview" Label
var bottomLabel = new Label
{
Text = "Below webview",
HorizontalTextAlignment = TextAlignment.Center
};
grid.Add(bottomLabel);
Grid.SetRow(bottomLabel, 2);

// Set the grid as the page content
Content = grid;
}

async void WebView_Navigated(object sender, WebNavigatedEventArgs e)
{
await DisplayAlert("Navigation Completed", $"WebView navigated to: {e.Url}", "OK");
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue32030 : _IssuesUITest
{
public Issue32030(TestDevice device) : base(device) { }

public override string Issue => "Android - WebView in a grid expands beyond it's cell";
[Test]
[Category(UITestCategories.WebView)]
public void VerifyWebViewStaysWithinGridCell()
{
App.WaitForElement("TopLabel");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion src/Core/src/Platform/Android/MauiWebViewClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override void OnPageFinished(WebView? view, string? url)
bool navigate = _navigationResult != WebNavigationResult.Failure || !GetValidUrl(url).Equals(_lastUrlNavigatedCancel, StringComparison.OrdinalIgnoreCase);
_lastUrlNavigatedCancel = _navigationResult == WebNavigationResult.Cancel ? url : null;

if (navigate)
if (navigate && !IsBlankNavigation(url))
handler.VirtualView.Navigated(handler.CurrentNavigationEvent, GetValidUrl(url), _navigationResult);

handler.SyncPlatformCookiesToVirtualView(url);
Expand Down Expand Up @@ -96,6 +96,15 @@ public override bool OnRenderProcessGone(WebView? view, RenderProcessGoneDetail?
bool NavigatingCanceled(string? url) =>
!_handler.TryGetTarget(out var handler) || handler.NavigatingCanceled(url);

static bool IsBlankNavigation(string? url)
{
if (string.IsNullOrWhiteSpace(url))
return false;

// Check if URL is about:blank (case insensitive)
return string.Equals(url.Trim(), "about:blank", StringComparison.OrdinalIgnoreCase);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could expand to more variants?

Examples:

  • "about:blank#"
  • "about:blank/"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be invoked on every Navigation. The impact on performance now is minimal for the current simple string comparison, but take this into account (for example, if think in use URI parsing or more complex stuff).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , When the source is null, we set the default WebView source to about:blank. As a result, the OnPageFinished method always receives about:blank as the parameter. Therefore, handling additional variants such as about:blank# or about:blank/ is not necessary in this case.
image

}

static string GetValidUrl(string? url)
{
if (string.IsNullOrEmpty(url))
Expand Down
4 changes: 4 additions & 0 deletions src/Core/src/Platform/Android/WebViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static void UpdateSource(this AWebView platformWebView, IWebView webView,
platformWebView.UpdateCanGoBackForward(webView);
}
}
else
{
platformWebView.LoadUrl("about:blank");
}
}

public static void UpdateSettings(this AWebView platformWebView, IWebView webView, bool javaScriptEnabled, bool domStorageEnabled)
Expand Down