Skip to content

Commit

Permalink
Fix brave/brave-ios#8489: Follow Safari's behaviour for Desktop-UA (b…
Browse files Browse the repository at this point in the history
…rave/brave-ios#8490)

Follow Safari's behaviour for Desktop-UA when in compact horizontal size class.
  • Loading branch information
Brandon-T authored Nov 28, 2023
1 parent 7ca9990 commit 789d772
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/Brave/Frontend/Browser/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 789d772

Please sign in to comment.