Created
October 24, 2024 04:05
-
-
Save ha1f/a27fd96787360fc5e8b98864b0273141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private extension WKWebView { | |
func getUserAgent() async throws -> String? { | |
try await withCheckedThrowingContinuation { continuation in | |
evaluateJavaScript("navigator.userAgent") { (result, error) in | |
if let error { | |
continuation.resume(throwing: error) | |
} else if let userAgent = result as? String { | |
continuation.resume(returning: userAgent) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment