Persisting desktop/mobile view in mobile Chrome browsers

AI-generated summary

A user, downey, is seeking a way to persist their desktop view preference in mobile Chrome browsers, specifically on their Android tablet. They find it inconvenient to have to request the desktop version every time they load a Discourse site.

codinghorror initially questions the effectiveness of a cookie-based solution, but downey explains that it would be helpful in maintaining their desktop UI setting for specific domains.

The discussion then shifts to user agent detection, with sam suggesting that Android mobile detection should always ask for Mobile + Android. DeanMarkTaylor shares Google Chrome’s user agent detection recommendations, which distinguish between phone and tablet patterns based on the presence or absence of “Mobile” in the user agent string.

codinghorror decides to change the user agent detection to check for the presence of Mobile (excluding iPads), assuming that if a device identifies itself as mobile, it should be treated as such.

I have both an Android phone & tablet, running the latest releases of Android/Chrome.

On the Pixel C, my standard orientation is landscape with a keyboard, so the mobile UI is not ideal. I keep trying the “request desktop version” in the browser options, but really wish that I didn’t have to do this step every single time I load a Discourse site.

Is there any way to persist the mobile/desktop preferences based on a cookie or something?

1 me gusta

Yes, but that cookie would be per domain so how would it help? The real issue is, freakishly rare android tablet, does it send a unique agent like the Nexus series do?

1 me gusta

I guess it would help by keeping the desktop UI setting every time I went to mydiscoursesite.example.org in my Android Chrome browser. Isn’t that desirable?

And, yes, unique user agent indeed:

Mozilla/5.0 (Linux; Android 6.0.1; Pixel C Build/MXC14G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.91 Safari/537.36

I think the call here is to always ask for Mobile + Android for Android mobile detection, if we need to whitelist some more 7’’ tablets (so they are treated as mobile) then we can

3 Me gusta

There are some specific Google Chrome user agent detection recommendations for “Phone” vs “Tablet” listed here:

https://developer.chrome.com/multidevice/user-agent

  • Phone pattern: Android + Chrome/[.0-9]* Mobile
  • Tablet pattern: Android + Chrome/[.0-9]* (?!Mobile)
2 Me gusta

All right, I’m changing it to

user_agent =~ /Mobile/ && !(user_agent =~ /iPad/)

No idea why we had webOS in there, who even uses that? Let’s just say it’s a mobile device if it is telling us it is one:

Mobile

5 Me gusta

This topic was automatically closed after 2 days. New replies are no longer allowed.