quarta-feira, 15 de julho de 2015

User Agent Strings

User Agent Strings

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.
Like all other browsers, Chrome for Android sends this information in the User-Agent HTTP header every time it makes a request to any site. It’s also available in the client through JavaScript using the navigator.userAgent call.

Chrome for Android

Chrome for Android reports its UA in the following formats, depending on whether the device is a phone or a tablet.
Phone UA:
Mozilla/5.0 (Linux; ; ) AppleWebKit/ (KHTML, like Gecko) Chrome/ Mobile Safari/
Tablet UA:
Mozilla/5.0 (Linux; ; ) AppleWebKit/(KHTML, like Gecko) Chrome/ Safari/
Here’s an example of the Chrome user agent string on a Galaxy Nexus:
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
If you are parsing user agent strings using regular expressions, the following can be used to check against Chrome on Android phones and tablets:
  • Phone pattern: 'Android' + 'Chrome/[.0-9]* Mobile'
  • Tablet pattern: 'Android' + 'Chrome/[.0-9]* (?!Mobile)'

Chrome for iOS

The UA in Chrome for iOS is the same as the Mobile Safari user agent, with CriOS/ instead of Version/.
Here’s an example of the Chrome UA on iPhone:
Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3
For comparison, the Safari UA:
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3
For more information about Mobile Safari user agent strings, see Using the Safari User Agent String.

WebView on Android

The Android 4.4 (KitKat) Chromium-based WebView adds Chrome/_version_ to the user agent string.
Old WebView UA:
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
WebView UA in KitKat to Lollipop
Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
If you’re attempting to differentiate between the WebView and Chrome for Android, you should look for the presence of the Version/_X.X_ 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.
WebView UA in Lollipop and Above
In the newer versions of WebView, you can differentiate the WebView by looking for the wv field as highlighted below.
Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36
Postar um comentário