Skip to content

Commit 4cf2bee

Browse files
dylanjeffersclaude
andauthored
Honor "Request Desktop Site" on mobile browsers (#14222)
## Summary Today, when a user on a mobile browser toggles "Request Desktop Site", the User-Agent flips to a desktop one — but the web client still serves the mobile experience. The cause is a fallback in `isMobile()` (and the duplicate `isMobileWeb()`) that flags any device with `navigator.platform === 'MacIntel'` and `maxTouchPoints > 1` as mobile, overriding the UA. iPadOS 13+ Safari sends a Mac UA by default, so iPads always tripped this branch regardless of what the browser claimed to be. This PR removes that override. The User-Agent regex on its own already returns `false` once a mobile browser advertises a desktop UA, so we now serve the desktop app whenever the browser asks for it. - `packages/web/src/utils/clientUtil.ts`: drop the `MacIntel` + touchPoints branch in `isMobile()`; rely on `isMobileUserAgent()` only. - `packages/web/src/common/utils/isMobileWeb.ts`: drop the same branch in the duplicate web copy. The dev-only `localStorage.__FORCE_MOBILE__` override is preserved. ## Test plan - [ ] On an iPhone, Safari with default settings → mobile site (UA contains "iPhone"). - [ ] On an iPhone, Safari → "Request Desktop Website" → desktop site is served. - [ ] On an iPad (iPadOS 13+) with default Safari settings → desktop site (matches the browser's stated UA). - [ ] On an iPad with "Request Mobile Website" toggled → mobile site (UA flips to iPad). - [ ] On Android Chrome, default → mobile site. - [ ] On Android Chrome, "Desktop site" toggled → desktop site. - [ ] On a regular desktop browser → desktop site (no regression). - [ ] Dev-only `localStorage.__FORCE_MOBILE__ = '1'` still forces mobile mode in a desktop browser. https://claude.ai/code/session_01AJfWVtxfhkeoypc9x1Lvez --- _Generated by [Claude Code](https://claude.ai/code/session_01AJfWVtxfhkeoypc9x1Lvez)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 62b9653 commit 4cf2bee

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@audius/web': patch
3+
---
4+
5+
Honor "Request Desktop Site" on mobile browsers: when a mobile browser flips its User-Agent to a desktop one (via the browser's "Request Desktop Site" toggle, or iPadOS Safari's default Mac UA), serve the desktop web app instead of the mobile experience.

packages/web/src/common/utils/isMobileWeb.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// isNativeMobile from storeContext first.
44

55
/** This check CANNOT be used in the mobile app (React Native). It should only be run once we already know that we are NOT on the native mobile app. */
6+
// Respect the User-Agent so "Request Desktop Site" works: when a mobile
7+
// browser flips its UA to desktop, we serve the desktop app. Avoid
8+
// platform/touchPoints heuristics that would override that explicit choice.
69
export const isMobileWeb = () => {
710
let check = false
811
;(function (a) {
@@ -17,9 +20,6 @@ export const isMobileWeb = () => {
1720
)
1821
check = true
1922
})(navigator.userAgent || navigator.vendor || window.opera)
20-
// iPad iOS 13
21-
if (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
22-
check = true
2323

2424
return check
2525
}

packages/web/src/utils/clientUtil.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,15 @@ export const isMobile = () => {
4444
// localStorage may be unavailable (private mode, SSR); fall through.
4545
}
4646

47-
let check = false
48-
if (
47+
// Respect the User-Agent so that "Request Desktop Site" works: when a
48+
// mobile browser toggles desktop mode the UA flips to a desktop one, and
49+
// we should serve the desktop app. Avoid platform/touchPoints heuristics
50+
// (e.g. iPadOS sending a Mac UA) that would override that explicit choice.
51+
// @ts-ignore -- TODO fix mobile imports causing type errors
52+
return isMobileUserAgent(
4953
// @ts-ignore -- TODO fix mobile imports causing type errors
50-
isMobileUserAgent(navigator.userAgent || navigator.vendor || window.opera)
51-
) {
52-
check = true
53-
}
54-
55-
// iPad iOS 13
56-
if (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1) {
57-
check = true
58-
}
59-
60-
return check
54+
navigator.userAgent || navigator.vendor || window.opera
55+
)
6156
}
6257

6358
export const isElectron = () => {

0 commit comments

Comments
 (0)