Detect Browser and Device
Detect Browser and Device is a reusable JavaScript snippet. Detects the user's browser, operating system, and device type from the user agent string. The full implementation: const detect = { get browser() { const ua = navigator.userAgent if (ua.includes('Firefox')) return 'Firefox' if (ua.includes('Edg')) return 'Edge' if (ua.includes('Chrome')) return 'Chrome' if (ua.includes('Safari')) return 'Safari' return 'Unknown' }, get os() { const ua = navigator.userAgent if (ua.includes('Windows')) return 'Windows' if (ua.includes('Mac')) return 'macOS' if (ua.includes('Linux')) return 'Linux' if (ua.includes('Android')) return 'Android' if (ua.includes('iOS')) return 'iOS' return 'Unknown' }, get isMobile() { return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) }, get isTouch() { return 'ontouchstart' in window || navigator.maxTouchPoints > 0 }, }… This snippet uses only standard JavaScript with no dependencies, so it runs in modern browsers and Node.js alike. Browse more patterns in the snippet library, or paste the code straight into the playground to experiment with it.