102

For iOS google chrome, when a user hits the "Request desktop site" button what does the browser do to try to bring up a desktop site? I imagine some sort of header on the request that sites are looking for, or something similar?

Mu Mind
  • 10,935
  • 4
  • 38
  • 69
butallmj
  • 1,531
  • 4
  • 14
  • 21

4 Answers4

70

I think the only difference is the User-Agent: header in the request.

Here are the User-Agent headers sent by Chrome on my Android device:

Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19

Notice the word "Mobile' in the first one, and also the mention of Android system and device. Checking these, I see that it also provides false information - namely X11 and x86_64 - to closely match the value sent by the Desktop Linux version of Chrome.

dsh
  • 12,037
  • 3
  • 33
  • 51
  • 15
    A separate header would be brilliant. User Agent sniffing is so horrible. – Mu Mind Oct 05 '12 at 17:38
  • 11
    I agree. Sometimes the automatic detection and redirect implemented by some sites is extremely counterproductive and aggravating. – dsh Oct 06 '12 at 15:32
  • 5
    A better solution would be to detect device size, interfaces, and capabilities. CSS media queries are a step in the right direction. – Brad May 03 '13 at 01:48
  • 2
    This feature is not implemented by a simple UA switch and refresh. The truth of the matter is that most mobile sites will NOT switch back to desktop if loaded with a desktop UA string. So then Safari uses your original request? Nope. It seems to work even if you originally typed in the URL for the mobile site. I don't know how its implemented because the name of mobile versions is by no means standardized, but there is something smarter going on than a simple UA change. – Andrew G Feb 03 '15 at 19:23
  • 1
    I would like to point out that the "layout viewport" would also change if one triggers "Request Desktop Site" option, which affects media query. Check *the-mobile-web-handbook* for more infomation about layout viewport. – Rick Oct 06 '19 at 10:35
26

Just wanted to point out that Chrome now not only changes the User-Agent but also ignores the original viewport meta tag if you "Request Desktop Site". Thus it won't be necessary to sniff the User-Agent anymore and you can rely on the viewport change as most responsive sites will automatically do. See this Change for further reference.

Thomas
  • 385
  • 5
  • 8
  • 1
    Thanks for that. my own very simple website is behaving very different when it isn't clicked and I couldn't understand why as I am doing nothing more than media queries in CSS. – R Reveley Dec 13 '17 at 20:38
17

One other slight difference is that the request appears to have been to the last intentionally entered URL before any re-directors moved it. For example:

Given: somesite.com sniffs the agent, sees Android, and does a document.location += "/m";

Then: the browser will have a URL of somesite.com/m

But: if you "Request desktop site" it will change the User-Agent and re-request from somesite.com

Unless: you had gone directly in on the mobile URL of somesite.com/m in the first place, in which case it just reloads somesite.com/m.

I would expect that this works with HTTP 301 and 302 redirects, I know it works with document.location changes (at least as described), and would speculate that it works with <meta> refreshes.

Jason Miller
  • 276
  • 2
  • 4
  • Did you base your answer from [this](https://productforums.google.com/forum/#!topic/chrome/tz24aCo6F3I)? – Keale Nov 05 '15 at 09:47
  • @Keale probably the other way around, given the timestamps – pulsar Sep 18 '18 at 17:42
  • Looks like if a POST request gets a 302 or 303 suggesting a GET for another URL, then the user changes 'desktop view' setting, the browser will submit a GET request to the original URL that returned the 302/303 (losing the POST parameters). Seems both Firefox and Chrome do this and IMO this is definitely not what should be happening. – Jake Jun 28 '20 at 05:06
-2

This javascript snippet will effectively do the same :

function requestDesktopSite() {
    document.getElementsByTagName('meta')['viewport'].content='min-width: 980px;';
}
<button onclick="requestDesktopSite()">Request Desktop Site</button>
10us
  • 1,622
  • 18
  • 13