Referring to Chrome\'s ability to emulate device resolution and touch events: https://developer.chrome.com/devtools/docs/device-mode
The actual issue:
I ended with:
window.navigator.userAgent.indexOf('Mobile') !== -1;
Chrome adds Mobile
to userAgent in device emulation mode, for example "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1"
'TouchEvent' in window && 'ontouchstart' in window
isn’t providing correct state in real time when you turning on/off device mode unfortunately