I'm trying to get the user-agent from WKWebView by using swift,
let webView = WKWebView(frame: .zero)
useragentlabel.text = webView.configuration.applicationNameForUserAgent
but it return Mobile/15E148
, it s can be that the user-agent ?
thanks
Fast, synchronous method with no closures, Swift 5, iOS 13 and iOS 14 tested:
let UA = WKWebView().value(forKey: "userAgent")
would have UA have (optional value) of:
Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
for iOS 13.5 in iPhone XS Simulator
[self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
}];
The result is userAgent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With