From f316caf0f0f0ea3e052536d4b7a519270912140f Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Mon, 13 Jul 2026 10:23:23 +0530 Subject: [PATCH 1/5] Fixed Android Webview font size issue --- .../Android/BlazorWebViewHandler.Android.cs | 1 + .../TestCases.HostApp/Issues/Issue26924.cs | 70 +++++++++++++++++++ .../Tests/Issues/Issue26924.cs | 26 +++++++ .../src/Platform/Android/WebViewExtensions.cs | 3 + 4 files changed, 100 insertions(+) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs diff --git a/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs b/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs index ff348f135250..ceecb2aeeece 100644 --- a/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs +++ b/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs @@ -49,6 +49,7 @@ protected override AWebView CreatePlatformView() blazorAndroidWebView.Settings.JavaScriptEnabled = true; blazorAndroidWebView.Settings.DomStorageEnabled = true; + blazorAndroidWebView.Settings.MinimumFontSize = 1; } _webViewClient = new WebKitWebViewClient(this); diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs new file mode 100644 index 000000000000..e76df4415a92 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs @@ -0,0 +1,70 @@ +namespace Maui.Controls.Sample.Issues +{ + [Issue(IssueTracker.Github, 26924, "Font Size of span Element Not Rendering Correctly in Mobile Mode in .NET MAUI Blazor", PlatformAffected.All)] + public class Issue26924 : TestContentPage + { + WebView _webView; + Label _resultLabel; + Button _checkButton; + + const string SmallFontSpanId = "smallFontSpan"; + const string paraFontSpanId = "paraFontSpanId"; + internal const string SmallFontCssValue = "4.87761px"; + + protected override void Init() + { + var html = $@" + + + + +

Hii this is Para

+ tiny span text + + "; + + _webView = new WebView + { + Source = new HtmlWebViewSource { Html = html }, + HeightRequest = 100, + AutomationId = "SmallFontWebView" + }; + + _resultLabel = new Label + { + Text = "Not checked yet", + AutomationId = "ComputedFontSizeLabel" + }; + + _checkButton = new Button + { + Text = "Get computed font size of span", + AutomationId = "CheckFontSizeButton", + Command = new Command(async () => await CheckComputedFontSizeAsync()) + }; + + // Update the result label once the WebView finishes loading the HTML, so the test + // can wait for "WebView loaded" before tapping the button instead of racing navigation. + _webView.Navigated += (_, __) => _resultLabel.Text = "WebView loaded"; + + Content = new VerticalStackLayout + { + Children = + { + new Label { Text = $"Expected computed font-size to stay close to {SmallFontCssValue} (i.e. under 8px), not be clamped up by the platform WebView's minimum font size." }, + _webView, + _checkButton, + _resultLabel + } + }; + } + + async Task CheckComputedFontSizeAsync() + { + var computedFontSize = await _webView.EvaluateJavaScriptAsync( + $"window.getComputedStyle(document.getElementById('{SmallFontSpanId}')).fontSize"); + + _resultLabel.Text = computedFontSize?.Trim('"') ?? string.Empty; + } + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs new file mode 100644 index 000000000000..ad9ecafe0adc --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue26924 : _IssuesUITest +{ + public Issue26924(TestDevice device) : base(device) + { + } + + public override string Issue => "Font Size of span Element Not Rendering Correctly in Mobile Mode in .NET MAUI Blazor"; + + [Test] + [Category(UITestCategories.WebView)] + public void SmallFontSizeSpanIsNotClampedByMinimumFontSize() + { + // The result label is updated to "WebView loaded" once the WebView finishes loading + // the HTML, so wait for that before tapping the button to avoid racing navigation. + App.WaitForTextToBePresentInElement("ComputedFontSizeLabel", "WebView loaded"); + App.Tap("CheckFontSizeButton"); + Assert.That(App.WaitForElement("ComputedFontSizeLabel").GetText(), Is.EqualTo("4.87761px")); + } +} + diff --git a/src/Core/src/Platform/Android/WebViewExtensions.cs b/src/Core/src/Platform/Android/WebViewExtensions.cs index f09cd7397f23..f3d00a5b001b 100644 --- a/src/Core/src/Platform/Android/WebViewExtensions.cs +++ b/src/Core/src/Platform/Android/WebViewExtensions.cs @@ -39,6 +39,9 @@ public static void UpdateSettings(this AWebView platformWebView, IWebView webVie platformWebView.Settings.JavaScriptEnabled = javaScriptEnabled; platformWebView.Settings.DomStorageEnabled = domStorageEnabled; + // Android WebView defaults MinimumFontSize to 8, which silently + // clamps up any CSS font-size below 8px. + platformWebView.Settings.MinimumFontSize = 1; } public static void UpdateUserAgent(this AWebView platformWebView, IWebView webView) From 2d82913c5e274042163b38d47e51de68bdb13d59 Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Tue, 14 Jul 2026 11:39:05 +0530 Subject: [PATCH 2/5] updated review concern --- .../src/Maui/Android/BlazorWebViewHandler.Android.cs | 1 + src/Core/src/Platform/Android/WebViewExtensions.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs b/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs index ceecb2aeeece..b17cbf20af75 100644 --- a/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs +++ b/src/BlazorWebView/src/Maui/Android/BlazorWebViewHandler.Android.cs @@ -50,6 +50,7 @@ protected override AWebView CreatePlatformView() blazorAndroidWebView.Settings.JavaScriptEnabled = true; blazorAndroidWebView.Settings.DomStorageEnabled = true; blazorAndroidWebView.Settings.MinimumFontSize = 1; + blazorAndroidWebView.Settings.MinimumLogicalFontSize = 1; } _webViewClient = new WebKitWebViewClient(this); diff --git a/src/Core/src/Platform/Android/WebViewExtensions.cs b/src/Core/src/Platform/Android/WebViewExtensions.cs index f3d00a5b001b..10635091583a 100644 --- a/src/Core/src/Platform/Android/WebViewExtensions.cs +++ b/src/Core/src/Platform/Android/WebViewExtensions.cs @@ -42,6 +42,7 @@ public static void UpdateSettings(this AWebView platformWebView, IWebView webVie // Android WebView defaults MinimumFontSize to 8, which silently // clamps up any CSS font-size below 8px. platformWebView.Settings.MinimumFontSize = 1; + platformWebView.Settings.MinimumLogicalFontSize = 1; } public static void UpdateUserAgent(this AWebView platformWebView, IWebView webView) From a160386455e5ae69c3c8b0759b7bf9b48d446b1a Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Tue, 14 Jul 2026 17:35:46 +0530 Subject: [PATCH 3/5] Added review concerns --- .../Elements/BlazorWebViewTests.Behaviors.cs | 71 +++++++++++++++++++ .../TestCases.HostApp/Issues/Issue26924.cs | 1 - 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs b/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs index 561f29063fe0..17650944f9a0 100644 --- a/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs +++ b/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs @@ -43,4 +43,75 @@ await InvokeOnMainThreadAsync(async () => }); } #endif + +#if ANDROID + const string SmallFontSpanId = "smallFontSpan"; + const string SmallFontCssValue = "4.87761px"; + + static class SmallFontTestStaticFilesContents + { + public const string SmallFontIndexHtmlContent = @" + + + + + + Blazor app + + + + + tiny span text +
+ +
+ An unhandled error has occurred. + Reload + 🗙 +
+ + + + + +"; + } + + /// + /// Regression test for https://github.com/dotnet/maui/issues/26924 - verifies that + /// BlazorWebViewHandler.Android.cs sets MinimumFontSize/MinimumLogicalFontSize to 1 so + /// small CSS font sizes (below the Android WebView's default 8px minimum) aren't clamped up. + /// + [Fact] + public async Task BlazorWebViewDoesNotClampSmallCssFontSizes() + { + EnsureHandlerCreated(additionalCreationActions: appBuilder => + { + appBuilder.Services.AddMauiBlazorWebView(); + }); + + var bwv = new BlazorWebViewWithCustomFiles + { + HostPage = "wwwroot/index.html", + CustomFiles = new Dictionary + { + { "index.html", SmallFontTestStaticFilesContents.SmallFontIndexHtmlContent }, + }, + }; + bwv.RootComponents.Add(new RootComponent { ComponentType = typeof(NoOpComponent), Selector = "#app", }); + + await InvokeOnMainThreadAsync(async () => + { + var bwvHandler = CreateHandler(bwv); + var platformWebView = bwvHandler.PlatformView; + await WebViewHelpers.WaitForWebViewReady(platformWebView); + + var computedFontSize = await WebViewHelpers.ExecuteScriptAsync( + platformWebView, + $"window.getComputedStyle(document.getElementById('{SmallFontSpanId}')).fontSize"); + + Assert.Equal($"\"{SmallFontCssValue}\"", computedFontSize); + }); + } +#endif } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs index e76df4415a92..9dff5eb3604f 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs @@ -8,7 +8,6 @@ public class Issue26924 : TestContentPage Button _checkButton; const string SmallFontSpanId = "smallFontSpan"; - const string paraFontSpanId = "paraFontSpanId"; internal const string SmallFontCssValue = "4.87761px"; protected override void Init() From 46bcc2cd3b12a710470dffa10a1c5bbf562b6d2b Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Wed, 15 Jul 2026 17:47:43 +0530 Subject: [PATCH 4/5] updated review concern --- .../Elements/BlazorWebViewTests.Behaviors.cs | 10 ++++++---- .../TestCases.Shared.Tests/Tests/Issues/Issue26924.cs | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs b/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs index 17650944f9a0..dd08c6158925 100644 --- a/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs +++ b/src/BlazorWebView/tests/DeviceTests/Elements/BlazorWebViewTests.Behaviors.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components.WebView.Maui; @@ -105,12 +107,12 @@ await InvokeOnMainThreadAsync(async () => var bwvHandler = CreateHandler(bwv); var platformWebView = bwvHandler.PlatformView; await WebViewHelpers.WaitForWebViewReady(platformWebView); - - var computedFontSize = await WebViewHelpers.ExecuteScriptAsync( + var computedFontSizeJson = await WebViewHelpers.ExecuteScriptAsync( platformWebView, - $"window.getComputedStyle(document.getElementById('{SmallFontSpanId}')).fontSize"); + $"parseFloat(window.getComputedStyle(document.getElementById('{SmallFontSpanId}')).fontSize)"); + var computedFontSize = double.Parse(computedFontSizeJson, CultureInfo.InvariantCulture); - Assert.Equal($"\"{SmallFontCssValue}\"", computedFontSize); + Assert.True(computedFontSize < 8, $"Expected computed font size to be under the 8px clamp, but was {computedFontSize}px."); }); } #endif diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs index ad9ecafe0adc..2c94c801e6bd 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs @@ -1,3 +1,4 @@ +using System.Globalization; using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -20,7 +21,10 @@ public void SmallFontSizeSpanIsNotClampedByMinimumFontSize() // the HTML, so wait for that before tapping the button to avoid racing navigation. App.WaitForTextToBePresentInElement("ComputedFontSizeLabel", "WebView loaded"); App.Tap("CheckFontSizeButton"); - Assert.That(App.WaitForElement("ComputedFontSizeLabel").GetText(), Is.EqualTo("4.87761px")); + var computedFontSizeText = App.WaitForElement("ComputedFontSizeLabel").GetText(); + Assert.That(computedFontSizeText, Is.Not.Null); + var computedFontSize = float.Parse(computedFontSizeText!.TrimEnd('p', 'x'), CultureInfo.InvariantCulture); + Assert.That(computedFontSize, Is.LessThan(8f)); } } From 8af6beea9bafaadc34291cdc7e00c5f14047dfdb Mon Sep 17 00:00:00 2001 From: Subhiksha Chandrasekaran Date: Thu, 16 Jul 2026 11:53:43 +0530 Subject: [PATCH 5/5] updated test sample review concerns --- src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs | 2 +- .../tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs index 9dff5eb3604f..b610ef46e652 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26924.cs @@ -17,7 +17,7 @@ protected override void Init() -

Hii this is Para

+

Hi, this is a paragraph.

tiny span text "; diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs index 2c94c801e6bd..5a8225c43ca6 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs @@ -21,10 +21,10 @@ public void SmallFontSizeSpanIsNotClampedByMinimumFontSize() // the HTML, so wait for that before tapping the button to avoid racing navigation. App.WaitForTextToBePresentInElement("ComputedFontSizeLabel", "WebView loaded"); App.Tap("CheckFontSizeButton"); + App.WaitForTextToBePresentInElement("ComputedFontSizeLabel", "px"); var computedFontSizeText = App.WaitForElement("ComputedFontSizeLabel").GetText(); Assert.That(computedFontSizeText, Is.Not.Null); - var computedFontSize = float.Parse(computedFontSizeText!.TrimEnd('p', 'x'), CultureInfo.InvariantCulture); - Assert.That(computedFontSize, Is.LessThan(8f)); + Assert.That(float.Parse(computedFontSizeText!.Trim().TrimEnd('p', 'x'), CultureInfo.InvariantCulture), Is.LessThan(8f)); } }