MCPcopy Create free account
hub / github.com/codecombat/codecombat / isMobile

Function isMobile

app/core/utils.js:1759–1780  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1757}
1758
1759const isMobile = () => {
1760 // First try the modern way - navigator.userAgentData
1761 if (navigator.userAgentData?.mobile !== undefined) {
1762 return navigator.userAgentData.mobile
1763 }
1764
1765 // Fallback to navigator.maxTouchPoints for iOS devices
1766 if (navigator.maxTouchPoints && navigator.maxTouchPoints > 1) {
1767 return true
1768 }
1769
1770 // Then try matching common mobile screen sizes
1771 if (window.matchMedia('(max-width: 1024px) and (orientation: portrait), (max-width: 1024px) and (orientation: landscape)').matches) {
1772 return true
1773 }
1774
1775 // Finally fall back to UA string detection for older devices
1776 const ua = navigator.userAgent || navigator.vendor || window.opera
1777 const modernMobileRE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Samsung.*Mobile|Mobile.*Firefox|Windows.*Phone|^HTC|LG.*Mobile|BB10|PlayBook|Tablet|Mobile Safari|Chrome.*Mobile/i
1778 const isMobileDevice = modernMobileRE.test(ua)
1779 return isMobileDevice
1780}
1781
1782const isIPad = () => {
1783 const ua = navigator.userAgent

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected