-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathuser-agent.html
More file actions
118 lines (81 loc) · 4.45 KB
/
user-agent.html
File metadata and controls
118 lines (81 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{{+bindTo:partials.standard_multidevice_article}}
<style>
.ua-example {
white-space: normal; /* more mobile-friendly */
}
</style>
<h1>User Agent Strings</h1>
<p>A browser’s user agent string (UA) helps identify which browser is being used, what version, and on which operating system. When feature detection APIs are not available, use the UA to customize behavior or content to specific browser versions.</p>
<p>Like all other browsers,
Chrome for Android sends this information in the <code>User-Agent</code>
HTTP header every time it makes a request to any site.
It’s also available in the client through JavaScript using the
<code>navigator.userAgent</code> call.</p>
<section class="collapsible">
<h2 id="chrome_for_android_user_agent">Chrome for Android</h2>
<p><a href="https://play.google.com/store/apps/details?id=com.android.chrome">Chrome for Android</a>
reports its UA in the following
formats, depending on whether the device is a phone or a tablet.</p>
<p><strong>Phone UA:</strong></p>
<pre class="ua-example">Mozilla/5.0 (Linux; <Android Version>; <Build Tag etc.>)
AppleWebKit/<WebKit Rev> (KHTML, like Gecko) Chrome/<Chrome Rev> <b>Mobile</b>
Safari/<WebKit Rev>
</pre>
<p><strong>Tablet UA:</strong></p>
<pre class="ua-example">Mozilla/5.0 (Linux; <Android Version>; <Build Tag etc.>)
AppleWebKit/<WebKit Rev>(KHTML, like Gecko) Chrome/<Chrome Rev>
Safari/<WebKit Rev>
</pre>
<p>Here’s an example of the Chrome user agent string on a Galaxy Nexus:</p>
<pre class="ua-example">Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B)
AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile
Safari/535.19
</pre>
<p>If you are parsing user agent strings using regular expressions, the
following can be used to check against Chrome on Android phones and tablets:</p>
<ul>
<li><strong>Phone pattern:</strong> <code>'Android' + 'Chrome/[.0-9]* Mobile'</code></li>
<li><strong>Tablet pattern:</strong> <code>'Android' + 'Chrome/[.0-9]* (?!Mobile)'</code></li>
</ul>
</section>
<section class="collapsible">
<h2 id="chrome_for_ios_user_agent">Chrome for iOS</h2>
<p>The UA in Chrome for iOS is the same as the Mobile Safari
user agent, with <code>CriOS/<ChromeRevision></code> instead of
<code>Version/<VersionNum></code>.</p>
<p>Here’s an example of the <strong>Chrome</strong> UA on iPhone:</p>
<pre class="ua-example">Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)
AppleWebKit/602.1.50 (KHTML, like Gecko) <b>CriOS/56.0.2924.75</b>
Mobile/14E5239e Safari/602.1</pre>
<p>For comparison, the <strong>Mobile Safari</strong> UA:</p>
<pre class="ua-example">Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)
AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0
Mobile/14E5239e Safari/602.1</pre>
When the Request Desktop Site feature is enabled, the <strong>Desktop Safari</strong> UA is
sent:
<pre class="ua-example">Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4)
AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7
Safari/600.7.12</pre>
</section>
<section class="collapsible">
<h2 id="webview_user_agent">WebView on Android</h2>
<p>The Android 4.4 (KitKat) <a href="webview/overview">Chromium-based WebView</a> adds <strong>Chrome/_version_</strong> to the user agent string.</p>
<p>Old WebView UA:</p>
<pre class="ua-example">Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Build/KLP)
AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30</pre>
<p><strong>WebView UA in KitKat to Lollipop</strong></p>
<pre class="ua-example">Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_)
AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 <b>Chrome/30.0.0.0 Mobile</b>
Safari/537.36</pre>
<p>If you’re attempting to differentiate between the WebView and Chrome for Android,
you should look for the presence of the <strong>Version/_X.X_</strong> string in the WebView
user-agent string. Don’t rely on the specific Chrome version number
(for example, 30.0.0.0) as the version numbers changes with each release.</p>
<p><strong>WebView UA in Lollipop and Above</strong></p>
<p>In the newer versions of WebView,
you can differentiate the WebView by looking for the wv field as highlighted below.</p>
<pre class="ua-example">Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; <b>wv</b>)
AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 <b>Chrome/43.0.2357.65 Mobile</b>
Safari/537.36</pre>
</section>
{{/partials.standard_multidevice_article}}