3D WebView has APIs for setting the browser's User-Agent string (Web.SetUserAgent() and IWithSettableUserAgent), but it doesn't have a dedicated API for getting the browser's User-Agent. However, you can get the browser's User-Agent using the navigator.userAgent JavaScript API. If you have an existing WebViewPrefab or CanvasWebViewPrefab in your scene, you can use it to get the User-Agent, like this:
// TODO: User the Editor to set this field to the
// WebViewPrefab or CanvasWebViewPrefab in your scene.
BaseWebViewPrefab webViewPrefab;
async void Awake() {
await webViewPrefab.WaitUntilInitialized();
// A page must be loaded first in order to execute JavaScript.
await webViewPrefab.WebView.WaitForNextPageLoadToFinish();
var userAgent = await webViewPrefab.WebView.ExecuteJavaScript("navigator.userAgent");
Debug.Log("User-Agent: " + userAgent);
}
Or if you want to check the User-Agent before creating a WebViewPrefab or CanvasWebViewPrefab, your app can create a temporary IWebView just for checking the User-Agent, like this:
async void Awake() {
var webView = Web.CreateWebView();
await webView.Init(100, 100);
// A page must be loaded first in order to execute JavaScript.
webView.LoadUrl("about:blank");
await webView.WaitForNextPageLoadToFinish();
var userAgent = await webView.ExecuteJavaScript("navigator.userAgent");
webView.Dispose();
Debug.Log("User-Agent: " + userAgent);
}