getUserAgent method

  1. @override
Future<String?> getUserAgent()

Gets the value used for the HTTP User-Agent: request header.

Implementation

@override
Future<String?> getUserAgent() async {
  final String? customUserAgent = await _webView.getCustomUserAgent();
  // Despite the official documentation of `WKWebView.customUserAgent`, the
  // default value seems to be an empty String and not null. It's possible it
  // could depend on the iOS version, so this checks for both.
  if (customUserAgent != null && customUserAgent.isNotEmpty) {
    return customUserAgent;
  }

  return (await _webView.evaluateJavaScript('navigator.userAgent;')
      as String?)!;
}