async function getDeviceType() {
if (navigator.userAgentData) {
const hints = await navigator.userAgentData.getHighEntropyValues(['mobile']);
return hints.mobile ? 'mobile' : 'desktop';
}
const ua = navigator.userAgent;
if (/tablet|ipad|playbook|silk/i.test(ua)) return 'tablet';
if (/mobile|android|iphone|ipod|blackberry|iemobile|opera mini/i.test(ua)) return 'mobile';
return 'desktop';
}
// Usage
getDeviceType().then((type) => {
console.log('Device:', type); // 'mobile', 'tablet', or 'desktop'
});
Create a free account and build your private vault. Share publicly whenever you want.