A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

What is the best way to detect touch-only users with MW?

jwbth

I’m modernizing referenceTooltips gadget (present in enwiki, ruwiki and many other Wikipedia editions), and I’m willing to aid accessibility effort by giving access to <abbr> elements titles (see also T130011) and other content hidden in native tooltips for touch-only devices via gadget tooltips which are available with touch.

But what is the best way to detect touch-only users, possibly using MW APIs? 'ontouchstart' in document.documentElement isn’t enough because there are touch laptops with mouse, and we need specifically touch-only devices. $.client.profile().name seems to have a high error rate, returning android for mobile Chrome and chrome for native Android browser.

I would like to add that we don’t need 100% accuracy here: we need at least a huge portion of touch-only users to process native browser tooltips for them.

jwbth

After reading stackoverflow (1, 2) and various other pages, I stopped at

( /Mobi|Android/i.test( navigator.userAgent ) ||
	typeof window.orientation !== 'undefined'
) &&
( 'ontouchstart' in document.documentElement )
  • The first check is the adjusted simple method of detecting mobile browsers recommended by Mozilla.
  • The second is a widely advised simple method of detecting mobile browsers that has a big disadvantage of being deprecated.
  • The last check is for reliability, since the first two checks (don’t know about the second, but the first—very likely) are prone to false positives.

Arguably we shouldn’t convert native tooltips into gadget tooltips for devices that have mouse support, even if they have touchscreens (there are laptops with touchscreens, as I mentioned above).