-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathWebViewManager.cs
31 lines (27 loc) · 978 Bytes
/
WebViewManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace Aila;
public class WebViewManager: ContentView
{
private Dictionary<string, WebView> _webViews = new();
public WebView GetWebViewForUrl(string url)
{
if (!_webViews.ContainsKey(url))
{
var webView = new WebView
{
UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15",
Source = new UrlWebViewSource { Url = url }
};
_webViews[url] = webView;
}
return _webViews[url];
}
// 新增方法:在指定的 WebView 中执行 JavaScript
public async Task<string> EvaluateJavaScriptAsync(string url, string script)
{
if (_webViews.ContainsKey(url))
{
return await _webViews[url].EvaluateJavaScriptAsync(script);
}
throw new InvalidOperationException("WebView not found for the provided URL.");
}
}