[whatwg] RWD Heaven: if browsers reported device capabilities in a request header (Boris Zbarsky)

Henri Sivonen hsivonen at iki.fi
Fri Mar 30 07:18:28 PDT 2012

On Mon, Feb 6, 2012 at 9:24 PM, Irakli Nadareishvili <irakli at gmail.com> wrote:
> if you don't mind me saying it, I am afraid you may be missing the point of this request. In Responsive Web Design, device capabilities are used in a high-level fashion to determine a class of the device: smartphone, tablet, desktop.

Firefox (at least from version 12 up), Opera Mobile and Safari already
expose this information.

Firefox for tablets includes the substring "Tablet" in the UA string
and Firefox for phones includes the substring "Mobile" in the UA
string.  If neither "Tablet" nor "Mobile" is present in the UA string,
the browser is running on a desktop.

In the case of Opera (excluding Mini), the indicators are "Tablet" and
"Mobi" (and desktop otherwise).

In the case of Safari, if the substring "iPad" is present, it's a
tablet.  Otherwise, if the substring "Mobile" is present, it's a phone
form factor.  Otherwise, its desktop (or a non-Safari browser spoofing
as Safari).

IE differentiates between desktop on the phone form factor as well:
the mobile form factor in closest substring "IEMobile".

Unfortunately, the Android stock browser on Android tablets does not
include a clear tablet indicator.

So you get something like
 * Returns "desktop", "tablet" or "phone"
 * Some 7" tablets get reported as phones. Android netbook likely get
reported as tablets.
 * Touch input not guaranteed on phones (Opera Mobile on keypad
Symbian, for example) and tablets (non-Fire Kindle)!
function formFactor() {
  var ua = navigator.userAgent;
  if (ua.indexOf("Tablet") > -1) {
    // Opera Mobile on tablets, Firefox on tablets, Playbook stock browser
    return "tablet";
  if (ua.indexOf("iPad") > -1) {
    // Safari on tablets
    return "tablet";
  if (ua.indexOf("Mobi") > -1) {
    // Opera Mobile on phones, Firefox on phones, Safari on phones
(and same-sized iPod Touch), IE on phones, Android stock on phones,
Chrome on phones, N9 stock, Dolfin on Bada
    return "phone";
  if (ua.indexOf("Opera Mini") > -1) {
    // Opera Mini (could be on a tablet, though); let's hope Opera
puts "Tablet" in the Mini UA on tablets
    return "phone";
  if (ua.indexOf("Symbian") > -1) {
    // S60 browser (predates Mobile Safari and does not say "Mobile")
    return "phone";
  if (ua.indexOf("Android") > -1 && ua.indexOf("Safari") > -1) {
    // Android stock on tablet or Chrome on Android tablet
    return "tablet";
  if (ua.indexOf("Kindle") > -1) {
    // Various Kindles; not all touch!
    return "tablet";
  if (ua.indexOf("Silk-Accelerated") > -1) {
    // Kindle Fire in Silk mode
    return "tablet";
  return "desktop";

Seems like the coarse form factor data is pretty much already in the
UA strings. Things could be improved by Opera Mini, Safari, Amazon's
browsers and Google's browsers saying "Tablet" when on tablet. Symbian
is dead, so no hope for its stock browser starting to say "Mobi".

The inferences you may want to make from the form factor data may well be wrong.

Henri Sivonen
hsivonen at iki.fi

More information about the whatwg mailing list