unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.78k stars 707 forks source link

WebView2 - External links issue #17893

Open GCX-Monter opened 1 month ago

GCX-Monter commented 1 month ago

Current behavior

When clicking on external links, they continue to open inside WebView2.

Expected behavior

All external links that do not contain the original domain should open in the default browser on all devices.

How to reproduce it (as minimally and precisely as possible)

Open any external link from the starter site.

Workaround

Unfortunately, I haven't found any workarounds.

Works on UWP/WinUI

None

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

No response

Affected platforms

Android, iOS, Windows (WinAppSDK)

IDE

Visual Studio 2022

IDE version

Visual Studuo 17.9.1, UNO 5.2

Relevant plugins

No response

Anything else we need to know?

Greetings to all of you, Uno Platform team. In the previous request, @jeromelaban suggested creating issues separately, so I will start with the most fundamental one. Taking this opportunity, I want to say again that I love you guys very much. Before discovering Uno, I tested about 12 different development environments to find the best performing platform for WebView. And what I found with you... It is simply colossal! Nowhere before have I encountered such quality that you have been able to implement. It is truly phenomenal. I love all of you, every team member. I wish you guys that your efforts only flourish! I hope to thank you for all your efforts in the future.

Unfortunately, I encountered an issue where I cannot make external links open in the default browser on the device; all my attempts over the past 4 months have been in vain. At the moment, this particular issue is preventing the release of the application. The start page contains many links to external resources, and if the user clicks on one of them, it simply opens within the app itself, as if using a regular browser, but it shouldn't be this way. Ideally, it should be set for the app that if the device has an installed application for the service the user wants to navigate to from WebView2, it should launch that service's application directly.

Please help me solve this problem, I am really counting on you 🩵

P.S. @jeromelaban I also want to especially thank you for everything you have done for Uno since its inception. I was also very happy when you responded to my previous request. Thank you very much, you have no idea how wholeheartedly I am devoted to you for the enormous work you have created. You are probably the most dynamically developing development platform that I have had the chance to get acquainted with. I made my first WebView application in Java for Android, and then on Kotlin, many developers abandon the idea of using WebView due to its low performance, and although the speed was indeed low, I did not want to give up. I fell in love with the WebView technology, and was going to find a platform on which it would work best. Then I tried to develop on Flutter with various plugins, then on React Native/Expo, later on such as IONIC, Cordova, NativeScript and others. Then I tried on MAUI and also Xamarin. This entire journey took me about 5 months of daily work, often having to sit at the IDE for 12-15 hours a day to get everything up and running and compare. And, I distinctly remember the day I came across your official website and read that Uno Platform supports WebView2 on Android. I couldn't believe my eyes, but I reread it, and it really was so.. Then I almost jumped to the ceiling with joy, realizing what opportunities are now opening up. I had previously looked for ways to implement WebView2 on smartphones, but nothing was found before. And I remember the moment when I ran to my laptop to quickly try it out, test it! I remember the moment when I first compiled and launched the application on my smartphone, it was wonderful... How perfectly it worked, the performance and smoothness of WebView2 was impressive even then when I launched the application for the first time in January this year. And with each of your updates, it worked even better, even smoother and faster. How pleasant it was to work with you...

Please continue to develop WebView2, it is one of the coolest things you have implemented. You are the best ❤️‍🔥

jeromelaban commented 3 weeks ago

Thanks for the report.

If the behavior is the same on WinAppSDK, this is not something we will be able to change. That being said, you may be able to inject some javascript in pages that handles this differently when navigating to separate pages, or you may be able to detect navigation to a separate origin, cancel the navitation in WebView2, then open the URL in a separate browser.

@MartinZikmund may have some additional thoughts there.

MartinZikmund commented 3 weeks ago

If you are able to find some API in WebView2 that can provide this functionality, we can try to find way to surface analogous functionality on other platforms as well. If you have control over the site, you could use https://platform.uno/docs/articles/controls/WebView.html#javascript-to-c-communication to send a message to C# code and then use Launcher API to open a new window