Method to Redirect BlazorWebView to Non-https://0.0.0.0 Address

2023年9月21日 70点热度 0人点赞 0条评论
内容目录

The source code has been studied for a long time, and its operating mechanism has been discovered. If the page that BlazorWebView navigates to is not https://0.0.0.0, then it will open the page in a browser outside the client.

// The URLs here are allowed to be opened in the browser
		public static readonly Uri[] URLS = new Uri[]
		{
            new Uri("https://open.feishu.cn")
		};

			this.webView.BlazorWebViewInitializing += (s, e) =>
			{
				this.webView.WebView.CoreWebView2InitializationCompleted += (s, e) =>
				{
					this.webView.UrlLoading += (s, e) =>
					{
						foreach (var item in URLS)
						{
							if (e.Url.IsBaseOf(item)|| e.Url.ToString().StartsWith(item.ToString()))
							{
							// Set loading strategy
								e.UrlLoadingStrategy = UrlLoadingStrategy.OpenInWebView;
								break;
							}
						}
					};
				};
			};

Then navigate to open:

WebView.CoreWebView2.Navigate(url)

痴者工良

高级程序员劝退师

文章评论