Repository navigation
Description
Current behavior 🐛
While working on with adding / updating xml docs on the eventhandlers here:
I noticed WebView2.Properties.cs currently calls Uri.ToString() with the provided Uri to trigger Navigation:
| /// <summary> | |
| /// Identifies the Source dependency property. | |
| /// </summary> | |
| public static DependencyProperty SourceProperty { get; } = | |
| DependencyProperty.Register(nameof(Source), typeof(Uri), typeof(WebView2), new FrameworkPropertyMetadata(null, | |
| (s, e) => | |
| { | |
| var webView = (WebView2)s; | |
| if (!webView._sourceChangeFromCore) | |
| { | |
| webView.CoreWebView2.Navigate(((Uri)e.NewValue)?.ToString()); | |
| } | |
| })); |
Which redirects to CoreWebView2.cs:
uno/src/Uno.UI/UI/Xaml/Controls/WebView/Core/CoreWebView2.cs
Lines 54 to 68 in 5d44b17
| public void Navigate(string uri) | |
| { | |
| if (!Uri.TryCreate(uri, UriKind.Absolute, out var actualUri)) | |
| { | |
| throw new ArgumentException("The passed in value is not an absolute URI", nameof(uri)); | |
| } | |
| _processedSource = actualUri; | |
| if (_owner.SwitchSourceBeforeNavigating) | |
| { | |
| Source = actualUri.ToString(); | |
| } | |
| UpdateFromInternalSource(); | |
| } |
which could also possibly enhanced, to allow relative Uri instead of failing, by matching to the BaseUri
AND This does also introduce the excact same pitfall as shown in the samples below, in line 69, which even does now parse the Uri again like this.
Some Examples to better understand the potential pitfalls with the current implementation:
Example 1 — path with space encoded as %20
- Input:
new Uri("http://example.com/a%20b") OriginalString:http://example.com/a%20bToString():http://example.com/a b<-- potential problem!AbsoluteUri:http://example.com/a%20b
Example 2 — query containing an escaped ampersand %26
- Input:
new Uri("http://example.com/search?q=a%26b") OriginalString:http://example.com/search?q=a%26bToString():http://example.com/search?q=a&b<-- and potential problem!AbsoluteUri:http://example.com/search?q=a%26b
Expected behavior 🎯
Recommended behavior for WebView2.Properties.cs:**
- For network/browser navigation prefer a transport-safe, escaped absolute form: use
AbsoluteUrifor absolute Uris, and possibly resolve or fail/throw for relative Uris against a defined.BaseUribefore callingNavigate. - Avoid
Uri.ToString()for navigation because it returns a human-readable, partially unescaped form, while the Caller might already have had Escaped and parsed the required Destination Uri beforehand and not expects it do parse it like that / at all
How to reproduce it (as minimally and precisely as possible) 🔬
No response
Workaround 🛠️
No response
Renderer 🎨
- Skia
- Native
Affected platforms 📱💻🖥️
No response
Uno.Sdk version (and other relevant versions) 📦
No response
IDE version 🧑💻
No response
Anything else we need to know? 💬
Questions and suggestions:
- Are we using
ToString()here intentional? Maybe then prefer switching toUri.OriginalStringinstead, to avoid parsing beyond what the User is maybe expecting to happen - If the intent is to always navigate to transport-safe absolute URLs, should we instead:
- absolute Uris: check the provided Uri with
Uri.IsWellformedOriginalStringand callAbsoluteUriif true - relative Uris: resolve the provided Uri against the
.BaseUri?
- Is this behavior covered by tests? If yes, could you please add to the WebView2 Uno Specifics Docs your expectations to the provided Uri for the Consumers for navigation semantics for the escaped / pre-parsed requirements we need to pay attention to and eventual and relative Uri support in the future?
Thanks!
Activity
Jen-Uno commentedon Dec 12, 2025
@morning4coffe-dev
github-actions commentedon Apr 30, 2026
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests.