diff --git a/Sources/Brave/Frontend/Browser/Tab.swift b/Sources/Brave/Frontend/Browser/Tab.swift index 330f5406fb62..f669fb93fdf9 100644 --- a/Sources/Brave/Frontend/Browser/Tab.swift +++ b/Sources/Brave/Frontend/Browser/Tab.swift @@ -715,6 +715,13 @@ class Tab: NSObject { func updateUserAgent(_ webView: WKWebView, newURL: URL) { guard let baseDomain = newURL.baseDomain else { return } + + let screenWidth = webView.currentScene?.screen.bounds.width ?? webView.bounds.size.width + if webView.traitCollection.horizontalSizeClass == .compact && (webView.bounds.size.width < screenWidth / 2.0) { + let desktopMode = userAgentOverrides[baseDomain] == true + webView.customUserAgent = desktopMode ? UserAgent.desktop : UserAgent.mobile + return + } let desktopMode = userAgentOverrides[baseDomain] ?? UserAgent.shouldUseDesktopMode webView.customUserAgent = desktopMode ? UserAgent.desktop : UserAgent.mobile