Is there a way to know device type - ex: mobile, tablet from Navigator API - https://developer.mozilla.org/en-US/docs/Web/API/Navigator?
In a secure context, you can use navigator.userAgentData, which provides a NavigatorUAData object, which has some useful information about the user agent (browser), including a mobile flag. The getHighEntropyValues method returns a promise which will be fulfilled with more detailed information (if the user allows it) or rejected (if not, or the browser doesn't offer high-entropy values).
For platforms that don't support userAgentData (yet), you can fall back to parsing the userAgent string, but beware that the userAgent string is notoriously unreliable and easily spoofed.
You can use the following function:
getDeviceType() {
const ua = navigator.userAgent;
const tabletRegex = /(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i;
const mobRegex = /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/;
if (tabletRegex.test(ua)) return "tablet";
if (mobRegex.test(ua)) return "mobile";
return "desktop";
}