Skip to content

Instantly share code, notes, and snippets.

@ha1f
Created October 24, 2024 04:05
Show Gist options
  • Save ha1f/a27fd96787360fc5e8b98864b0273141 to your computer and use it in GitHub Desktop.
Save ha1f/a27fd96787360fc5e8b98864b0273141 to your computer and use it in GitHub Desktop.
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